<?php
/*
 * 请保留此信息
 * 颓废：http://tuifei.sinaapp.com/
 * 欢迎友情链接
 */
 $fname = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
 $xml = '';
 function num($num){
 	if($num<10){
 		$num=str_replace('0','',$num);
 	}
 	return $num;
 }
function file_data($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);
	$data = curl_exec($ch);
	curl_close($ch);
	//$data = iconv('UTF-8', 'GBK', $data);
	return $data;
}
function tv_vid($vid) {
$url = 'http://vv.video.qq.com/geturl?vid='.$vid;
$str = file_data($url);
preg_match('|<url>(.*)</url>|', $str, $flv);
header("location:$flv[1]");
}

function tv_id($id) {
	global $fname;
	$list='';
	$url='http://v.qq.com/cover/'.$id{0}.'/'.$id.'.html';
	$str = file_data($url);
	preg_match('|vid:"([^"]+)"|', $str, $flv);
	$ids=explode('|',$flv[1]);
	foreach($ids as$k=> $v){
		$d=$k+1;
		$list.='<m   src="'.$fname.'?vid='.$v.'" label="第'.$d.'集" />'."\n";
	}
	return $list;
}
function variety_id($id) {
	global $fname;
	$list = '';
	$str = file_data($id);
	preg_match('|type\/10_([0-9]+)\.html|',$id,$vid);
	preg_match_all('|" year="([^<]+)月<|', $str, $arr);
	foreach ($arr[1] as $v) {
		$z = explode('">', $v);
		$list .= '<m list_src="' . $fname . '?month=' . $vid[1] . '-' . $z[0] . '-' . $z[1] . '" label="' . $z[0] . '年' . $z[1] . '月" />' . "\n";
	}
	return $list;
}
function variety_month($id) {
	global $fname;
	$list='';
	$ids = explode('-', $id);
	$vs=num($ids[2]);
	$url = 'http://v.qq.com/json/column_history/' . $ids[0] . '/' . $ids[1] . '_'.$vs.'.json?_=2187381';
	$str = file_data($url);
	preg_match_all('|coverid":"([^"]+)","date|',$str,$ar1);
	preg_match_all('|sectitle":"([^"]+)","title|',$str,$ar2);
	$arr=array_combine($ar1[1],$ar2[1]);
	foreach($arr as $k=>$v){
		$list.='<m  list_src="'.$fname.'?tvid='.$k.'" label="'.$v.'" />'."\n";
	}
return $list;
}
function variety_list(){
		global $fname;
	$list='';
	$ar=array (
	'345' => '非诚勿扰',
	'320' => '舞林大会',
	'391' => '给力星期天',
	'344' => '我是大美人',
	'395' => '喜剧之王',
	'336' => '百科全说',
	'405' => '称心如意',
	'378' => '老公看你的',
	'379' => '欢喜冤家',
	'339' => '幸福晚点名',
	'402' => '职来职往',
	'477' => '非常了得',
	'326' => '综艺大哥大',
	'327' => '超级星光大道',
	'414' => '型男大主厨',
	'435' => '美食大三通',
	'465' => '达人来了',
	'475' => '我最时尚',
	'304' => '快乐大本营',
	'457' => '快乐女声',
	'308' => '天天向上',
	'311' => '鲁豫有约',
	'496' => '不见不散',
	'324' => '康熙来了',
	'337' => '我们约会吧',
	'373' => '非常静距离',
	'392' => '越策越开心',
	'405' => '称心如意',
	'388' => 'lady呱呱',
	'477' => '非常了得',
	'387' => '今夜有戏',
	'323' => '我爱记歌词',
	'338' => '我是大评委',
	'374' => '非同凡响',
	'433' => '中国梦想秀',
	'438' => '麦霸英雄汇',
	'466' => '天下达人秀',
	'351' => '幸福魔方',
	'375' => '中国达人秀',
	'346' => '壹周立波秀',
	'426' => '本山快乐营',
	'317' => 'QQ绿钻音乐会',
	'332' => '音乐现场',
	'380' => '我是冒险王',
	'417' => '幸福秀',
	'416' => '收藏秀',
	'418' => '巨星秀',
	'478' => '军情直播间',
	'413' => '王牌大贱谍',
	'322' => '挑战麦克风',
	'539' => '激情唱响',
	'412' => '国光帮帮忙',
	'533' => '少年进化论');
	foreach($ar as $k=>$v){
		$list.='<m list_src="'.$fname.'?id=http://v.qq.com/variety/type/10_'.$k.'.html" label="'.$v.'" />'."\n";
	}
	return $list;
}
$xml="<list>\n";
if(isset($_GET['id'])){
$xml.=variety_id($_GET['id']);
}elseif(isset($_GET['tvid'])){
$xml.=tv_id($_GET['tvid']);
}elseif(isset($_GET['vid'])){
tv_vid($_GET['vid']);
}elseif(isset($_GET['month'])){
$xml.=variety_month($_GET['month']);
}else{
$xml.=variety_list();
}
$xml.="</list>\n";
echo $xml;
?>
