QQ soso音乐搜索api 演示地址:http://www.ip62.com/qqmusic/ 点击mp3地址后面的直接在线播放
- class music {
- private $musicname;
-
- public function __construct($musicname){
- $this->musicname = $musicname;
- }
- private function map_url(){
-
- $url = "http://shopcgi.qqmusic.qq.com/fcgi-bin/shopsearch.fcg?value=".urlencode(iconv("utf-8","gb2312",$this->musicname));
- if(!function_exists("file_get_contents"))
- {
- $ch = curl_init();
- $timeout = 5;
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- }else{
- $file_contents = file_get_contents($url);
- }
- return $file_contents;
- }
-
- public function getmusic(){
- $data = $this-> map_url();
- $data = substr($data,15);
- $data = substr($data,0,-2);
- preg_match("/songlist\:\[(?P.*)\]\}/i", $data,$musicdata);
- $musicdata = explode(",",$musicdata['music']);
- $music = array();
- foreach($musicdata as $v){
- if(preg_match("/\{idx\:(?P.*)/i",$v,$a)){
- $id = trim($a[id],"\"");
- }
- if(preg_match("/song_id\:(?P.*)/i", $v,$c)){
- $music[$id]['song_id'].=trim($c['song_id'],"\"");
- }
- if(preg_match("/song_name\:(?P.*)/i",$v,$s)){
- $music[$id]['song_name'].=trim($s['song_name'],"\"");
- }
- if(preg_match("/album_name\:(?P.*)/i",$v,$n)){
- $music[$id]['album_name'].=trim($n['album_name'],"\"");
- }
- if(preg_match("/singer_name\:(?P.*)/i",$v,$name)){
- $music[$id]['singer_name'].=trim($name['singer_name'],"\"");
- }
- if(preg_match("/location\:(?P.*)/i",$v,$l)){
- $music[$id]['location'].=trim($l['location'],"\"");
- }
- }
- return $music;
- }
- public function getmusicurl(){
- $muiscurl = "";
- $result = $this->getmusic();
- foreach ($result as $id =>$v){
-
- $muiscurl.="歌曲{$id},歌曲名称:".iconv("gb2312","utf-8",$v['song_name']).",歌手:".iconv('gb2312','utf-8',$v['singer_name']).",专辑:".iconv('gb2312','utf-8',$v['album_name']).",歌曲地址:http://stream1{$v['location']}.qqmusic.qq.com/3{$v['song_id']}.mp3
"; - }
- return $muiscurl;
- }
- }
- $music = new music("新年快乐");
- $data = $music->getmusic();
- //var_dump($data);
- //echo "http://stream1{$data[1]['localtion']}.qqmusic.qq.com/3{$data[1]['song_id']}.mp3";
- echo $music->getmusicurl();
- //演示地址:http://www.ip62.com/qqmusic/
- ?>
|