-
-
Save losywee/587e9ce5e922c5c361740b8ff3afa5c9 to your computer and use it in GitHub Desktop.
网易云音乐MV解析- PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
## Save as: 163.php | |
// Musci Video - Format: http://localhost/163.php?pv=720&id=313066 | |
// Musci Singer - Format: http://localhost/163.php?request=singer&id=313066 | |
// Musci Name - Format: http://localhost/163.php?request=name&id=313066 | |
// Musci Cover - Format: http://localhost/163.php?request=cover&id=313066 | |
## Can append suffix to the link. Example: http://localhost/163.php?pv=720&id=313066.mp4 | |
## No Internal Error Output | |
ERROR_REPORTING(0); | |
## Get Param | |
if (isset($_GET['id'])) { | |
preg_match('/\d+/i', $_GET['id'], $id_matches); | |
$mv_id = $id_matches[0]; | |
} else { | |
echo "Known Error! Not Found ID." . "<br>"; | |
return false; | |
} | |
if (isset($_GET['pv'])) { | |
switch ($_GET["pv"]) { | |
case '480': $mv_pv = '480'; break; // Options: 1080,720,480,240; Don't Support 240P; | |
case '720': $mv_pv = '720'; break; | |
default: $mv_pv = '1080'; break; | |
} | |
} else { $mv_pv = '1080'; } | |
$request = isset($_GET['request']) ? $_GET['request'] : ''; | |
## Functions | |
function curl_get($url) { | |
$refer = "http://music.163.com/"; | |
$header[] = "Cookie: " . "appver=1.5.0.75771;"; // Optional | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); | |
curl_setopt($ch, CURLOPT_REFERER, $refer); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
return $output; | |
} | |
function get_mv_info($mv_id) { | |
$url = "http://music.163.com/api/mv/detail/?id=" . $mv_id . "&type=mp4"; | |
$json_data = curl_get($url); | |
return json_decode($json_data, true); | |
} | |
function get_mv_url($mv_id) { | |
$output_arr = get_mv_info($mv_id); | |
if (isset($output_arr['data']['brs'])){ | |
$object_arr = $output_arr['data']['brs']; | |
if (isset($object_arr[$mv_pv])) { $mv_url = $object_arr[$mv_pv]; } | |
else if (isset($object_arr['1080'])) { $mv_url = $object_arr['1080']; } | |
else if (isset($object_arr['720'])) { $mv_url = $object_arr['720']; } | |
else if (isset($object_arr['480'])) { $mv_url = $object_arr['480']; } | |
} else { | |
echo "Known Error! Not Found Resource." . "<br>"; | |
return false; | |
} | |
header('Content-Type:video/mp4'); | |
header("Location:".$mv_url); | |
} | |
function get_mv_cover_url($mv_id) { | |
$output_arr = get_mv_info($mv_id); | |
if (isset($output_arr['data']['cover'])) { | |
$mv_cover_url = $output_arr['data']['cover']; | |
} else { | |
echo "Known Error! Not Found Resource." . "<br>"; | |
return false; | |
} | |
header('Content-Type:image/jpeg'); | |
header("Location:".$mv_cover_url); | |
} | |
function get_mv_name($mv_id) { | |
$output_arr = get_mv_info($mv_id); | |
if (isset($output_arr['data']['name'])) { | |
echo $output_arr['data']['name']; | |
} else { return false; } | |
} | |
function get_mv_singer($mv_id) { | |
$output_arr = get_mv_info($mv_id); | |
if (isset($output_arr['data']['artistName'])) { | |
echo $output_arr['data']['artistName']; | |
} else { return false; } | |
} | |
## Output Data | |
switch ($request) { | |
case 'singer': | |
get_mv_singer($mv_id); | |
break; | |
case 'name': | |
get_mv_name($mv_id); | |
break; | |
case 'cover': | |
get_mv_cover_url($mv_id); | |
break; | |
default: | |
get_mv_url($mv_id); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment