升级 Meting 至最新版

修复网易云音乐失效
pull/21/head
mengkunsoft 2018-02-06 10:21:27 +08:00
parent 404f1dadae
commit 3ce5b8facf
1 changed files with 595 additions and 578 deletions

View File

@ -1,11 +1,11 @@
<?php
/*!
/**
* Meting music framework
* https://i-meto.com
* https://github.com/metowolf/Meting
* Version 1.3.10
* Version 1.4.0
*
* Copyright 2017, METO Sheel <i@i-meto.com>
* Copyright 2018, METO Sheel <i@i-meto.com>
* Released under the MIT license
*/
@ -25,21 +25,22 @@ class Meting
public function site($v)
{
$suppose=array('netease','tencent','xiami','kugou','baidu');
$this->_SITE=in_array($v,$suppose)?$v:'netease';
$suppose = array('netease', 'tencent', 'xiami', 'kugou', 'baidu');
$this->_SITE = in_array($v,$suppose) ? $v : 'netease';
return $this;
}
public function cookie($v = '')
{
if (!empty($v)) {
$this->_TEMP['cookie']=$v;
$this->_TEMP['cookie'] = $v;
}
return $this;
}
public function format($v = true)
{
$this->_FORMAT=$v;
$this->_FORMAT = $v;
return $this;
}
@ -48,17 +49,17 @@ class Meting
if (isset($API['encode'])) {
$API=call_user_func_array(array($this,$API['encode']), array($API));
}
$BASE=$this->curlset();
$curl=curl_init();
if ($API['method']=='POST') {
$BASE = $this->curlset();
$curl = curl_init();
if ($API['method'] == 'POST') {
if (is_array($API['body'])) {
$API['body']=http_build_query($API['body']);
$API['body'] = http_build_query($API['body']);
}
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $API['body']);
} elseif ($API['method']=='GET') {
} elseif ($API['method'] == 'GET') {
if (isset($API['body'])) {
$API['url']=$API['url'].'?'.http_build_query($API['body']);
$API['url'] = $API['url'].'?'.http_build_query($API['body']);
}
}
curl_setopt($curl, CURLOPT_HEADER, 0);
@ -70,13 +71,20 @@ class Meting
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_URL, $API['url']);
curl_setopt($curl, CURLOPT_COOKIE, isset($this->_TEMP['cookie'])?$this->_TEMP['cookie']:$BASE['cookie']);
curl_setopt($curl, CURLOPT_REFERER, $BASE['referer']);
curl_setopt($curl, CURLOPT_USERAGENT, $BASE['useragent']);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Accept: */*',
'Accept-Encoding: gzip, deflate',
'Accept-Language: zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
'Referer: ' . $BASE['referer'],
'User-Agent: ' . $BASE['useragent']
]);
for ($i=0;$i<=$this->_RETRY;$i++) {
$data=curl_exec($curl);
$info=curl_getinfo($curl);
$error=curl_errno($curl);
$status=$error?curl_error($curl):'';
$data = curl_exec($curl);
$info = curl_getinfo($curl);
$error = curl_errno($curl);
$status = $error ? curl_error($curl) : '';
if (!$error) {
break;
}
@ -91,25 +99,25 @@ class Meting
)
);
}
if ($this->_FORMAT&&isset($API['decode'])) {
$data=call_user_func_array(array($this,$API['decode']), array($data));
if ($this->_FORMAT && isset($API['decode'])) {
$data = call_user_func_array(array($this,$API['decode']), array($data));
}
if ($this->_FORMAT&&isset($API['format'])) {
$data=json_decode($data, 1);
$data=$this->clean($data, $API['format']);
$data=json_encode($data);
if ($this->_FORMAT && isset($API['format'])) {
$data = json_decode($data, 1);
$data = $this->clean($data, $API['format']);
$data = json_encode($data);
}
return $data;
}
private function pickup($array, $rule)
{
$t=explode('#', $rule);
$t = explode('#', $rule);
foreach ($t as $vo) {
if (!isset($array[$vo])){
return array();
}
$array=$array[$vo];
$array = $array[$vo];
}
return $array;
}
@ -117,30 +125,30 @@ class Meting
private function clean($raw, $rule)
{
if (!empty($rule)) {
$raw=$this->pickup($raw, $rule);
$raw = $this->pickup($raw, $rule);
}
if (!isset($raw[0])&&sizeof($raw)) {
$raw=array($raw);
if (!isset($raw[0]) && sizeof($raw)) {
$raw = array($raw);
}
$result=array_map(array($this,'format_'.$this->_SITE), $raw);
$result = array_map(array($this,'format_'.$this->_SITE), $raw);
return $result;
}
public function search($keyword, $page=1, $limit=30)
public function search($keyword, $option = null)
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
'method' => 'POST',
'params' => array(
's' => $keyword,
'type' => 1,
'limit' => $limit,
'type' => isset($option['type']) ? $option['type'] : 1,
'limit' => isset($option['limit']) ? $option['limit'] : 30,
'total' => 'true',
'offset' => ($page-1)*$limit,
'offset' => isset($option['page']) && isset($option['limit']) ? ($option['page'] - 1) * $option['limit'] : 0,
),
'url' => 'http://music.163.com/api/cloudsearch/pc',
),
@ -149,13 +157,13 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp',
'body' => array(
'format' => 'json',
'p' => $page,
'n' => $limit,
'p' => isset($option['page']) ? $option['page'] : 1,
'n' => isset($option['limit']) ? $option['limit'] : 30,
'w' => $keyword,
'aggr' => 1,
'lossless' => 1,
@ -166,32 +174,32 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
'v' => '2.0',
'app_key' => '1',
'key' => $keyword,
'page' => $page,
'limit' => $limit,
'page' => isset($option['page']) ? $option['page'] : 1,
'limit' => isset($option['limit']) ? $option['limit'] : 30,
'r' => 'search/songs',
),
'format' => 'data#songs',
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://ioscdn.kugou.com/api/v3/search/song',
'body' => array(
'iscorrect' => 1,
'pagesize' => $limit,
'pagesize' => isset($option['limit']) ? $option['limit'] : 30,
'plat' => 2,
'tag' => 1,
'sver' => 5,
'showtype' => 10,
'page' => $page,
'page' => isset($option['page']) ? $option['page'] : 1,
'keyword' => $keyword,
'version' => 8550
),
@ -199,16 +207,16 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
'method' => 'baidu.ting.search.merge',
'isNew' => 1,
'query' => $keyword,
'page_size' => $limit,
'page_no' => $page,
'type' => 0,
'page_size' => isset($option['limit']) ? $option['limit'] : 30,
'page_no' => isset($option['page']) ? $option['page'] : 1,
'type' => isset($option['type']) ? $option['type'] : 0,
'format' => 'json',
'from' => 'ios',
'channel' => '(null)',
@ -227,22 +235,22 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
'method' => 'POST',
'params' => array(
'c' => '[{"id":'.$id.'}]',
'c' => '[{"id":'.$id.',"v":0}]',
),
'url' => 'http://music.163.com/api/v3/song/detail',
'url' => 'http://music.163.com/api/v3/song/detail/',
),
'encode' => 'netease_AESECB',
'format' => 'songs',
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg',
'body' => array(
@ -255,7 +263,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
@ -268,7 +276,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://m.kugou.com/app/i/getSongInfo.php',
'body' => array(
@ -280,7 +288,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
@ -304,13 +312,18 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
'method' => 'GET',
'params' => array(
'id' => $id,
"total" => "true",
"offset" => "0",
"id" => $id,
"limit" => "1000",
"ext" => "true",
"private_cloud" => "true"
),
'url' => 'http://music.163.com/api/v1/album/'.$id,
),
@ -319,7 +332,7 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_album_detail_cp.fcg',
'body' => array(
@ -332,7 +345,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
@ -345,7 +358,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://mobilecdn.kugou.com/api/v3/album/song',
'body' => array(
@ -359,7 +372,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
@ -383,15 +396,17 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
'method' => 'GET',
'params' => array(
'top' => $limit,
"id" => $id,
"ext" => "true",
"private_cloud" => "true",
"ext" => "true",
"top" => $limit,
"id" => $id
),
'url' => 'http://music.163.com/api/v1/artist/'.$id,
),
@ -400,7 +415,7 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg',
'body' => array(
@ -415,7 +430,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
@ -430,7 +445,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://mobilecdn.kugou.com/api/v3/singer/song',
'body' => array(
@ -444,7 +459,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
@ -469,14 +484,16 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
'method' => 'POST',
'params' => array(
'id' => $id,
"n" => 1000,
"s" => "0",
"id" => $id,
"n" => "1000",
"t" => "0"
),
'url' => 'http://music.163.com/api/v3/playlist/detail',
),
@ -485,7 +502,7 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_playlist_cp.fcg',
'body' => array(
@ -498,7 +515,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
@ -511,7 +528,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://mobilecdn.kugou.com/api/v3/special/song',
'body' => array(
@ -525,7 +542,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
@ -549,7 +566,7 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
@ -565,7 +582,7 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg',
'body' => array(
@ -577,7 +594,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://www.xiami.com/song/gethqsong/sid/'.$id,
'body' => array(
@ -590,7 +607,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://media.store.kugou.com/v1/get_res_privilege',
'body' => json_encode(array(
@ -611,7 +628,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://music.baidu.com/data/music/fmlink',
'body' => array(
@ -623,7 +640,7 @@ class Meting
);
break;
}
$this->_TEMP['br']=$br;
$this->_TEMP['br'] = $br;
return $this->curl($API);
}
@ -631,7 +648,7 @@ class Meting
{
switch ($this->_SITE) {
case 'netease':
$API=array(
$API = array(
'method' => 'POST',
'url' => 'http://music.163.com/api/linux/forward',
'body' => array(
@ -650,7 +667,7 @@ class Meting
);
break;
case 'tencent':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg',
'body' => array(
@ -661,7 +678,7 @@ class Meting
);
break;
case 'xiami':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://api.xiami.com/web',
'body' => array(
@ -674,7 +691,7 @@ class Meting
);
break;
case 'kugou':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'http://m.kugou.com/app/i/krc.php',
'body' => array(
@ -687,7 +704,7 @@ class Meting
);
break;
case 'baidu':
$API=array(
$API = array(
'method' => 'GET',
'url' => 'https://musicapi.qianqian.com/v1/restserver/ting',
'body' => array(
@ -749,31 +766,31 @@ class Meting
case 'netease':
return array(
'referer' => 'https://music.163.com/',
'cookie' => 'os=linux; appver=1.0.0.1026; osver=Ubuntu%2016.10; MUSIC_U=' . $this->getRandomHex(112) . '; __remember_me=true',
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'cookie' => 'os=linux; deviceId=' . $this->getRandomHex(52) . '; osver=Ubuntu%2016.04.3%20LTS; appver=1.1.0.1232; channel=netease; MUSIC_A=' . $this->getRandomHex(208) . '; __csrf=' . $this->getRandomHex(32),
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
);
case 'tencent':
return array(
'referer' => 'https://y.qq.com/portal/player.html',
'cookie' => 'pgv_pvi=22038528; pgv_si=s3156287488; pgv_pvid=5535248600; yplayer_open=1; ts_last=y.qq.com/portal/player.html; ts_uid=4847550686; yq_index=0; qqmusic_fromtag=66; player_exist=1',
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
);
case 'xiami':
return array(
'referer' => 'http://h.xiami.com/',
'cookie' => 'user_from=2;XMPLAYER_addSongsToggler=0;XMPLAYER_isOpen=0;_xiamitoken=123456789' . $this->getRandomHex(32) . ';',
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'cookie' => '_xiamitoken=' . $this->getRandomHex(32) . '; _unsign_token=' . $this->getRandomHex(32),
'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
);
case 'kugou':
return array(
'referer' => 'http://www.kugou.com/webkugouplayer/flash/webKugou.swf',
'cookie' => '_WCMID=123456789',
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'cookie' => 'kg_mid=' . $this->getRandomHex(32),
'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',
);
case 'baidu':
return array(
'referer' => 'http://ting.baidu.com/',
'cookie' => 'BAIDUID=123456789',
'cookie' => 'BAIDUID=' . $this->getRandomHex(32),
'useragent' => 'ios_5.9.12',
);
}
@ -781,11 +798,11 @@ class Meting
private function getRandomHex($length)
{
$val = '';
for( $i=0; $i<$length; $i++ ) {
$val .= chr( rand( 65, 90 ) );
if (function_exists('openssl_random_pseudo_bytes')) {
return bin2hex(openssl_random_pseudo_bytes($length));
} else {
return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
}
return $val;
}
/**