<?php
error_reporting(0);
$singerid=$_REQUEST['singerid'];
$mid=$_REQUEST['mid'];
if(!empty($singerid)){
header("Content-type: text/xml; charset=utf-8");
echo spage($singerid);
}elseif(!empty($mid)){
mtv_id($mid);
//header("location:$flv");
}

function curl($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);
	return $c;
}
function spage($singerid) {
$fname = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
	$singerurl = "http://www.yinyuetai.com/fanclub/mv/$singerid/toTop/";
	$str = curl($singerurl);
	if (preg_match('|<div class="page-nav">(.*)</div>|imsU', $str, $page)) {
		preg_match_all('|toTop\/([0-9]+)"|ims', $page[1], $num);
		$num = array_reverse($num[1]);
		for ($i = 1; $i <= $num[1]; $i++) {
			$singerurl = "http://www.yinyuetai.com/fanclub/mv/$singerid/toTop/$i";
			$str .= curl($singerurl);
		}
	} else {
		$str .= '';
	}
	preg_match_all('|<div class="thumb">\s+<a target="_blank" title="([^>]+)">|ims', $str, $mv);
	$list = "<list>\n";
	foreach ($mv[1] as $value) {
		$value = explode('" href="/video/', $value);
		$mtv_name=htmlspecialchars($value[0], ENT_QUOTES);
		//$mtv_src=mtv_id($value[1]);
		$list .= "<m type=\"2\" src=\"$fname?mid=$value[1]\" label=\"$mtv_name\" />\n";
	}
	$list.="</list>";
	return $list;
}

function mtv_id($id){
	$mtv_url = "http://www.yinyuetai.com/mvplayer/get-video-info?flex=true&videoId=$id";
        preg_match("|http(.*)\.flv|U", curl($mtv_url), $flv);
	if(!empty($flv[0])){
	header("location:$flv[0]");
       //return $flv[0];
        }else{
        	return ;
        }
}


?>