<?php
header(
'Content-type: text/json;charset=utf-8'
);
$mv_id
=
'14316913'
;
$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
;
}