<?php
function g_s($url) {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $ch = curl_init();
        $timeout = 30;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
        @ $c = curl_exec($ch);
        curl_close($ch);
        $c = mb_convert_encoding($c, 'GBK', 'UTF-8');
        return $c;
}
$xml = '<?xml version="1.0" encoding="GBK" ?>';
$xml .= "\n";
$xml .= '<list>';
$xml .= "\n";
$filename = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];
if (isset ($_GET['sid'])) {
        $singer_str='';
        for($i=1;$i<=3;$i++){
        $singer_url = 'http://sns.video.qq.com/tvideo/fcgi-bin/GetSingerMV?otype=json&sort=3&id=' . $_GET['sid'] . '&dis=0&page='.$i.'&callback=jsonp2182423&_=2182423';        
        $singer_str .= g_s($singer_url);}
        preg_match_all('|"title":"([^"]*)"|', $singer_str, $ar1);
        preg_match_all('|"vid":"([0-9a-zA-Z_]+)"|', $singer_str, $ar2);
        $ar = array_combine($ar2[1], $ar1[1]);
        foreach ($ar as $k => $v) {
                $xml .= '<m src="' . $filename . '?vid=' . $k . '" label="' . $v . '" />';
                $xml .= "\n";
        }
}elseif (isset($_GET['vid'])) {
        $g = 'http://vv.video.qq.com/geturl?vid='.$_GET['vid'];
        $h = g_s($g);
        preg_match('|<url>(.*)</url>|', $h, $j);
        $j=$j[1];
        header("location:$j");
}else{
        $surl = 'http://v.qq.com/music/singer/index.html';
        $str = g_s($surl);
        preg_match_all('|singer_0_0_0_0.html\?sort=2&id=([0-9]+)&dis=0&page=1|', $str, $ar1);
        preg_match_all('|&dis=0&page=1">(.*)</a></li>|', $str, $ar2);
        $ar = array_combine($ar1[1], $ar2[1]);
        foreach ($ar as $k => $v) {
                $th=array('<','>','&');
                $v=str_replace($th,'',$v);
                $xml .= '<m list_src="' . $filename . '?sid=' . $k . '" label="' . $v . '" />';
                $xml .= "\n";
        }
}
$xml .= '</list>';
echo $xml;
?>