Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Last active July 8, 2020 21:23
Show Gist options
  • Save mysteriouss/d77bb005ac3712bcd01e1428c0de1e17 to your computer and use it in GitHub Desktop.
Save mysteriouss/d77bb005ac3712bcd01e1428c0de1e17 to your computer and use it in GitHub Desktop.
netease music -> qq
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 11/03/2018
* Time: 2:20 AM
*/
date_default_timezone_set('Asia/Shanghai');
if(!isset($argv[1])){
echo 'Usage: php netease.php $url' . PHP_EOL;
return;
}
echo str_replace('/#','',$argv[1]) . PHP_EOL;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => str_replace('/#','',$argv[1]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6",
"Cache-Control: no-cache",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
preg_match("/<h2 class=\"f-ff2\">(.*?)<\/h2>/i",$response,$album_name);
if(!count($album_name)) return;
echo 'album name: ' . PHP_EOL;
$album_name = end($album_name);
var_dump($album_name);
preg_match("/<a class=\"s-fc7\" .*?>(.*?)<\/a>/i",$response,$artist_name);
if(!count($artist_name)) return;
echo 'artist name: ' . PHP_EOL;
$artist_name = end($artist_name);
var_dump($artist_name);
preg_match("/<ul class=\"f-hide\">(.*?)<\/ul>/i",$response,$album);
echo 'album:' . PHP_EOL;
var_dump($album);
if(!count($album)){
//var_dump($response);
return;
}
$album = end($album);
preg_match_all("/<li><a href=\"\/song\?id=([0-9]+)\">(.*?)<\/a><\/li>/i",$album,$songs);
echo 'songs:' . PHP_EOL;
var_dump($songs);
if(!count($songs)){
return;
}
$songs_name = $songs[2];
$songs_info = array();
$index = 1;
foreach ($songs_name as $song_name){
$curl = curl_init();
$song_name .= '-' . $artist_name;
$song_name = urlencode($song_name);
curl_setopt_array($curl, array(
CURLOPT_URL => "http://music.able.cat/download/api/?id=$song_name&t=qq",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 5,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"User-Agent: JSBoxMain/97 CFNetwork/811.5.4 Darwin/16.7.0"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//echo $response . PHP_EOL;
$response = json_decode($response,true);
if(!is_array($response) ||
!array_key_exists('count',$response) ||
!array_key_exists('data',$response)){
continue;
}
$count = $response['count'];
if(intval($count) < 1){
continue;
}elseif (intval($count) > 1) {
//echo json_encode($response) . PHP_EOL;
}
$data = $response['data'];
if(is_array($data) && count($data)){
$data = reset($data);
}
if(is_array($data) &&
array_key_exists('flac',$data) &&
array_key_exists('Album',$data) &&
array_key_exists('title',$data) &&
array_key_exists('singer',$data) &&
array_key_exists('url', $data)
){
$album = $data['Album'];
$title = $data['title'];
$singer = $data['singer'];
$album = str_replace('/','|',$album);
$album = str_replace(':','',$album);
$path = __DIR__.'/'. $album_name;
$title = str_replace('/','|',$title);
$title = str_replace(':','',$title);
if(strlen( $data['flac'] )){
$flac = $data['flac'];
echo '<< '. $album . ' >> '. $index . '. ' . $title . PHP_EOL . $flac . PHP_EOL;
exec("mkdir -p \"$path\" && wget -q \"$flac\" -O \"$path/$index. $title - $singer.flac\"");
}else{
$url = $data['url'];
echo '<< '. $album . ' >> '. $index . '. ' . $title . PHP_EOL . $url . PHP_EOL;
exec("mkdir -p \"$path\" && wget -q \"$url\" -O \"$path/$index. $title - $singer.mp3\"");
}
//sleep(1);
}
}
$index ++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment