/* */

网易云音乐MV在线解析代码 PHP源码

分类:实用代码 时间:2022-11-22 15:38 浏览:0 评论:0
0

本代码可实现输入MV的id,直接解析出mp4的地址来,可以下载观看。

<?php
header('Content-type: text/json;charset=utf-8');
$mv_id  = '14316913';//这里写mv的id
$array  = parse_url('https://music.163.com/mv?id='.$mv_id);
$id     = str_replace("id=", "",$array['query']);
$html   = music163_mv('http://music.163.com/api/mv/detail/?id='.$id.'&type=mp4');
$mv     = json_decode($html, true);
if($mv['code'] == '200'){
    $json           =   ['code'=> 1, 'msg'=>"解析成功"];
    $json['desc']   =   empty($mv['data']['desc']) ? '暂无简介' : $mv['data']['desc'];
    $json['title']  =   $mv['data']['name'];
    $json['list']   =   array_map(function($url){
        return str_replace("http://", "https://", $url);
    }, $mv['data']['brs']);
    foreach($mv['data']['artists'] as $pron){
        $json['artists'][]  =   ['name' =>  $pron['name']];
    }
    if (!empty($_GET['brs']) && $json['list'][$_GET['brs']] != '') {
        header('location:'.$json['list'][$_GET['brs']]);
    }
}else{
    $json = ['code'=> 0, 'msg'=>"解析失败!请检查视频地址是否正确(*^_^*)"];
}
echo json_encode($json, 480);
function music163_mv($url) {
    $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_RETURNTRANSFER, true) ;
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;
    $output = curl_exec($ch) ;
    curl_close ($ch);
    return $output;
}

解析出来是这个样子:

{
    "code": 1,
    "msg": "解析成功",
    "desc": "暂无简介",
    "title": "这世界那么多人 (电影《我要我们在一起》主题曲)",
    "list": {
        "240": "https://vodkgeyttp8.vod.126.net/cloudmusic/08b0/core/4670/f6678cdf81445f0e505eb65a18469ceb.mp4?wsSecret=569333b018f80079b5ae507d25b487d4&wsTime=1655215107",
        "480": "https://vodkgeyttp8.vod.126.net/cloudmusic/08b0/core/4670/e53f624135cbf89b1b663a8213dbb474.mp4?wsSecret=1d396b02d597b12aeb3786630f29ed6f&wsTime=1655215107",
        "720": "https://vodkgeyttp8.vod.126.net/cloudmusic/08b0/core/4670/ca624963e49caa4e45e601e79d5de024.mp4?wsSecret=3fcb753ab9a935c7894913885190f9c5&wsTime=1655215107"
    },
    "artists": [
        {
            "name": "莫文蔚"
        }
    ]
}


1. 本站所有资源来源于用户上传或网络,仅作为参考研究使用,如有侵权请邮件联系站长!
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4. 实用代码 > 网易云音乐MV在线解析代码 PHP源码

用户评论