QQ soso music search api demo address: http://www.ip62.com/qqmusic/ click mp3 address after the direct online playback
- 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, $ )){
- $ 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']). ", artist :". iconv ('gb2312', 'utf-8', $ v ['singer _ name']). ", album :". iconv ('gb2312', 'utf-8', $ v ['Album _ name']). ", song address: http: // stream1 {$ v ['location']} .qqmusic.qq.com/3366?v='song_id '{}}
";
- }
- Return $ muiscurl;
- }
- }
- $ Music = new music ("Happy new Year ");
- $ Data = $ music-> getmusic ();
- // Var_dump ($ data );
- // Echo "http: // stream1 {$ data [1] ['localtion ']} .qqmusic.qq.com/3366?data=1='song_id ";
- Echo $ music-> getmusicurl ();
- // Demo address: http://www.ip62.com/qqmusic/
- ?>
|