开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1224|回复: 0
收起左侧

[PHP相关教程] 酷狗歌曲信息及歌词抓取 分享给需要的人

[复制链接]
结帖率:57% (4/7)
发表于 2018-2-11 20:55:04 | 显示全部楼层 |阅读模式   重庆市重庆市
歌曲信息如下: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源代码


  1. <?php
  2. //播放器音乐解析模块
  3. error_reporting(0);
  4. $do=isset($_GET['do'])?$_GET['do']:exit;
  5. switch($do){
  6.         case 'parse':
  7.                 $type=isset($_GET['type'])?$_GET['type']:exit;
  8.                 $id=isset($_GET['id'])?$_GET['id']:null;
  9.         $id= str_replace("kg",'',$id);
  10.                 $callback=isset($_GET['callback'])?$_GET['callback']:null;
  11. //歌曲信息抓取
  12.                 if($type=='kg'){
  13.             $ch_3 = curl_init();
  14.             curl_setopt ($ch_3, CURLOPT_URL,"http://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash=".$id);
  15.             curl_setopt ($ch_3, CURLOPT_RETURNTRANSFER, 1);
  16.             curl_setopt ($ch_3, CURLOPT_CONNECTTIMEOUT, 10);
  17.             $play_data=json_decode(curl_exec($ch_3),true);
  18.             curl_close($ch_3);
  19.             $SongName = $play_data['songName'];
  20.             $ListenUrl=$play_data['url'];
  21.             $PicUrl=$play_data['imgUrl'];
  22.                         $PicUrl= str_replace("{size}","100",$PicUrl);
  23.             $Artist =$play_data['singerName'];

  24.                         //$ret = file_get_contents('http://m.kugou.com/app/i/krc.php?cmd=100&keyword='.$SongName.'&hash='.$id.'&timelength=246000&d=0.5261128980200738');
  25.                         //$LrcUrl=$ret;

  26.                 }
  27.                 echo $callback.'({"location":"'.$ListenUrl.'","lyric":"'.$LrcUrl.'","album_cover":"'.$PicUrl.'","album_name":"'.$Album.'","artist_name":"'.$Artist.'","song_name":"'.$SongName.'","song_id":"'.$id.'"}) ';
  28.         break;

  29. //歌词抓取
  30.         case 'lyric':
  31.                 if($_GET['type']=='kg'){
  32.                         $id=isset($_GET['id'])?$_GET['id']:null;
  33.                         $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/');
  34.                 }
  35.                 //echo "var cont = '".$data."';";
  36.                 echo $data;
  37.         break;
  38. }


  39. function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0)
  40. {
  41.         $ch = curl_init();

  42.         curl_setopt($ch, CURLOPT_URL, $url);

  43.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  44.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

  45.         $httpheader[] = "Accept:application/json";

  46.         $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";

  47.         $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";

  48.         $httpheader[] = "Connection:close";

  49.         curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);

  50.         if ($post) {

  51.                 curl_setopt($ch, CURLOPT_POST, 1);

  52.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

  53.         }

  54.         if ($header) {

  55.                 curl_setopt($ch, CURLOPT_HEADER, true);

  56.         }

  57.         if ($cookie) {

  58.                 curl_setopt($ch, CURLOPT_COOKIE, $cookie);

  59.         }

  60.         if($referer){

  61.                 if($referer==1){

  62.                         curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');

  63.                 }else{

  64.                         curl_setopt($ch, CURLOPT_REFERER, $referer);

  65.                 }

  66.         }

  67.         if ($ua) {

  68.                 curl_setopt($ch, CURLOPT_USERAGENT, $ua);

  69.         }

  70.         else {

  71.                 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)");

  72.         }

  73.         if ($nobaody) {

  74.                 curl_setopt($ch, CURLOPT_NOBODY, 1);

  75.         }

  76.         curl_setopt($ch, CURLOPT_ENCODING, "gzip");

  77.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  78.         $ret = curl_exec($ch);

  79.         curl_close($ch);

  80.         return $ret;

  81. }

  82. function ipcxiami($location){

  83. $count = (int)substr($location, 0, 1);

  84. $url = substr($location, 1);

  85. $line = floor(strlen($url) / $count);

  86. $loc_5 = strlen($url) % $count;

  87. $loc_6 = array();

  88. $loc_7 = 0;

  89. $loc_8 = '';

  90. $loc_9 = '';

  91. $loc_10 = '';

  92. while ($loc_7 < $loc_5){

  93. $loc_6[$loc_7] = substr($url, ($line+1)*$loc_7, $line+1);

  94. $loc_7++;

  95. }

  96. $loc_7 = $loc_5;

  97. while($loc_7 < $count){

  98. $loc_6[$loc_7] = substr($url, $line * ($loc_7 - $loc_5) + ($line + 1) * $loc_5, $line);

  99. $loc_7++;

  100. }

  101. $loc_7 = 0;

  102. while ($loc_7 < strlen($loc_6[0])){

  103. $loc_10 = 0;

  104. while ($loc_10 < count($loc_6)){

  105. $loc_8 .= @$loc_6[$loc_10][$loc_7];

  106. $loc_10++;

  107. }

  108. $loc_7++;

  109. }

  110. $loc_9 = str_replace('^', 0, urldecode($loc_8));

  111. return $loc_9;

  112. }
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表