酷狗API,可根据关键字搜索歌曲及获取音乐原始路径

回复 已回复1 星标
更多
酷狗API,可根据关键字搜索歌曲及获取音乐原始路径
»

酷狗API,可根据关键字搜索歌曲及获取音乐原始路径。demo文件在附件中,下载后请将“.txt”后缀去掉,再进行解压。

附根据该API,做的一个简单的音乐网站:http://music.flc.ren/

<?php

/**

* 酷狗API类

* @author Flc <2015-08-27 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;

/**

* 初始化

*/

function __construct(){

if(self::$http == null) self::$http = new http();

}

/**

* 获取列表

* @param string  $keyword  关键字

* @param integer $page     当前页

* @param integer $pagesize 每页获取数量

* @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;

}

/**

* 获取音乐地址

* @param string $hash 音乐hash码

* @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;

}

}

?>

正序阅读 1# 2019-12-13 16:13

好好

新窗口打开 关闭