<?php
$xml = "<list>\n";
function g_s($url) {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $referer = 'http://www.netitv.com/';
        $ch = curl_init();
        $timeout = 30;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $referer);
        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 dy_page($pid) {
        $ar = explode('|', $pid);
        $xml_url = 'http://www.netitv.com/' . $ar[0] . '/proXml/' . $ar[1] . '_1.xml';
        $xml_str = g_s($xml_url);
        preg_match_all('@<\!\[CDATA\[([^>]+)\]\]>@', $xml_str, $name);
        preg_match('|<playurls>(.*)<\/playurls>|is', $xml_str, $xar);
        preg_match_all('@<\!\[CDATA\[([^>]+)\]\]>@', $xar[1], $arr);
        $name = $name[1];
        $xstr = '';
        foreach ($arr[1] as $k => $v) {
                $z = $k +1;
                $xstr .= '<m type="2" src="' . $v . '" label="' . $name[1] . '-' . $z . '" />' . "\n";
        }
        return $xstr;
}
function my_page($playid) {
        $ar = explode('|', $playid);
        $xml_url = 'http://www.netitv.com/' . $ar[0] . '/proXml/' . $ar[1] . '_1.xml';
        $xml_str = g_s($xml_url);
        preg_match('|<playurls>(.*)<\/playurls>|is', $xml_str, $xar);
        preg_match('@<\!\[CDATA\[([^>]+)\]\]>@U', $xar[1], $arr);
        header("location:$arr[1]");
}

function move_list($u, $p,$type) {
        $str = '';
        $list = '';
        $fname = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];
        if ($type == '1') {
        $list_url = 'http://www.netitv.com/_CMS_TXT_/2010/11/24/1586_5_CMSSQL_' . $u . '.txt';
        $str = g_s($list_url);
        if ($p != '1') {
                for ($i = 2; $i <= $p; $i++) {
                        $list_url = 'http://www.netitv.com/_CMS_TXT_/2010/11/24/1586_5_CMSSQL_' . $u . '_' . $i . '.txt';
                        $str .= g_s($list_url);
                }
        }
        preg_match_all("|param1='([^>]+)\|/#|", $str, $ar);
        $ar = array_unique($ar[1]);
                foreach ($ar as $k => $v) {
                        $z = explode("' param='elivemovie://|Play|", $v);
                        $list .= '<m   label="' . $z[0] . '" list_src="' . $fname . '?pid=' . $z[1] . '" />' . "\n";
                }
                $list .= "\n";
                return $list;
        }
        elseif ($type == '2') {
        $list_url = 'http://www.netitv.com/_CMS_TXT_/2010/11/25/1588_5_CMSSQL_' . $u . '.txt';
        $str = g_s($list_url);
        if ($p != '1') {
                for ($i = 2; $i <= $p; $i++) {
                        $list_url = 'http://www.netitv.com/_CMS_TXT_/2010/11/25/1588_5_CMSSQL_' . $u . '_' . $i . '.txt';
                        $str .= g_s($list_url);
                }
        }
        preg_match_all("|param1='([^>]+)\|/#|", $str, $ar);
        $ar = array_unique($ar[1]);
                foreach ($ar as $k => $v) {
                        $z = explode("' param='elivemovie://|Play|", $v);
                        $list .= '<m  type="2" label="' . $z[0] . '" src="' . $fname . '?playid=' . $z[1] . '" />' . "\n";
                }
                return $list ;
        }
}
function film_list($m) {
        $ar1=array('16731','16732','16733','16734','16735','16736','16737','16738','20017','20401','20402','20403','20404');
        $ar2=array('4','2','8','8','14','5','1','2','4','1','3','2','3');
        $n=$m-1;
        return move_list($ar1[$n],$ar2[$n],'2');
}
function tv_list($tv) {
$ar1=array('16740','16741','16742','16743','16744','16745','16746','16747','16748','16749','20695');
$ar2=array('2','3','2','3','2','3','5','2','2','3','1');
        $n=$tv-1;
        return move_list($ar1[$n],$ar2[$n],'1');
}
function default_list() {
        $list = '';
        $fname = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];
        $tv = array ('偶像电视剧','言情电视剧','武侠电视剧','历史电视剧','警匪电视剧','军事电视剧','生活电视剧','喜剧电视剧','悬疑电视剧','怀旧电视剧','动漫电视剧');
        $film = array ('动作电影','冒险电影','爱情电影','喜剧电影','剧情电影','战争电影','科幻电影','恐怖电影','动漫电影','武侠电影','悬疑电影','犯罪电影','家庭电影');
        foreach ($tv as $key => $value) {
                $keys = $key +1;
                $list .= '<m list_src="' . $fname . '?tv=' . $keys . '" label="' . $value . '" />' . "\n";
        }
        foreach ($film as $k => $v) {
                $ks = $k +1;
                $list .= '<m list_src="' . $fname . '?m=' . $ks . '" label="' . $v . '" />' . "\n";
        }
        return $list;
}
if (isset ($_GET['pid'])) {
        $xml .= dy_page($_GET['pid']);
}
elseif (isset ($_GET['playid'])) {
         my_page($_GET['playid']);
}
elseif (isset ($_GET['m'])) {
        $xml .= film_list($_GET['m']);
}
elseif (isset ($_GET['tv'])) {
        $xml .= tv_list($_GET['tv']);
} else {
        $xml .= default_list();
}
$xml .= "</list>";
echo $xml;
?>