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

来源:互联网 发布:信息化管理平台软件 编辑:程序博客网 时间:2024/05/01 12:37

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
原创粉丝点击