php获取酷狗mv播放链接,酷狗歌单获取歌曲信息的接口源码

<?php /** *@authorYoungxj *@time2018年6月22日 *@todo利用酷狗歌单进行获取酷狗歌曲信息 */ // 访问短网址出现的地址 // http://m.kugou.com/share/zlist.html?u=25230245&h1=142560927507380788791872687420293028022&h2=da7ce5776afd5fdba03daa05f4a19860&listid=25&uid=25230245&type=0&_t=1528116907&token=2b631b0f122f5dc5c0ca758374c4d190eb8bde2ea382bf7a29bacfd5bb439489&sign=c0c7fe2caee03445b51bf8961308174b&chl=qq_client // 歌单列表接口 // http://m.kugou.com/zlist/list?listid=25&type=0&uid=25230245&sign=c0c7fe2caee03445b51bf8961308174b&_t=1528116907&pagesize=30&json=&page=1&token=2b631b0f122f5dc5c0ca758374c4d190eb8bde2ea382bf7a29bacfd5bb439489 // 关键值 uid sign _t token listid type // 获取歌曲信息的接口 // http://m.kugou.com/app/i/getSongInfo.php?hash=348CE533CE66E6DCEDA4A9FD63AB6D86&cmd=playInfo&is_share=1 # 设置json格式 header('Content-type: application/json'); #缓存文件名(最好使用json文件格式) $fileName = 'data.json'; # 酷狗歌单分享出来的短网址 $kgUrl = "http://t.kugou.com/1md5hf5t8V2"; file_get_contents($kgUrl); # 获取歌单访问后302跳转的header头信息 $responseInfo = $http_response_header; # 第五条记录为Location跳转地址里面包含多个关键值 $local = $responseInfo['5']; # 下面是蹩脚正则取值 // uid(疑似用户id) $zz_uid = "/uid=(.*?)&/"; preg_match($zz_uid,$local,$uid); // sign $zz_sign = "/sign=(.*?)&/"; preg_match($zz_sign,$local,$sign); // _t $zz_t = "/_t=(.*?)&/"; preg_match($zz_t,$local,$t); // listid(疑似歌单id) $zz_listid = "/listid=(.*?)&/"; preg_match($zz_listid,$local,$listid); // type $zz_type = "/type=(.*?)&/"; preg_match($zz_type,$local,$type); // token $zz_token = "/token=(.*?)&/"; preg_match($zz_token,$local,$token); //echo '
'; # 把取到的值变量定义 $uid = $uid['1']; $sign = $sign['1']; $t = $t['1']; $listid = $listid['1']; $type = $type['1']; $token = $token['1']; # 这里是呼应后面文本缓存的 # 主要是判断文本缓存中的token是否与当前获取的token是否一致 # 如果一致则读取文本缓存的json # 如果不一致则使用后面的获取最新 # 继续写入文本缓存 if(is_file($fileName)){ $dataJson = file_get_contents($fileName); $dataJsons = json_decode($dataJson,1); if($token == $dataJsons['token']){ echo $dataJson; exit(); } } # 这个地址是获取歌单列表里有多少歌 $listUrl = 'http://m.kugou.com/zlist/list?listid='.$listid.'&type='.$type.'&uid='.$uid.'&sign='.$sign.'&_t='.$t.'&pagesize=30&json=&page=1&token='.$token; $list = file_get_contents($listUrl); //var_dump($list); $lists = json_decode($list,1); # 统计歌单歌曲总数 $coun = count($lists["list"]["info"]); $arr = array('token'=>$token); for ($i=0; $i < $coun; $i++) { # 利用前面歌单列表取到的hash # 进行二次临时歌曲地址寻找 $hash = $lists["list"]["info"][$i]['hash']; $getSongInfoUrl = 'http://m.kugou.com/app/i/getSongInfo.php?hash='.$hash.'&cmd=playInfo&is_share=1'; $get = file_get_contents($getSongInfoUrl); $getjson = json_decode($get,1); $arr[$i] = $getjson; } # 到这里已经能正常输出歌单里所有歌曲的信息 echo $data_json = json_encode($arr,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); # 后面的为文本进行缓存的技术 $myfile = fopen($fileName, "w") or die("无法打开文件,请确定是否有权限编辑文件"); $txt = $data_json; fwrite($myfile, $txt); fclose($myfile);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值