QQ Soso Music Search API Demo address: http://www.ip62.com/qqmusic/Click the direct online play after MP3 address
- 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. = "Song {$id}, Song name:". Iconv ("gb2312", "Utf-8", $v [' Song_name ']). ", Singer:". Iconv (' gb2312 ', ' utf-8 ', $v [' Singer_ Name ']). ", Album:". Iconv (' gb2312 ', ' utf-8 ', $v [' Album_name ']). ", Song address: http://stream1{$v [' Location ']}.QQMUSIC.QQ.COM/3 {$v [' song_id ']}.mp3
";
- }
- return $muiscurl;
- }
- }
- $music = new Music ("Happy New Year");
- $data = $music->getmusic ();
- Var_dump ($data);
- echo "http://stream1{$data [1][' localtion ']}.qqmusic.qq.com/3{$data [1][' song_id ']}.mp3 ';
- echo $music->getmusicurl ();
- Demo Address: http://www.ip62.com/qqmusic/
- ?>
Copy Code |