$music_valid = preg_match('/^(http|https|ftp):\\/\\/{1}([\\S]+)$/is', $music_input); $music_type_valid = true; $music_url = $music_input; break; default: $music_valid = false; break; } if ($music_valid && $music_type_valid) { if (null !== $music_name) { $music_name = htmlspecialchars($music_name, ENT_QUOTES, 'UTF-8'); $music_response = maicong_get_song_by_name($music_name, $music_type); } if (null !== $music_id) { $music_id = htmlspecialchars($music_id, ENT_QUOTES, 'UTF-8'); $music_response = maicong_get_song_by_id($music_id, $music_type); } if (null !== $music_url) { $music_response = maicong_get_song_by_url($music_url); } if (!empty($music_response)) { $reinfo = array('status' => '200', 'msg' => '', 'data' => $music_response); } else { $reinfo = array('status' => '0', 'msg' => 'ㄟ( ▔, ▔ )ㄏ,没有找到相关信息'); } } else { $reinfo = array('status' => '0', 'msg' => '(・-・*),请检查您的输入是否正确'); } header('Content-type:text/json'); echo json_encode($reinfo); exit;
function maicong_get_song_by_url($url) { preg_match('/http(s)?:\\/\\/music\\.163\\.com\\/(#|m)\\/song(\\?id=|\\/)(\\d+)/i', $url, $match_163); preg_match('/http(s)?:\\/\\/(www|m)\\.1ting\\.com\\/(player\\/b6\\/player_|#\\/song\\/)(\\d+)(\\.html|)/i', $url, $match_1ting); preg_match('/http(s)?:\\/\\/music\\.baidu\\.com\\/song\\/(\\d+)/i', $url, $match_baidu); preg_match('/http(s)?:\\/\\/m\\.kugou\\.com\\/play\\/info\\/([a-z0-9]+)/i', $url, $match_kugou); preg_match('/http(s)?:\\/\\/www\\.kuwo\\.cn\\/(yinyue|my)\\/(\\d+)/i', $url, $match_kuwo); preg_match('/http(s)?:\\/\\/(y\\.qq\\.com\\/#type=song&mid=|data\\.music\\.qq\\.com\\/playsong\\.html\\?songmid=)([a-zA-Z0-9]+)/i', $url, $match_qq); preg_match('/http(s)?:\\/\\/(www|m)\\.xiami\\.com\\/song\\/(\\d+)/i', $url, $match_xiami); preg_match('/http(s)?:\\/\\/5sing\\.kugou\\.com\\/(m\\/detail\\/|)(\\w+)(-|\\/)(\\d+)(-1|)\\.html/i', $url, $match_5sing); preg_match('/http(s)?:\\/\\/m\\.ttpod\\.com\\/#a=gqxq&from=ss&neid=(\\d+)/i', $url, $match_ttpod); preg_match('/http(s)?:\\/\\/music\\.migu\\.cn\\/#\\/song\\/(\\d+)/i', $url, $match_migu); preg_match('/http(s)?:\\/\\/soundcloud\\.com\\/[\\w\\-]+\\/[\\w\\-]+/i', $url, $match_soundcloud); if (!empty($match_163)) { $songid = $match_163[4]; $songtype = '163'; } elseif (!empty($match_1ting)) { $songid = $match_1ting[4]; $songtype = '1ting'; } elseif (!empty($match_baidu)) { $songid = $match_baidu[2]; $songtype = 'baidu'; } elseif (!empty($match_kugou)) { $songid = $match_kugou[2]; $songtype = 'kugou'; } elseif (!empty($match_kuwo)) { $songid = $match_kuwo[3]; $songtype = 'kuwo'; } elseif (!empty($match_qq)) { $songid = $match_qq[3]; $songtype = 'qq'; } elseif (!empty($match_xiami)) { $songid = $match_xiami[3]; $songtype = 'xiami'; } elseif (!empty($match_5sing)) { $songid = $match_5sing[3] . '/' . $match_5sing[5]; $songtype = '5sing'; } elseif (!empty($match_ttpod)) { $songid = $match_ttpod[2]; $songtype = 'ttpod'; } elseif (!empty($match_migu)) { $songid = $match_migu[2]; $songtype = 'migu'; } elseif (!empty($match_soundcloud)) { $match_resolve = array('method' => 'GET', 'url' => 'http://api.soundcloud.com/resolve.json', 'referer' => 'https://soundcloud.com/', 'proxy' => false, 'body' => array('url' => $match_soundcloud[0], 'client_id' => MC_SC_CLIENT_ID)); $match_request = maicong_curl($match_resolve); preg_match('/tracks\\/(\\d+)\\.json/i', $match_request, $match_location); if (!empty($match_location)) { $songid = $match_location[1]; $songtype = 'soundcloud'; } } else { return; } return maicong_get_song_by_id($songid, $songtype); }