百度,soso,yahoo音乐搜索接口
2009-09-16 20:05
387 查看
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
百度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
相关文章推荐
- 百度,soso,yahoo音乐搜索接口
- 百度搜索接口调用
- 站内搜索代码(百度,Google,Yahoo等)
- 调用百度搜索接口查询
- 百度发布硬盘搜索 开放API和XML接口给程序员
- android 百度搜索接口
- 百度“哼唱”音乐搜索
- 百度开放音乐搜索api
- google,百度,yahoo搜索比较
- Yahoo支持音乐搜索和播放
- 百度搜索结果惊现音乐试听功能
- vue2.0,jsonp的一个小案例 请求百度搜索的接口
- 百度搜索词&淘宝搜索词 接口实现
- 实现google baidu yahoo soso ... 站内搜索代码
- 百度MP3音乐API接口及应用
- angularjs实现百度的搜索接口及链接的实现
- 百度搜索接口调用
- jsonp结合百度接口-实现搜索功能
- 百度搜索词&淘宝搜索词 接口实现