当前位置:首页 > 建站技巧 > 酷狗音乐MV轮播PHP

酷狗音乐MV轮播PHP

admin2年前 (2022-09-14)建站技巧1016
※ 声明:本站为非商业性博客,内容均为本站网友收集于互联网公开分享,仅限于学习和探讨的目的,不得将上述内容用于非法或商业途径,版权争议与本站无关,如有冒犯,请留言删除!

<?php 
header("Content-Type: text/html; charset=UTF-8");
$id = isset($_GET['id'])?$_GET['id']:'';
if($id=='list'||$id==null||$id=='top'){
  $type = isset($_GET['type'])?$_GET['type']:'';
  $sort=array(
    'xgtj'=>[9, '新歌推荐'],
    'hyjx'=>[13,'华语精选'],
    'rhjx'=>[17,'日韩精选'],
    'omjx'=>[16,'欧美精选'],
    );
  if(!$type){   //未指定时,随机一个分类
    $type=array_keys($sort)[array_rand(array_keys($sort),1)];  
  }
  $k=mt_rand(0,9);
  if($id=='list'){   //获取ID,默认设定10个页面
    $v=1;$s=10;      
  }else{   //随机看,默认设定一个页面
    $v=mt_rand(1,10);$s=1;  
  }
  for($n=$k*10+$v,$m=$n+$s,$p=$n;$p<$m;++$p){
    $mvurl = "http://www.kugou.com/mvweb/html/index_{$sort[$type][0]}_$p.html";
    $data = curl_get($mvurl);
    preg_match_all('/href=".*?mv_(.*?).html.*?title="(.*?)">\n.*?_src=.*?mvpic\/\w*?\/\w*?\/(.*?).jpg"/',$data,$pams);
    $count=count($pams[0]);
    for($i = 0; $i < $count; $i++){
      $rid=$ids[]=$pams[1][$i];
      $title=$names[]=$pams[2][$i];
      $hash=$pams[3][$i];
      if($id=='list'){
        echo $title.',http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?id='.$rid.'&hash='.$hash.'&type='.$sort[$type][1].'</a><br>';
      }
    }
  }
  if($id==null||$id=='top'){
    $rand=array_rand($ids,1);
    $id=$ids[$rand];
    $name=$names[$rand];
  }
}
if($id!='list'&&$id!='top'&&$id!=null){
  $hash= isset($_GET['hash'])?$_GET['hash']:'';
  if(!$hash){
    $web='http://www.kugou.com/mvweb/html/mv_'.$id.'.html';
    $data= curl_get($web);
    preg_match_all('/_hash = "(.*?)"/',$data,$info);
    $hash=$info[1][0];  
    if($info[1][1]){
      $hash=$info[1][mt_rand(0,1)];
    }
  }
  $bsurl = "http://m.kugou.com/app/i/mv.php?cmd=100&ext=mp4&hash=".$hash;
  $data = json_decode(curl_get($bsurl));
  if($data->mvdata->rq->hash){
    $line='rq';  //超清
  }else if($data->mvdata->sq->hash){
    $line='sq';  //高清
  }else{
    $line='le';  //标清  
  }
  $txurl=$data->mvdata->{$line}->downurl;          //tx 线路
  $aliurl=$data->mvdata->{$line}->backupdownurl[0];//ali线路
  $songname=$data->songname;
  $singer=$data->singer;
  $remark=$data->remark;
  $playurl=array($aliurl,$txurl)[mt_rand(0,1)].'?id='.$id.'&tag='.$singer.'-'.$songname.'-'.$remark;
  //print_r($playurl);
  header('location:'.$playurl);
}

function curl_get($url){
  $host=parse_url($url);
  $header = array (
      "User-Agent: Mozilla/5.0",
      //'Referer: http://'.$host['host'],
  );
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  $output = curl_exec($ch);
  curl_close($ch);
  return $output;
}
?>

获取任意分类下的ID列表:     /kgmv.php?id=list 

获取华语精选分类下的ID列表:/kgmv.php?id=list&type=hyjx 

随机看MV:                  /kgmv.php?id=top


※ 感谢您的支持,如果喜欢本内容,请打赏本站!谢谢!
打赏 支付宝打赏 微信打赏

扫描二维码推送至手机访问。

版权声明:本文由 鹦鹉台 发布,如需转载请注明出处。

本文链接:https://zimtv.cn/tool/酷狗音乐MV轮播PHP.html

分享给朋友:

“酷狗音乐MV轮播PHP” 的相关文章

网页定时展示代码

网页定时展示代码

网页定时展示代码:var PlayList={     list:{ '06:00':'播放内容一',...

Lightbox弹出层插件:jQuery弹出层插件用法

Lightbox弹出层插件:jQuery弹出层插件用法

Lightbox弹出层插件说明文档  :1.引入资源,(JQ1.3+)和JS文件<script type="text/javascript" s...

为你的主题加上loading效果

为你的主题加上loading效果

第一步: 新建一个loading样式css 将以下代码放进去 然后引用这个文件#Loadanimation{     background-col...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。