|
歌曲信息如下:http://www.xiaoshuai.org/api/music.php?do=parse&type=kg&id={音乐哈希值}
歌词拉取信息如下:http://www.xiaoshuai.org/api/music.php?do=lyric&type=kg&id={音乐哈希值}
下面是PHP源代码
- <?php
- //播放器音乐解析模块
- error_reporting(0);
- $do=isset($_GET['do'])?$_GET['do']:exit;
- switch($do){
- case 'parse':
- $type=isset($_GET['type'])?$_GET['type']:exit;
- $id=isset($_GET['id'])?$_GET['id']:null;
- $id= str_replace("kg",'',$id);
- $callback=isset($_GET['callback'])?$_GET['callback']:null;
- //歌曲信息抓取
- if($type=='kg'){
- $ch_3 = curl_init();
- curl_setopt ($ch_3, CURLOPT_URL,"http://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash=".$id);
- curl_setopt ($ch_3, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch_3, CURLOPT_CONNECTTIMEOUT, 10);
- $play_data=json_decode(curl_exec($ch_3),true);
- curl_close($ch_3);
- $SongName = $play_data['songName'];
- $ListenUrl=$play_data['url'];
- $PicUrl=$play_data['imgUrl'];
- $PicUrl= str_replace("{size}","100",$PicUrl);
- $Artist =$play_data['singerName'];
- //$ret = file_get_contents('http://m.kugou.com/app/i/krc.php?cmd=100&keyword='.$SongName.'&hash='.$id.'&timelength=246000&d=0.5261128980200738');
- //$LrcUrl=$ret;
- }
- echo $callback.'({"location":"'.$ListenUrl.'","lyric":"'.$LrcUrl.'","album_cover":"'.$PicUrl.'","album_name":"'.$Album.'","artist_name":"'.$Artist.'","song_name":"'.$SongName.'","song_id":"'.$id.'"}) ';
- break;
- //歌词抓取
- case 'lyric':
- if($_GET['type']=='kg'){
- $id=isset($_GET['id'])?$_GET['id']:null;
- $data=get_curl('http://m.kugou.com/app/i/krc.php?cmd=100&keyword='.$SongName.'&hash='.$id.'&timelength=246000&d=0.5261128980200738',0,'http://www.kugou.com/');
- }
- //echo "var cont = '".$data."';";
- echo $data;
- break;
- }
- function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $httpheader[] = "Accept:application/json";
- $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
- $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
- $httpheader[] = "Connection:close";
- curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
- if ($post) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- }
- if ($header) {
- curl_setopt($ch, CURLOPT_HEADER, true);
- }
- if ($cookie) {
- curl_setopt($ch, CURLOPT_COOKIE, $cookie);
- }
- if($referer){
- if($referer==1){
- curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
- }else{
- curl_setopt($ch, CURLOPT_REFERER, $referer);
- }
- }
- if ($ua) {
- curl_setopt($ch, CURLOPT_USERAGENT, $ua);
- }
- else {
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)");
- }
- if ($nobaody) {
- curl_setopt($ch, CURLOPT_NOBODY, 1);
- }
- curl_setopt($ch, CURLOPT_ENCODING, "gzip");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $ret = curl_exec($ch);
- curl_close($ch);
- return $ret;
- }
- function ipcxiami($location){
- $count = (int)substr($location, 0, 1);
- $url = substr($location, 1);
- $line = floor(strlen($url) / $count);
- $loc_5 = strlen($url) % $count;
- $loc_6 = array();
- $loc_7 = 0;
- $loc_8 = '';
- $loc_9 = '';
- $loc_10 = '';
- while ($loc_7 < $loc_5){
- $loc_6[$loc_7] = substr($url, ($line+1)*$loc_7, $line+1);
- $loc_7++;
- }
- $loc_7 = $loc_5;
- while($loc_7 < $count){
- $loc_6[$loc_7] = substr($url, $line * ($loc_7 - $loc_5) + ($line + 1) * $loc_5, $line);
- $loc_7++;
- }
- $loc_7 = 0;
- while ($loc_7 < strlen($loc_6[0])){
- $loc_10 = 0;
- while ($loc_10 < count($loc_6)){
- $loc_8 .= @$loc_6[$loc_10][$loc_7];
- $loc_10++;
- }
- $loc_7++;
- }
- $loc_9 = str_replace('^', 0, urldecode($loc_8));
- return $loc_9;
- }
复制代码
|
|