Baidu Music non-public API

Source: Internet
Author: User

Introduction of Baidu Music Search API

As mentioned above, the key to replying to a music message is how to get a link to a song based on the name of the song, and we must find a ready-made music search API, unless the reader has a music server, or only replies to the fixed music from the user. Baidu has a non-public music search API, is said to be non-public, because the pen is not in the Baidu website anywhere to see the introduction of the API, but this does not affect the reader's study of this example, we can still call it. The request address of the Baidu Music Search API is as follows:

http://box.zhangmen.baidu.com/x?op=12&count=1&title=title$ $AUTHOR $

Http://box.zhangmen.baidu.com for the home address of the Baidu Music box, the above link without the pipe parameters op and Count, focus on title and Author,title to represent the song name, author means singers, author can be empty,the parameter title and author need to be URL encoded (UTF-8 or GB2312)。 For example, to search for songs zero the band "Believe in Yourself", you can do the following:

GB2312 encoded Music Search link

Http://box.zhangmen.baidu.com/x? op=&Count=1&title=%cf%e0%d0%c5%d7%d4%bc%ba$$%c1%e3%b5% e3%c0%d6%b6%d3$$$$

UTF-8 encoded Music Search link

Http://box.zhangmen.baidu.com/x? op=&Count=1&title=%e7%9b%b8%e4%bf%a1%e8%87%aa%e5%b7%b1$ $%e9%9b%b6%e7%82%b9%e4%b9%90%e9%98%9f$$$$

The above address is accessed through the browser and returns XML data in the following format:

 <result>      <count>1</count>       <url>          <encode>               <! [cdata[http://zhangmenshiting.baidu.com/data2/music/44277542/ Zwzla2xra2pfn6nndk6ap5wxcjvob5puz2trbwprmnbjz2xolpeza2drzmwzmzmdl2hjzwhvnwlpymrtzmltcgplzfqin5t1ywbobw5qcgxia2nmz2twbze $]]>          </encode>           <decode>               <! [cdata[44277542.mp3?xcode=a39c6698955c82594aab36931dcbef60139f180191368931&mid=0.59949419022597]]>           </decode>           <type>8</type>          <lrcid>64644</lrcid>           <flag>1</flag>      </url>       <durl>          < encode>              <! [cdata[http://zhangmenshiting2.baidu.com/data2/music/44277530/ Zwzla2xramhfn6nndk6ap5wxcjvob5puz2trbwprmnbjz2xolpeza2drzmwzmzmdl2hjaghvnz5qlgrpbpedamjla1qin5t1ywbobw5qcgxia2nmz2twbze $]]>          </encode>           <decode>               <! [cdata[44277530.mp3?xcode=a39c6698955c82594aab36931dcbef60439ff9b159af2138&mid=0.59949419022597]]>            </decode>          <type>8</type >          <lrcid>64644</lrcid>           <flag>1</flag>       </durl>      <p2p>           


The main parameters in the returned results are described below:

1) <count> indicates the number of music to be searched;

2) <url> contains the common quality music link,<durl> contains high-quality music links;

3) <encode> contains the encrypted music link, actually only the music name is encrypted,<decode> contains the decrypted music name. Therefore, to get a link to the music you need to focus on <encode> and <decode> content, the following will be specifically for the reader to introduce.

4) <type> indicates the types of music files, such as RM, WMA, MP3, etc.;

5) <lrcid> is the lyrics in the id,<url> lyrics ID 64644, then how to get the lyrics? This example does not care about lyrics, just a mention. The lyrics are addressed as follows:

Http://box.zhangmen.baidu.com/bdlrc/646/64644.lrc

Where http://box.zhangmen.baidu.com/bdlrc/is a fixed value, 646 is the directory name of the lyrics, the calculation method is the lyrics ID (64644) divided by 100, take the integer part; 64644.LRC is the lyrics file name.

here's how to get music links from <encode> and <decode>. for illustrative purposes, the <url> and <durl> sections of the above search results are extracted and annotated as shown.

650) this.width=650; "Src=" http://img.blog.csdn.net/20131210154940640?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvbhlxodq3oq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "/>

, 1 and 2 are stitched together to be a link to regular quality music, and 3 and 4 are spliced together as links to high-quality music. in other words, the normal quality and high quality music links are as follows:

Regular quality music links

Http://zhangmenshiting.baidu.com/data2/music/44277542/44277542.mp3? Xcode=a39c6698955c82594aab36931dcbef60139f180191368931

High quality music Links

Http://zhangmenshiting2.baidu.com/data2/music/44277530/44277530.mp3? Xcode=a39c6698955c82594aab36931dcbef60439ff9b159af2138

Parameter Xcode can be understood as a random verification code, the value of each search will be different, if not with this parameter is reported an unauthorized exception "401 Authorization Required". It is important to note that Xcode has a time limit, exceeding the limit of the re-access link to report the exception: {"Error": {"code": "2", "Message": "Object Not Exists", "Logid": "3456414897"}. With Xcode in effect, you'll be prompted to download music by accessing the music link above through your browser.



This article is from the "meteor Shower It Journey" blog, please be sure to keep this source http://lxy2020.blog.51cto.com/2528961/1571348

Baidu Music non-public API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.