2017-01-28 21:23:45 +08:00
< ? php
2018-02-06 00:27:04 +08:00
/**
2017-01-28 21:23:45 +08:00
* Meting music framework
* https :// i - meto . com
2017-06-13 22:30:56 +08:00
* https :// github . com / metowolf / Meting
2018-03-08 14:18:32 +08:00
* Version 1.5 . 2.
2017-01-28 21:23:45 +08:00
*
2018-02-06 00:27:04 +08:00
* Copyright 2018 , METO Sheel < i @ i - meto . com >
2017-01-28 21:23:45 +08:00
* Released under the MIT license
*/
2017-06-13 22:30:56 +08:00
2017-04-12 12:53:58 +08:00
namespace Metowolf ;
2017-06-13 22:30:56 +08:00
2017-01-28 21:23:45 +08:00
class Meting
{
2018-03-08 14:18:32 +08:00
const VERSION = '1.5.2' ;
2017-01-28 21:23:45 +08:00
2018-03-03 23:19:26 +08:00
public $raw ;
public $data ;
public $info ;
public $error ;
public $status ;
public $server ;
public $format = false ;
2018-03-08 14:18:32 +08:00
public $header = array (
'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' ,
);
2018-03-03 23:19:26 +08:00
public function __construct ( $value = 'netease' )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
$this -> site ( $value );
2017-02-04 23:45:44 +08:00
}
2018-03-03 23:19:26 +08:00
public function site ( $value )
2017-03-18 21:02:03 +08:00
{
2018-02-06 00:27:04 +08:00
$suppose = array ( 'netease' , 'tencent' , 'xiami' , 'kugou' , 'baidu' );
2018-03-03 23:19:26 +08:00
$this -> server = in_array ( $value , $suppose ) ? $value : 'netease' ;
2018-03-08 14:18:32 +08:00
$this -> header = $this -> curlset ();
2018-03-03 23:19:26 +08:00
2017-02-04 23:45:44 +08:00
return $this ;
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
public function cookie ( $value )
2017-06-13 22:30:56 +08:00
{
2018-03-08 14:18:32 +08:00
$this -> header [ 'Cookie' ] = $value ;
2018-03-03 23:19:26 +08:00
2018-02-06 00:27:04 +08:00
return $this ;
2017-06-13 22:30:56 +08:00
}
2018-03-03 23:19:26 +08:00
public function format ( $value = true )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
$this -> format = $value ;
2017-01-28 21:23:45 +08:00
return $this ;
}
2018-03-03 23:19:26 +08:00
private function exec ( $api )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
if ( isset ( $api [ 'encode' ])) {
$api = call_user_func_array ( array ( $this , $api [ 'encode' ]), array ( $api ));
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
if ( $api [ 'method' ] == 'GET' ) {
if ( isset ( $api [ 'body' ])) {
$api [ 'url' ] .= '?' . http_build_query ( $api [ 'body' ]);
$api [ 'body' ] = null ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
}
$this -> curl ( $api [ 'url' ], $api [ 'body' ]);
if ( ! $this -> format ) {
return $this -> raw ;
}
$this -> data = $this -> raw ;
if ( isset ( $api [ 'decode' ])) {
$this -> data = call_user_func_array ( array ( $this , $api [ 'decode' ]), array ( $this -> data ));
}
if ( isset ( $api [ 'format' ])) {
$this -> data = $this -> clean ( $this -> data , $api [ 'format' ]);
}
return $this -> data ;
}
2018-03-08 14:18:32 +08:00
private function curl ( $url , $payload = null , $headerOnly = 0 )
2018-03-03 23:19:26 +08:00
{
2018-03-08 14:18:32 +08:00
$header = array_map ( function ( $k , $v ) {
return $k . ': ' . $v ;
}, array_keys ( $this -> header ), $this -> header );
2018-03-03 23:19:26 +08:00
$curl = curl_init ();
if ( ! is_null ( $payload )) {
2017-03-18 21:02:03 +08:00
curl_setopt ( $curl , CURLOPT_POST , 1 );
2018-03-03 23:19:26 +08:00
curl_setopt ( $curl , CURLOPT_POSTFIELDS , is_array ( $payload ) ? http_build_query ( $payload ) : $payload );
2017-01-28 21:23:45 +08:00
}
2018-03-08 14:18:32 +08:00
curl_setopt ( $curl , CURLOPT_HEADER , $headerOnly );
2017-03-18 21:02:03 +08:00
curl_setopt ( $curl , CURLOPT_TIMEOUT , 20 );
curl_setopt ( $curl , CURLOPT_ENCODING , 'gzip' );
curl_setopt ( $curl , CURLOPT_IPRESOLVE , 1 );
curl_setopt ( $curl , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $curl , CURLOPT_SSL_VERIFYPEER , 0 );
curl_setopt ( $curl , CURLOPT_CONNECTTIMEOUT , 10 );
2018-03-03 23:19:26 +08:00
curl_setopt ( $curl , CURLOPT_URL , $url );
2018-03-08 14:18:32 +08:00
curl_setopt ( $curl , CURLOPT_HTTPHEADER , $header );
2018-03-03 23:19:26 +08:00
for ( $i = 0 ; $i < 3 ; $i ++ ) {
$this -> raw = curl_exec ( $curl );
$this -> info = curl_getinfo ( $curl );
$this -> error = curl_errno ( $curl );
$this -> status = $this -> error ? curl_error ( $curl ) : '' ;
if ( ! $this -> error ) {
2017-03-18 21:02:03 +08:00
break ;
}
2017-02-04 23:45:44 +08:00
}
2017-01-28 21:23:45 +08:00
curl_close ( $curl );
2018-03-03 23:19:26 +08:00
return $this ;
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
private function pickup ( $array , $rule )
{
2018-03-03 23:19:26 +08:00
$t = explode ( '.' , $rule );
2017-03-18 21:02:03 +08:00
foreach ( $t as $vo ) {
2018-03-03 23:19:26 +08:00
if ( ! isset ( $array [ $vo ])) {
2017-06-13 22:30:56 +08:00
return array ();
2017-03-18 21:02:03 +08:00
}
2018-02-06 00:27:04 +08:00
$array = $array [ $vo ];
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return $array ;
}
2017-03-18 21:02:03 +08:00
private function clean ( $raw , $rule )
{
2018-03-03 23:19:26 +08:00
$raw = json_decode ( $raw , true );
2017-03-18 21:02:03 +08:00
if ( ! empty ( $rule )) {
2018-02-06 00:27:04 +08:00
$raw = $this -> pickup ( $raw , $rule );
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
if ( ! isset ( $raw [ 0 ]) && count ( $raw )) {
2018-02-06 00:27:04 +08:00
$raw = array ( $raw );
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
$result = array_map ( array ( $this , 'format_' . $this -> server ), $raw );
return json_encode ( $result );
2017-01-28 21:23:45 +08:00
}
2018-02-06 00:27:04 +08:00
public function search ( $keyword , $option = null )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/cloudsearch/pc' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
's' => $keyword ,
'type' => isset ( $option [ 'type' ]) ? $option [ 'type' ] : 1 ,
'limit' => isset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 30 ,
'total' => 'true' ,
'offset' => isset ( $option [ 'page' ]) && isset ( $option [ 'limit' ]) ? ( $option [ 'page' ] - 1 ) * $option [ 'limit' ] : 0 ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
'format' => 'result.songs' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp' ,
'body' => array (
'format' => 'json' ,
'p' => isset ( $option [ 'page' ]) ? $option [ 'page' ] : 1 ,
'n' => isset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 30 ,
'w' => $keyword ,
'aggr' => 1 ,
'lossless' => 1 ,
'cr' => 1 ,
'new_json' => 1 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.song.list' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.search.searchservice.searchsongs/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'key' => $keyword ,
'pagingVO' => array (
'page' => isset ( $option [ 'page' ]) ? $option [ 'page' ] : 1 ,
'pageSize' => isset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 30 ,
),
),
'r' => 'mtop.alimusic.search.searchservice.searchsongs' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
'format' => 'data.data.songs' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'http://ioscdn.kugou.com/api/v3/search/song' ,
'body' => array (
'iscorrect' => 1 ,
'pagesize' => isset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 30 ,
'plat' => 2 ,
'tag' => 1 ,
'sver' => 5 ,
'showtype' => 10 ,
'page' => isset ( $option [ 'page' ]) ? $option [ 'page' ] : 1 ,
'keyword' => $keyword ,
2018-03-03 23:19:26 +08:00
'version' => 8550 ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'format' => 'data.info' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
2018-02-06 00:27:04 +08:00
'method' => 'baidu.ting.search.merge' ,
'isNew' => 1 ,
2018-03-03 23:19:26 +08:00
'platform' => 'darwin' ,
'page_no' => isset ( $option [ 'page' ]) ? $option [ 'page' ] : 1 ,
2018-02-06 00:27:04 +08:00
'query' => $keyword ,
2018-03-03 23:19:26 +08:00
'version' => '11.0.2' ,
2018-02-06 00:27:04 +08:00
'page_size' => isset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 30 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'result.song_info.song_list' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
public function song ( $id )
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/v3/song/detail/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'c' => '[{"id":' . $id . ',"v":0}]' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
2018-02-06 00:27:04 +08:00
'format' => 'songs' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg' ,
'body' => array (
'songmid' => $id ,
'platform' => 'yqq' ,
'format' => 'json' ,
),
'decode' => 'tencent_singlesong' ,
'format' => 'data' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.songservice.getsongdetail/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'songId' => $id ,
),
'r' => 'mtop.alimusic.music.songservice.getsongdetail' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
'format' => 'data.data.songDetail' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
'url' => 'http://m.kugou.com/app/i/getSongInfo.php' ,
'body' => array (
2018-03-03 23:19:26 +08:00
'cmd' => 'playInfo' ,
'hash' => $id ,
'from' => 'mkugou' ,
2018-02-06 00:27:04 +08:00
),
'format' => '' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
'method' => 'baidu.ting.song.getInfos' ,
'songid' => $id ,
'res' => 1 ,
'platform' => 'darwin' ,
'version' => '1.0.0' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'baidu_AESCBC' ,
2018-02-06 00:27:04 +08:00
'format' => 'songinfo' ,
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
public function album ( $id )
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/v1/album/' . $id ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'total' => 'true' ,
'offset' => '0' ,
'id' => $id ,
'limit' => '1000' ,
'ext' => 'true' ,
'private_cloud' => 'true' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
2018-02-06 00:27:04 +08:00
'format' => 'songs' ,
);
break ;
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_album_detail_cp.fcg' ,
'body' => array (
'albummid' => $id ,
'platform' => 'mac' ,
'format' => 'json' ,
'newsong' => 1 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.getSongInfo' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.albumservice.getalbumdetail/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'albumId' => $id ,
),
'r' => 'mtop.alimusic.music.albumservice.getalbumdetail' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
'format' => 'data.data.albumDetail.songs' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'http://mobilecdn.kugou.com/api/v3/album/song' ,
'body' => array (
'albumid' => $id ,
'plat' => 2 ,
'page' => 1 ,
'pagesize' => - 1 ,
'version' => 8550 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.info' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
2018-02-06 00:27:04 +08:00
'method' => 'baidu.ting.album.getAlbumInfo' ,
'album_id' => $id ,
2018-03-03 23:19:26 +08:00
'platform' => 'darwin' ,
'version' => '11.0.2' ,
2018-02-06 00:27:04 +08:00
),
'format' => 'songlist' ,
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
public function artist ( $id , $limit = 50 )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/v1/artist/' . $id ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'ext' => 'true' ,
'private_cloud' => 'true' ,
'ext' => 'true' ,
'top' => $limit ,
'id' => $id ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
2018-02-06 00:27:04 +08:00
'format' => 'hotSongs' ,
);
break ;
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg' ,
'body' => array (
'singermid' => $id ,
'begin' => 0 ,
'num' => $limit ,
'order' => 'listen' ,
'platform' => 'mac' ,
'newsong' => 1 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.list' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.songservice.getartistsongs/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'artistId' => $id ,
'pagingVO' => array (
'page' => 1 ,
'pageSize' => $limit ,
),
),
'r' => 'mtop.alimusic.music.songservice.getartistsongs' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
'format' => 'data.data.songs' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'http://mobilecdn.kugou.com/api/v3/singer/song' ,
'body' => array (
'singerid' => $id ,
'page' => 1 ,
'plat' => 0 ,
'pagesize' => $limit ,
'version' => 8400 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.info' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
'method' => 'baidu.ting.artist.getSongList' ,
'artistid' => $id ,
'limits' => $limit ,
'platform' => 'darwin' ,
'offset' => 0 ,
'tinguid' => 0 ,
'version' => '11.0.2' ,
2018-02-06 00:27:04 +08:00
),
'format' => 'songlist' ,
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
public function playlist ( $id )
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/v3/playlist/detail' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
's' => '0' ,
'id' => $id ,
'n' => '1000' ,
't' => '0' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
'format' => 'playlist.tracks' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_playlist_cp.fcg' ,
'body' => array (
'id' => $id ,
'format' => 'json' ,
'newsong' => 1 ,
'platform' => 'jqspaframe.json' ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.cdlist.0.songlist' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.list.collectservice.getcollectdetail/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'listId' => $id ,
'isFullTags' => false ,
'pagingVO' => array (
'page' => 1 ,
'pageSize' => 1000 ,
),
),
'r' => 'mtop.alimusic.music.list.collectservice.getcollectdetail' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
'format' => 'data.data.collectDetail.songs' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'http://mobilecdn.kugou.com/api/v3/special/song' ,
'body' => array (
'specialid' => $id ,
'page' => 1 ,
'plat' => 2 ,
'pagesize' => - 1 ,
'version' => 8400 ,
),
2018-03-03 23:19:26 +08:00
'format' => 'data.info' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
'method' => 'baidu.ting.diy.gedanInfo' ,
'listid' => $id ,
'platform' => 'darwin' ,
'version' => '11.0.2' ,
2018-02-06 00:27:04 +08:00
),
'format' => 'content' ,
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
public function url ( $id , $br = 320 )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/song/enhance/player/url' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'ids' => array ( $id ),
'br' => $br * 1000 ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
2018-02-06 00:27:04 +08:00
'decode' => 'netease_url' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg' ,
'body' => array (
2018-03-03 23:19:26 +08:00
'songmid' => $id ,
2018-02-06 00:27:04 +08:00
'platform' => 'yqq' ,
2018-03-03 23:19:26 +08:00
'format' => 'json' ,
2018-02-06 00:27:04 +08:00
),
'decode' => 'tencent_url' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.songservice.getsongdetail/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'songId' => $id ,
),
'r' => 'mtop.alimusic.music.songservice.getsongdetail' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
2018-02-06 00:27:04 +08:00
'decode' => 'xiami_url' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
'url' => 'http://media.store.kugou.com/v1/get_res_privilege' ,
2018-03-03 23:19:26 +08:00
'body' => json_encode (
array (
'relate' => 1 ,
'userid' => 0 ,
'vip' => 0 ,
'appid' => 1005 ,
'token' => '' ,
'behavior' => 'download' ,
'clientver' => '8493' ,
'resource' => array ( array (
'id' => 0 ,
'type' => 'audio' ,
'hash' => $id ,
)), )
2018-02-06 00:27:04 +08:00
),
'decode' => 'kugou_url' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
'method' => 'baidu.ting.song.getInfos' ,
'songid' => $id ,
'res' => 1 ,
'platform' => 'darwin' ,
'version' => '1.0.0' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'baidu_AESCBC' ,
2018-02-06 00:27:04 +08:00
'decode' => 'baidu_url' ,
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
$this -> temp [ 'br' ] = $br ;
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
public function lyric ( $id )
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-03-18 21:02:03 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'POST' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://music.163.com/api/song/lyric' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'id' => $id ,
'os' => 'linux' ,
'lv' => - 1 ,
'kv' => - 1 ,
'tv' => - 1 ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'netease_AESCBC' ,
2018-02-06 00:27:04 +08:00
'decode' => 'netease_lyric' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg' ,
'body' => array (
2018-03-03 23:19:26 +08:00
'songmid' => $id ,
'g_tk' => '5381' ,
2018-02-06 00:27:04 +08:00
),
'decode' => 'tencent_lyric' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://h5api.m.xiami.com/h5/mtop.alimusic.music.lyricservice.getsonglyrics/1.0/' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'data' => array (
'songId' => $id ,
),
'r' => 'mtop.alimusic.music.lyricservice.getsonglyrics' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'encode' => 'xiami_sign' ,
2018-02-06 00:27:04 +08:00
'decode' => 'xiami_lyric' ,
);
break ;
2017-03-18 21:02:03 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'http://lyrics.kugou.com/search' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'keyword' => '%20-%20' ,
'ver' => 1 ,
'hash' => $id ,
'client' => 'pc' ,
'man' => 'no' ,
'duration' => 295058 ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'decode' => 'kugou_lyric' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$api = array (
2018-02-06 00:27:04 +08:00
'method' => 'GET' ,
2018-03-03 23:19:26 +08:00
'url' => 'https://gss2.baidu.com/6Ls1aze90MgYm2Gp8IqW0jdnxx1xbK/v1/restserver/ting' ,
2018-02-06 00:27:04 +08:00
'body' => array (
2018-03-03 23:19:26 +08:00
'from' => 'qianqianmini' ,
'method' => 'baidu.ting.song.lry' ,
'songid' => $id ,
'platform' => 'darwin' ,
'version' => '1.0.0' ,
2018-02-06 00:27:04 +08:00
),
2018-03-03 23:19:26 +08:00
'decode' => 'baidu_lyric' ,
2018-02-06 00:27:04 +08:00
);
break ;
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
return $this -> exec ( $api );
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
public function pic ( $id , $size = 300 )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2017-01-28 21:23:45 +08:00
case 'netease' :
2018-03-03 23:19:26 +08:00
$url = 'https://p3.music.126.net/' . $this -> netease_encryptId ( $id ) . '/' . $id . '.jpg?param=' . $size . 'y' . $size ;
2018-02-06 00:27:04 +08:00
break ;
2017-01-28 21:23:45 +08:00
case 'tencent' :
2018-03-03 23:19:26 +08:00
$url = 'https://y.gtimg.cn/music/photo_new/T002R' . $size . 'x' . $size . 'M000' . $id . '.jpg?max_age=2592000' ;
2018-02-06 00:27:04 +08:00
break ;
2017-01-28 21:23:45 +08:00
case 'xiami' :
2018-03-03 23:19:26 +08:00
$format = $this -> format ;
$data = $this -> format ( false ) -> song ( $id );
$this -> format = $format ;
$data = json_decode ( $data , true );
$url = $data [ 'data' ][ 'data' ][ 'songDetail' ][ 'albumLogo' ];
$url = str_replace ( 'http:' , 'https:' , $url ) . '@1e_1c_100Q_' . $size . 'h_' . $size . 'w' ;
2018-02-06 00:27:04 +08:00
break ;
2017-01-28 21:23:45 +08:00
case 'kugou' :
2018-03-03 23:19:26 +08:00
$format = $this -> format ;
$data = $this -> format ( false ) -> song ( $id );
$this -> format = $format ;
$data = json_decode ( $data , true );
$url = $data [ 'imgUrl' ];
$url = str_replace ( '{size}' , '400' , $url );
2018-02-06 00:27:04 +08:00
break ;
2017-01-28 21:23:45 +08:00
case 'baidu' :
2018-03-03 23:19:26 +08:00
$format = $this -> format ;
$data = $this -> format ( false ) -> song ( $id );
$this -> format = $format ;
$data = json_decode ( $data , true );
$url = isset ( $data [ 'songinfo' ][ 'pic_radio' ]) ? $data [ 'songinfo' ][ 'pic_radio' ] : $data [ 'songinfo' ][ 'pic_small' ];
2018-02-06 00:27:04 +08:00
break ;
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
return json_encode ( array ( 'url' => $url ));
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
private function curlset ()
{
2018-03-03 23:19:26 +08:00
switch ( $this -> server ) {
2018-01-02 21:53:23 +08:00
case 'netease' :
2018-02-06 00:27:04 +08:00
return array (
2018-03-08 14:18:32 +08:00
'Referer' => 'https://music.163.com/' ,
'Cookie' => 'os=pc; osver=Microsoft-Windows-10-Professional-build-10586-64bit; appver=2.0.3.131777; channel=netease; __remember_me=true' ,
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36' ,
'X-Real-IP' => long2ip ( mt_rand ( 1884815360 , 1884890111 )),
2018-02-06 00:27:04 +08:00
);
2018-01-02 21:53:23 +08:00
case 'tencent' :
2018-02-06 00:27:04 +08:00
return array (
2018-03-08 14:18:32 +08:00
'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' ,
'User-Agent' => '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' ,
2018-02-06 00:27:04 +08:00
);
2018-01-02 21:53:23 +08:00
case 'xiami' :
2018-02-06 00:27:04 +08:00
return array (
2018-03-08 14:18:32 +08:00
'Referer' => 'http://h5api.m.xiami.com/' ,
'Cookie' => '_m_h5_tk=15d3402511a022796d88b249f83fb968_1511163656929; _m_h5_tk_enc=b6b3e64d81dae577fc314b5c5692df3c' ,
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) XIAMI-MUSIC/3.0.9 Chrome/56.0.2924.87 Electron/1.6.11 Safari/537.36' ,
2018-02-06 00:27:04 +08:00
);
2018-01-02 21:53:23 +08:00
case 'kugou' :
2018-02-06 00:27:04 +08:00
return array (
2018-03-08 14:18:32 +08:00
'Referer' => 'http://www.kugou.com/webkugouplayer/flash/webKugou.swf' ,
'Cookie' => 'kg_mid=' . $this -> getRandomHex ( 32 ),
'User-Agent' => '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' ,
2018-02-06 00:27:04 +08:00
);
2018-01-02 21:53:23 +08:00
case 'baidu' :
2018-02-06 00:27:04 +08:00
return array (
2018-03-08 14:18:32 +08:00
'Cookie' => 'BAIDUID=' . $this -> getRandomHex ( 32 ) . ':FG=1' ,
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) baidu-music/1.0.2 Chrome/56.0.2924.87 Electron/1.6.11 Safari/537.36' ,
2018-02-06 00:27:04 +08:00
);
2018-01-02 21:53:23 +08:00
}
}
private function getRandomHex ( $length )
{
2018-02-06 00:27:04 +08:00
if ( function_exists ( 'openssl_random_pseudo_bytes' )) {
2018-03-03 23:19:26 +08:00
return bin2hex ( openssl_random_pseudo_bytes ( $length / 2 ));
2018-02-06 00:27:04 +08:00
} else {
2018-03-03 23:19:26 +08:00
return bin2hex ( mcrypt_create_iv ( $length / 2 , MCRYPT_DEV_URANDOM ));
2018-01-02 21:53:23 +08:00
}
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
private function bchexdec ( $hex )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
$dec = 0 ;
$len = strlen ( $hex );
for ( $i = 1 ; $i <= $len ; $i ++ ) {
$dec = bcadd ( $dec , bcmul ( strval ( hexdec ( $hex [ $i - 1 ])), bcpow ( '16' , strval ( $len - $i ))));
}
return $dec ;
}
private function bcdechex ( $dec )
{
$hex = '' ;
do {
$last = bcmod ( $dec , 16 );
$hex = dechex ( $last ) . $hex ;
$dec = bcdiv ( bcsub ( $dec , $last ), 16 );
} while ( $dec > 0 );
return $hex ;
}
private function str2hex ( $string )
{
$hex = '' ;
for ( $i = 0 ; $i < strlen ( $string ); $i ++ ) {
$ord = ord ( $string [ $i ]);
$hexCode = dechex ( $ord );
$hex .= substr ( '0' . $hexCode , - 2 );
}
return $hex ;
}
private function netease_AESCBC ( $api )
{
$modulus = '157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607' ;
$pubkey = '65537' ;
$nonce = '0CoJUm6Qyw8W8jud' ;
$vi = '0102030405060708' ;
2018-03-08 14:18:32 +08:00
if ( extension_loaded ( 'bcmath' )) {
$skey = $this -> getRandomHex ( 16 );
} else {
$skey = 'B3v3kH4vRPWRJFfH' ;
}
2018-03-03 23:19:26 +08:00
$body = json_encode ( $api [ 'body' ]);
2018-03-08 14:18:32 +08:00
if ( function_exists ( 'openssl_encrypt' )) {
$body = openssl_encrypt ( $body , 'aes-128-cbc' , $nonce , false , $vi );
$body = openssl_encrypt ( $body , 'aes-128-cbc' , $skey , false , $vi );
} else {
$pad = 16 - ( strlen ( $body ) % 16 );
$body = base64_encode ( mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $nonce , $body . str_repeat ( chr ( $pad ), $pad ), MCRYPT_MODE_CBC , $vi ));
$pad = 16 - ( strlen ( $body ) % 16 );
$body = base64_encode ( mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $skey , $body . str_repeat ( chr ( $pad ), $pad ), MCRYPT_MODE_CBC , $vi ));
}
if ( extension_loaded ( 'bcmath' )) {
$skey = strrev ( utf8_encode ( $skey ));
$skey = $this -> bchexdec ( $this -> str2hex ( $skey ));
$skey = bcpowmod ( $skey , $pubkey , $modulus );
$skey = $this -> bcdechex ( $skey );
$skey = str_pad ( $skey , 256 , '0' , STR_PAD_LEFT );
} else {
$skey = '85302b818aea19b68db899c25dac229412d9bba9b3fcfe4f714dc016bc1686fc446a08844b1f8327fd9cb623cc189be00c5a365ac835e93d4858ee66f43fdc59e32aaed3ef24f0675d70172ef688d376a4807228c55583fe5bac647d10ecef15220feef61477c28cae8406f6f9896ed329d6db9f88757e31848a6c2ce2f94308' ;
}
2018-03-03 23:19:26 +08:00
$api [ 'url' ] = str_replace ( '/api/' , '/weapi/' , $api [ 'url' ]);
$api [ 'body' ] = array (
'params' => $body ,
'encSecKey' => $skey ,
);
return $api ;
}
private function baidu_AESCBC ( $api )
{
$key = 'DBEECF8C50FD160E' ;
$vi = '1231021386755796' ;
$data = 'songid=' . $api [ 'body' ][ 'songid' ] . '&ts=' . intval ( microtime ( true ) * 1000 );
2017-03-18 21:02:03 +08:00
if ( function_exists ( 'openssl_encrypt' )) {
2018-03-03 23:19:26 +08:00
$data = openssl_encrypt ( $data , 'aes-128-cbc' , $key , false , $vi );
2017-03-18 21:02:03 +08:00
} else {
2018-03-08 14:18:32 +08:00
$pad = 16 - ( strlen ( $data ) % 16 );
$data = base64_encode ( mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $key , $data . str_repeat ( chr ( $pad ), $pad ), MCRYPT_MODE_CBC , $vi ));
2017-01-30 22:01:26 +08:00
}
2017-01-28 21:23:45 +08:00
2018-03-03 23:19:26 +08:00
$api [ 'body' ][ 'e' ] = $data ;
return $api ;
}
private function xiami_sign ( $api )
{
$data = $this -> curl ( 'http://h5api.m.xiami.com/h5/mtop.alimusic.search.searchservice.searchsongs/1.0/?appKey=12574478&t=1511168684000&dataType=json&data=%7B%22requestStr%22%3A%22%7B%5C%22model%5C%22%3A%7B%5C%22key%5C%22%3A%5C%22Dangerous+Woman%5C%22%2C%5C%22pagingVO%5C%22%3A%7B%5C%22page%5C%22%3A1%2C%5C%22pageSize%5C%22%3A30%7D%7D%7D%22%7D&api=mtop.alimusic.search.searchservice.searchsongs&v=1.0&type=originaljson&sign=f6c99a429e9ef703ea955f7cd113a467' , null , 1 );
preg_match_all ( '/_m_h5[^;]+/' , $data -> raw , $match );
2018-03-08 14:18:32 +08:00
$this -> header [ 'Cookie' ] = $match [ 0 ][ 0 ] . '; ' . $match [ 0 ][ 1 ];
2018-03-03 23:19:26 +08:00
$data = json_encode ( array (
'requestStr' => json_encode ( array (
'header' => array (
'platformId' => 'mac' ,
),
'model' => $api [ 'body' ][ 'data' ],
)),
));
$appkey = '12574478' ;
2018-03-08 14:18:32 +08:00
$cookie = $this -> header [ 'Cookie' ];
2018-03-03 23:19:26 +08:00
preg_match ( '/_m_h5_tk=([^_]+)/' , $cookie , $match );
$token = $match [ 1 ];
$t = time () * 1000 ;
$sign = md5 ( sprintf ( '%s&%s&%s&%s' , $token , $t , $appkey , $data ));
$api [ 'body' ] = array (
'appKey' => $appkey ,
't' => $t ,
'dataType' => 'json' ,
'data' => $data ,
'api' => $api [ 'body' ][ 'r' ],
'v' => '1.0' ,
'type' => 'originaljson' ,
'sign' => $sign ,
2017-01-28 21:23:45 +08:00
);
2018-03-03 23:19:26 +08:00
return $api ;
2017-01-28 21:23:45 +08:00
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function tencent_singlesong ( $result )
{
2018-03-03 23:19:26 +08:00
$result = json_decode ( $result , true );
$data = $result [ 'data' ][ 0 ];
$t = array (
'songmid' => $data [ 'mid' ],
2017-01-28 21:23:45 +08:00
'songname' => $data [ 'name' ],
'albummid' => $data [ 'album' ][ 'mid' ],
);
2018-03-03 23:19:26 +08:00
foreach ( $t as $key => $vo ) {
$result [ 'data' ][ 0 ][ $key ] = $vo ;
2017-02-27 16:31:17 +08:00
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
return json_encode ( $result );
2017-02-27 16:31:17 +08:00
}
2018-03-03 23:19:26 +08:00
private function netease_encryptId ( $id )
2017-03-18 21:02:03 +08:00
{
2018-03-03 23:19:26 +08:00
$magic = str_split ( '3go8&$8*3*3h0k(2)2' );
$song_id = str_split ( $id );
for ( $i = 0 ; $i < count ( $song_id ); $i ++ ) {
$song_id [ $i ] = chr ( ord ( $song_id [ $i ]) ^ ord ( $magic [ $i % count ( $magic )]));
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
$result = base64_encode ( md5 ( implode ( '' , $song_id ), 1 ));
$result = str_replace ( array ( '/' , '+' ), array ( '_' , '-' ), $result );
2017-01-28 21:23:45 +08:00
return $result ;
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function netease_url ( $result )
{
2018-03-03 23:19:26 +08:00
$data = json_decode ( $result , true );
2017-06-13 22:30:56 +08:00
if ( isset ( $data [ 'data' ][ 0 ][ 'uf' ][ 'url' ])) {
2018-03-03 23:19:26 +08:00
$data [ 'data' ][ 0 ][ 'url' ] = $data [ 'data' ][ 0 ][ 'uf' ][ 'url' ];
2017-09-20 23:21:31 +08:00
}
if ( isset ( $data [ 'data' ][ 0 ][ 'url' ])) {
2018-03-03 23:19:26 +08:00
$url = array (
'url' => $data [ 'data' ][ 0 ][ 'url' ],
'size' => $data [ 'data' ][ 0 ][ 'size' ],
'br' => $data [ 'data' ][ 0 ][ 'br' ] / 1000 ,
2017-04-12 12:53:58 +08:00
);
2017-06-13 22:30:56 +08:00
} else {
2018-03-03 23:19:26 +08:00
$url = array (
'url' => '' ,
'size' => 0 ,
'br' => - 1 ,
2017-06-13 22:30:56 +08:00
);
2017-04-12 12:53:58 +08:00
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $url );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function tencent_url ( $result )
{
2018-03-03 23:19:26 +08:00
$data = json_decode ( $result , true );
$guid = mt_rand () % 10000000000 ;
$api = array (
2017-01-28 21:23:45 +08:00
'method' => 'GET' ,
'url' => 'https://c.y.qq.com/base/fcgi-bin/fcg_musicexpress.fcg' ,
'body' => array (
2017-09-20 23:21:31 +08:00
'json' => 3 ,
2018-03-03 23:19:26 +08:00
'guid' => $guid ,
2017-09-20 23:21:31 +08:00
'format' => 'json' ,
2017-01-28 21:23:45 +08:00
),
);
2018-03-03 23:19:26 +08:00
$key = json_decode ( $this -> exec ( $api ), true );
$key = $key [ 'key' ];
$type = array (
'size_320mp3' => array ( 320 , 'M800' , 'mp3' ),
'size_192aac' => array ( 192 , 'C600' , 'm4a' ),
'size_128mp3' => array ( 128 , 'M500' , 'mp3' ),
'size_96aac' => array ( 96 , 'C400' , 'm4a' ),
'size_48aac' => array ( 48 , 'C200' , 'm4a' ),
'size_24aac' => array ( 24 , 'C100' , 'm4a' ),
2017-01-28 21:23:45 +08:00
);
2018-03-03 23:19:26 +08:00
foreach ( $type as $index => $vo ) {
if ( $data [ 'data' ][ 0 ][ 'file' ][ $index ] && $vo [ 0 ] <= $this -> temp [ 'br' ]) {
$url = array (
'url' => 'https://dl.stream.qqmusic.qq.com/' . $vo [ 1 ] . $data [ 'data' ][ 0 ][ 'file' ][ 'media_mid' ] . '.' . $vo [ 2 ] . '?vkey=' . $key . '&guid=' . $guid . '&uid=0&fromtag=30' ,
'size' => $data [ 'data' ][ 0 ][ 'file' ][ $index ],
'br' => $vo [ 0 ],
2017-01-28 21:23:45 +08:00
);
break ;
}
}
2017-06-13 22:30:56 +08:00
if ( ! isset ( $url [ 'url' ])) {
2018-03-03 23:19:26 +08:00
$url = array (
'url' => '' ,
'size' => 0 ,
'br' => - 1 ,
2017-06-13 22:30:56 +08:00
);
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $url );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function xiami_url ( $result )
{
2018-03-03 23:19:26 +08:00
$data = json_decode ( $result , true );
$type = array (
's' => 740 ,
'h' => 320 ,
'l' => 128 ,
'f' => 64 ,
'e' => 32 ,
);
$max = 0 ;
$url = array ();
foreach ( $data [ 'data' ][ 'data' ][ 'songDetail' ][ 'listenFiles' ] as $vo ) {
if ( $type [ $vo [ 'quality' ]] <= $this -> temp [ 'br' ] && $type [ $vo [ 'quality' ]] > $max ) {
$max = $type [ $vo [ 'quality' ]];
$url = array (
'url' => $vo [ 'url' ],
'size' => $vo [ 'filesize' ],
'br' => $type [ $vo [ 'quality' ]],
);
2017-04-12 12:53:58 +08:00
}
2018-03-03 23:19:26 +08:00
}
if ( ! isset ( $url [ 'url' ])) {
$url = array (
'url' => '' ,
'size' => 0 ,
'br' => - 1 ,
2017-04-12 12:53:58 +08:00
);
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $url );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function kugou_url ( $result )
{
2018-03-03 23:19:26 +08:00
$data = json_decode ( $result , true );
2017-01-28 21:23:45 +08:00
2018-03-03 23:19:26 +08:00
$max = 0 ;
$url = array ();
2017-03-18 21:02:03 +08:00
foreach ( $data [ 'data' ][ 0 ][ 'relate_goods' ] as $vo ) {
2018-03-03 23:19:26 +08:00
if ( $vo [ 'info' ][ 'bitrate' ] <= $this -> temp [ 'br' ] && $vo [ 'info' ][ 'bitrate' ] > $max ) {
$api = array (
2017-01-28 21:23:45 +08:00
'method' => 'GET' ,
'url' => 'http://trackercdn.kugou.com/i/v2/' ,
'body' => array (
'hash' => $vo [ 'hash' ],
'key' => md5 ( $vo [ 'hash' ] . 'kgcloudv2' ),
'pid' => 1 ,
'behavior' => 'play' ,
'cmd' => '23' ,
'version' => 8400 ,
),
);
2018-03-03 23:19:26 +08:00
$t = json_decode ( $this -> exec ( $api ), true );
2017-03-18 21:02:03 +08:00
if ( isset ( $t [ 'url' ])) {
2018-03-03 23:19:26 +08:00
$max = $t [ 'bitRate' ] / 1000 ;
$url = array (
'url' => $t [ 'url' ],
'size' => $t [ 'fileSize' ],
'br' => $t [ 'bitRate' ] / 1000 ,
2017-01-28 21:23:45 +08:00
);
}
}
}
2017-06-13 22:30:56 +08:00
if ( ! isset ( $url [ 'url' ])) {
2018-03-03 23:19:26 +08:00
$url = array (
'url' => '' ,
'size' => 0 ,
'br' => - 1 ,
2017-06-13 22:30:56 +08:00
);
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $url );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function baidu_url ( $result )
{
2018-03-03 23:19:26 +08:00
$data = json_decode ( $result , true );
$max = 0 ;
$url = array ();
foreach ( $data [ 'songurl' ][ 'url' ] as $vo ) {
if ( $vo [ 'file_bitrate' ] <= $this -> temp [ 'br' ] && $vo [ 'file_bitrate' ] > $max ) {
$url = array (
'url' => $vo [ 'file_link' ],
'br' => $vo [ 'file_bitrate' ],
);
}
}
if ( ! isset ( $url [ 'url' ])) {
$url = array (
2017-06-13 22:30:56 +08:00
'url' => '' ,
'br' => - 1 ,
);
}
2018-03-03 23:19:26 +08:00
2017-02-27 16:31:17 +08:00
return json_encode ( $url );
}
2018-03-03 23:19:26 +08:00
2017-04-12 12:53:58 +08:00
private function netease_lyric ( $result )
{
2018-03-03 23:19:26 +08:00
$result = json_decode ( $result , true );
$data = array (
'lyric' => isset ( $result [ 'lrc' ][ 'lyric' ]) ? $result [ 'lrc' ][ 'lyric' ] : '' ,
'tlyric' => isset ( $result [ 'tlyric' ][ 'lyric' ]) ? $result [ 'tlyric' ][ 'lyric' ] : '' ,
2017-04-12 12:53:58 +08:00
);
2018-03-03 23:19:26 +08:00
2017-04-12 12:53:58 +08:00
return json_encode ( $data );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function tencent_lyric ( $result )
{
2018-03-03 23:19:26 +08:00
$result = substr ( $result , 18 , - 1 );
$result = json_decode ( $result , true );
$data = array (
'lyric' => isset ( $result [ 'lyric' ]) ? base64_decode ( $result [ 'lyric' ]) : '' ,
'tlyric' => isset ( $result [ 'trans' ]) ? base64_decode ( $result [ 'trans' ]) : '' ,
2018-02-06 00:27:04 +08:00
);
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
return json_encode ( $data );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function xiami_lyric ( $result )
{
2018-03-03 23:19:26 +08:00
$result = json_decode ( $result , true );
if ( count ( $result [ 'data' ][ 'data' ][ 'lyrics' ])) {
$data = $result [ 'data' ][ 'data' ][ 'lyrics' ][ 0 ][ 'content' ];
$data = preg_replace ( '/<[^>]+>/' , '' , $data );
preg_match_all ( '/\[([\d:\.]+)\](.*)\s\[x-trans\](.*)/i' , $data , $match );
if ( count ( $match [ 0 ])) {
for ( $i = 0 ; $i < count ( $match [ 0 ]); $i ++ ) {
$A [] = '[' . $match [ 1 ][ $i ] . ']' . $match [ 2 ][ $i ];
$B [] = '[' . $match [ 1 ][ $i ] . ']' . $match [ 3 ][ $i ];
}
$arr = array (
'lyric' => str_replace ( $match [ 0 ], $A , $data ),
'tlyric' => str_replace ( $match [ 0 ], $B , $data ),
);
} else {
$arr = array (
'lyric' => $data ,
'tlyric' => '' ,
);
2017-07-01 11:54:31 +08:00
}
2018-03-03 23:19:26 +08:00
} else {
$arr = array (
'lyric' => '' ,
2017-07-01 11:54:31 +08:00
'tlyric' => '' ,
);
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $arr );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function kugou_lyric ( $result )
{
2018-03-03 23:19:26 +08:00
$result = json_decode ( $result , true );
$api = array (
'method' => 'GET' ,
'url' => 'http://lyrics.kugou.com/download' ,
'body' => array (
'charset' => 'utf8' ,
'accesskey' => $result [ 'candidates' ][ 0 ][ 'accesskey' ],
'id' => $result [ 'candidates' ][ 0 ][ 'id' ],
'client' => 'pc' ,
'fmt' => 'lrc' ,
'ver' => 1 ,
),
);
$data = json_decode ( $this -> exec ( $api ), true );
$arr = array (
'lyric' => base64_decode ( $data [ 'content' ]),
2017-06-13 22:30:56 +08:00
'tlyric' => '' ,
2017-01-28 21:23:45 +08:00
);
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return json_encode ( $arr );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function baidu_lyric ( $result )
{
2018-03-03 23:19:26 +08:00
$result = json_decode ( $result , true );
$data = array (
'lyric' => isset ( $result [ 'lrcContent' ]) ? $result [ 'lrcContent' ] : '' ,
2017-06-13 22:30:56 +08:00
'tlyric' => '' ,
2017-02-04 23:45:44 +08:00
);
2018-03-03 23:19:26 +08:00
2017-02-04 23:45:44 +08:00
return json_encode ( $data );
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function format_netease ( $data )
{
2018-03-03 23:19:26 +08:00
$result = array (
'id' => $data [ 'id' ],
'name' => $data [ 'name' ],
'artist' => array (),
'album' => $data [ 'al' ][ 'name' ],
'pic_id' => isset ( $data [ 'al' ][ 'pic_str' ]) ? $data [ 'al' ][ 'pic_str' ] : $data [ 'al' ][ 'pic' ],
'url_id' => $data [ 'id' ],
'lyric_id' => $data [ 'id' ],
'source' => 'netease' ,
2017-01-28 21:23:45 +08:00
);
2017-03-18 21:02:03 +08:00
if ( isset ( $data [ 'al' ][ 'picUrl' ])) {
preg_match ( '/\/(\d+)\./' , $data [ 'al' ][ 'picUrl' ], $match );
2018-03-03 23:19:26 +08:00
$result [ 'pic_id' ] = $match [ 1 ];
2017-01-28 21:23:45 +08:00
}
2017-03-18 21:02:03 +08:00
foreach ( $data [ 'ar' ] as $vo ) {
2018-03-03 23:19:26 +08:00
$result [ 'artist' ][] = $vo [ 'name' ];
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return $result ;
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function format_tencent ( $data )
{
if ( isset ( $data [ 'musicData' ])) {
2018-03-03 23:19:26 +08:00
$data = $data [ 'musicData' ];
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
$result = array (
'id' => $data [ 'mid' ],
'name' => $data [ 'name' ],
'artist' => array (),
'album' => trim ( $data [ 'album' ][ 'title' ]),
'pic_id' => $data [ 'album' ][ 'mid' ],
'url_id' => $data [ 'mid' ],
'lyric_id' => $data [ 'mid' ],
'source' => 'tencent' ,
2017-01-28 21:23:45 +08:00
);
2017-03-18 21:02:03 +08:00
foreach ( $data [ 'singer' ] as $vo ) {
2018-03-03 23:19:26 +08:00
$result [ 'artist' ][] = $vo [ 'name' ];
2017-03-18 21:02:03 +08:00
}
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return $result ;
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function format_xiami ( $data )
{
2018-03-03 23:19:26 +08:00
$result = array (
'id' => $data [ 'songId' ],
'name' => $data [ 'songName' ],
'artist' => array (),
'album' => $data [ 'albumName' ],
'pic_id' => $data [ 'songId' ],
'url_id' => $data [ 'songId' ],
'lyric_id' => $data [ 'songId' ],
2017-01-28 21:23:45 +08:00
'source' => 'xiami' ,
);
2018-03-03 23:19:26 +08:00
foreach ( $data [ 'singerVOs' ] as $vo ) {
$result [ 'artist' ][] = $vo [ 'artistName' ];
}
2017-01-28 21:23:45 +08:00
return $result ;
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function format_kugou ( $data )
{
2018-03-03 23:19:26 +08:00
$result = array (
2017-01-28 21:23:45 +08:00
'id' => $data [ 'hash' ],
2018-03-03 23:19:26 +08:00
'name' => isset ( $data [ 'filename' ]) ? $data [ 'filename' ] : $data [ 'fileName' ],
2017-01-28 21:23:45 +08:00
'artist' => array (),
2018-03-03 23:19:26 +08:00
'album' => isset ( $data [ 'album_name' ]) ? $data [ 'album_name' ] : '' ,
2017-01-28 21:23:45 +08:00
'url_id' => $data [ 'hash' ],
'pic_id' => $data [ 'hash' ],
'lyric_id' => $data [ 'hash' ],
'source' => 'kugou' ,
);
2018-03-03 23:19:26 +08:00
list ( $result [ 'artist' ], $result [ 'name' ]) = explode ( ' - ' , $result [ 'name' ], 2 );
$result [ 'artist' ] = explode ( '、' , $result [ 'artist' ]);
2017-01-28 21:23:45 +08:00
return $result ;
}
2018-03-03 23:19:26 +08:00
2017-03-18 21:02:03 +08:00
private function format_baidu ( $data )
{
2018-03-03 23:19:26 +08:00
$result = array (
2017-01-28 21:23:45 +08:00
'id' => $data [ 'song_id' ],
'name' => $data [ 'title' ],
2017-03-18 21:02:03 +08:00
'artist' => explode ( ',' , $data [ 'author' ]),
2017-07-01 11:54:31 +08:00
'album' => $data [ 'album_title' ],
2017-01-28 21:23:45 +08:00
'pic_id' => $data [ 'song_id' ],
'url_id' => $data [ 'song_id' ],
'lyric_id' => $data [ 'song_id' ],
'source' => 'baidu' ,
);
2018-03-03 23:19:26 +08:00
2017-01-28 21:23:45 +08:00
return $result ;
}
}