<?php
function file_data($url) {
        if (function_exists('file_get_contents')) {
                $str = file_get_contents($url);
                return $str;
        }
}
function curl_xml($str, $item) {
        if ($str) {
                /*
                 * 如果你不是用sinaapp空间,强烈建议使用以下代码
                $obj = new DOMDocument();
                $obj->loadXML($str);
                $names = $obj->getElementsByTagName("$item");
                if ($names) {
                        $tt = $names->item(0);
                        $src = $tt->firstChild->nodeValue;
                        return $src;
                }
                */
                preg_match_all('|"><!\[CDATA\[([^>]+)\]\]>|',$str,$ar);
                return $ar[1][0];
                //自动取得资源最高清地址
        }
}
$fname='http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];
if (isset ($_GET['m'])) {
        if (strlen($_GET['m'])<10) {
                $url = 'http://pgmsvr.tv189.cn/program/getVideoPlayInfo?pid=' . $_GET['m'] . '&indexid=1&nocache=' . rand(1111, 9999);
                $str = file_data($url);
                $flv = curl_xml($str, 'url');
                header("location:$flv");
        } else {
                $url=urldecode($_GET['m']);
                $str = file_data($url);
                $flv= curl_xml($str, 'url');
                header("location:$flv");
        }
}
elseif (isset ($_GET['tv'])) {
        $tvurl = 'http://tv.tv189.com/v/' . $_GET['tv'] . '.htm';
        $tvstr = file_data($tvurl);
        preg_match("|title = '([^']+)'|",$tvstr,$tvname);
        preg_match("|totalvideo = '([0-9]+)'|", $tvstr, $total);
        $num = $total[1] + 0;
        $xml="<list>\n";
        for ($i = 1; $i < $num; $i++) {
        $tvid ='http://pgmsvr.tv189.cn/program/getVideoPlayInfo?pid=' . $_GET['tv'] . '&indexid='.$i.'&nocache=' . rand(1111, 9999);
        $tvid=urlencode($tvid);
        $xml.='<m type="2"  src="'.$fname.'?m='.$tvid.'" label="'.$tvname[1].'-'.$i.'" />'."\n";
        }
        $xml.="</list>\n";
        echo $xml;
}else{
        echo "天翼新版网站代理程序<br><br>电视剧演示：http://tv.tv189.com/v/<font color=red>203986</font>.htm ,<br>则代理程序写 $fname?tv=<font color=red>203986</font><br><br>电影演示：http://movie.tv189.com/v/<font color=red>213857</font>.htm<br>则代理程序写$fname?m=<font color=red>213857</font>即可";
}
?>