百度,soso,yahoo音乐搜索接口

本文介绍如何使用SOSO、百度及Yahoo等音乐API接口来获取音乐资源。通过C++示例代码展示了如何利用百度音乐接口进行HTTP请求,从而获得包含歌曲和歌词链接的XML响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SOSO音乐接口 http://music.soso.com/music.cgi?ty=getsongurls&w=歌名&pl=歌手名

百度MP3音乐接口 http://box.zhangmen.baidu.com/x?op=12&count=1&title=歌名$$歌手名$$$$

yahoo音乐api http://developer.yahoo.com/music/

下面以百度接口为例,向大家展示一下其用法。

#include <afxwin.h>
#include <stdio.h>
#include <windows.h>
#include "Wininet.h"

#pragma comment(lib,"Wininet.lib")
#pragma comment(lib,"nafxcwd.lib")

//模拟浏览器发送HTTP请求函数
CString HttpRequest(char * lpHostName,short sPort,char * lpUrl,char * lpMethod,char * lpPostData,int nPostDataLen)
{
HINTERNET hInternet,hConnect,hRequest;
BOOL bRet;
CString strResponse;
FILE * fp ;

char hdrs[] = "Content-Type: application/x-www-form-urlencoded";

hInternet = InternetOpen("User-Agent",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(!hInternet)
goto Ret0;

hConnect = InternetConnect(hInternet,lpHostName,INTERNET_DEFAULT_HTTP_PORT,NULL,"HTTP/1.1",INTERNET_SERVICE_HTTP,0,1);
if(!hConnect)
goto Ret0;

hRequest = HttpOpenRequest(hConnect,lpMethod,lpUrl,"HTTP/1.1",NULL,NULL,INTERNET_FLAG_RELOAD,1);
if(!hRequest)
goto Ret0;

//bRet = HttpAddRequestHeaders(hRequest,"Content-Type: application/x-www-form-urlencoded",Len(FORMHEADERS),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
//if(!bRet)
//goto Ret0;


bRet = HttpSendRequest(hRequest,hdrs, strlen(hdrs), lpPostData,nPostDataLen);


fp = fopen("C://23.xml","w");
while(TRUE)
{
char cReadBuffer[4096];
unsigned long lNumberOfBytesRead;
bRet = InternetReadFile(hRequest,cReadBuffer,sizeof(cReadBuffer) - 1,&lNumberOfBytesRead);
if(!bRet || !lNumberOfBytesRead)
break;
cReadBuffer[lNumberOfBytesRead] = 0;
strResponse = strResponse + cReadBuffer;
fwrite(cReadBuffer,lNumberOfBytesRead,1,fp);
}
fclose(fp);

Ret0:
if(hRequest)
InternetCloseHandle(hRequest);
if(hConnect)
InternetCloseHandle(hConnect);
if(hInternet)
InternetCloseHandle(hInternet);

return strResponse;
}


void main(int argc, char *argv[])
{
//CString strResponse = HttpRequest("translate.google.com",80,"/translate_t?langpair=en|zh-CN","POST","hl=zh-CN&ie=UTF-8&text=this is me&langpair=en|zh-CN",strlen("hl=zh-CN&ie=UTF-8&text=this is me&langpair=en|zh-CN"));
// CString strResponse = HttpRequest("box.zhangmen.baidu.com",80,
// "/x?op=12","POST",
// "count=1&title=me",strlen("count=1&title=me"));
CString strResponse = HttpRequest("box.zhangmen.baidu.com",80,"/x?op=12&count=1&title=me","GET",NULL,0);
// FILE * fp = fopen("C://123.htm","wb");
// fwrite(strResponse,strResponse.GetLength(),1,fp);
// fclose(fp);
// ::MessageBox(NULL,strResponse,"123",0);
}

那么在C盘下就有一个23.xml 的文件, 解析这个xml就可以得到mp3的地址与歌词地址。


在XML中,<lrcid>64259</lrcid> 对应歌词路径是:http://box.zhangmen.baidu.com/bdlrc/642/64259.lrc

在XML中,<encode>http://mp32.jmusics.com/music_ol0808/SEED/FINDTHEWAY/ZDI$.mp3</encode>

< decode > 3.mp3 </ decode > 对应的歌曲路径是: http://mp32.jmusics.com/music_ol0808/SEED/FINDTHEWAY/3.mp3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值