Cool dog API, which can search for songs based on keywords and obtain original music paths

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the cool dog API. You can search for songs based on keywords and obtain the original music path.

A simple music website is provided based on this API: Http://flc.ren/music

Code hosting address: https://code.csdn.net/flc1125/kugou-api/tree/master

Demo file, under the Code. /**
* Cool dog API
* @ Author Flc <22:51:24>
*/
Require_once 'HTTP. class. php ';

Class kugou {
Const LIST_URL = 'HTTP: // lib9.service.kugou.com/websearch/index.php? Page = {page} & keyword = {keyword} & cmd = 100 & pagesize = {pagesize }';
Const MUSIC_URL = 'HTTP: // m.kugou.com/app/ I /getSongInfo.php? Hash = {hash} & cmd = playInfo ';

Protected static $ http = null;

/**
* Initialization
*/
Function _ construct (){
If (self ::$ http = null) self ::$ http = new http ();
}

/**
* Get the list
* @ Param string $ keyword
* @ Param integer $ page Current page
* @ Param integer $ pagesize the number of retrieved entries per page
* @ Return array | false
*/
Public function getList ($ keyword, $ page = 1, $ pagesize = 10 ){
$ Url = str_replace (array ('{page}', '{keyword}', '{pagesize}'), array ($ page, $ keyword, $ pagesize), self:: LIST_URL );

$ Json = self: $ http-> http_gets ($ url );
If (! $ Json) return false;
$ Resp = json_decode ($ json, true );

Return $ resp;
}

/**
* Obtain the music address
* @ Param string $ hash music hash code
* @ Return string | false
*/
Public function getMusic ($ hash ){
$ Url = str_replace (array ('{hash}'), array ($ hash), self: MUSIC_URL );

$ Json = self: $ http-> http_gets ($ url );
If (! $ Json) return false;
$ Resp = json_decode ($ json, true );

Return $ resp;
}
}
?>

Kugou.zip (2.13 KB download: 124 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.