<?
@$vid=$_REQUEST[vid];
if(!empty($vid))
makelist(lid($vid));
else
makelist(lists());
function curl($preg, $url,$rd) {
	$str= file_get_contents($url);
	if($rd=='1')
	preg_match_all($preg,$str, $arr);
	else
	preg_match($preg,$str, $arr);
	return $arr[1];
}
function makelist($list) {
header("Content-type: text/xml; charset=utf-8");
echo  "<list>\n$list</list>";
}
function lists() {
	$list = '';
	$fname='http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
	$url = 'http://so.v.163.com/stree/0085.xml';
	$str = curl('|<section id="([^<]+)"\/>|imsU', $url,'1');
	foreach ($str as $value) {
		$value = explode('" title="', $value);
		$name = htmlspecialchars(urldecode($value[1]));
		$name=str_replace('＞','',$name);
		$list .= "<m list_src=\"$fname?vid=$value[0]\" label=\"$name\" />\n";
	}
	return $list;

}
function lid($id) {
	$list='';
	$url = "http://so.v.163.com/flashinfo/vinfo/$id.xml";
	$vids= curl('|<vid>([^<]+)</vid>|ims',$url,'1');
	$titles= curl('|<!\[CDATA\[([^>]+)\]\]>|ims',$url,'1');
	$name=array_combine($vids,$titles);
	foreach($name as $vid=>$title){
		$v7=$vid{7};
		$v8=$vid{8};
		$title = htmlspecialchars($title);
		$v_url="http://live.ws.126.net/video/$v7/$v8/0085_$vid.xml";
		$v_src=curl('|<flv>([^<]+)<\/flv>|',$v_url,'0');
		$list.="<m src=\"$v_src?start={start_bytes}\" stream=\"true\" label=\"$title\" />\n";
	}
	return iconv('gbk','utf-8',$list);
}

?>
