<?php
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);
        @ $c = curl_exec($ch);
        curl_close($ch);
        return $c;
}
function get_u($u) {
        global $fname;
        $t = explode('-', $u);
        $list = '';
        for ($i = 1; $i <= $t[1]; $i++) {
                $q = 'http://so.tv.sohu.com/list_p11_p2_' . $t[0] . '_p3_p4-1_p5_p6_p70_p82_p9-1_p10' . $i . '_p11.html';
                $list .= '<m label="第' . $i . '页" list_src="' . $fname . '?n=' . $q . '" />' . "\n";
        }
        return $list;
}
function get_n($n) {
        global $fname;
        $str = file_data($n);
        preg_match_all('|<h4><a href="([^<]+)</a></h4>|', $str, $a1);
        //return $a1[1];
        $list = '';
        foreach ($a1[1] as $k => $v) {
                $a2 = explode('" target="_blank">', $v);
                $list .= '<m label="' . $a2[1] . '" list_src="' . $fname . '?id=' . $a2[0] . '" />' . "\n";
        }
        return $list;
}
function get_id($id) {
        $str = file_get_contents($id);
        if (preg_match('|var vid="([0-9]+)|', $str, $as)) {
                $im = $as[1];
        }
        elseif (preg_match('|<div class=area id=picFocus><a \n\nhref="([^"]+)"|ims', $str, $as)) {
                $str1 = file_data($as[1]);
                preg_match('|var vid="([0-9]+)|', $str1, $as);
                $im = $as[1];
        }
        $url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid=' . $im;
        $fp = file_data($url);
        preg_match_all('|http://data.vod.itc.cn([^"]+)"|', $fp, $ar1);
        preg_match('|tvName":"([^"]+)","|', $fp, $name);
        preg_match('|"su":\["(.*)"\],"|', $fp, $ar2);
        $ar1 = $ar1[1];
        $ar2 = $ar2[1];
        $ar2 = explode('","', $ar2);
        @ $ar = array_combine($ar1, $ar2);
        $list = '';
        foreach ($ar as $k => $v) {
                $u = 'http://220.181.61.229/?prot=2&file=' . $k . '&new=' . $v;
                $m = file_data($u);
                $s = explode('|', $m);
                @ $flv = $s[0] . $v . '?key=' . $s[3];
                $list .= '<m type="2" src="' . $flv . '" label="' . $name[1] . '." />';
                $list .= "\n";
        }
        return $list;
}
function default_list() {
        global $fname;
        $lb = array (
                '爱情' => 'u7231_u60c5_u7247-21',
                '动作' => 'u52a8_u4f5c_u7247-19',
                '喜剧' => 'u559c_u5267_u7247-14',
                '科幻' => 'u79d1_u5e7b_u7247-2',
                '战争' => 'u6218_u4e89_u7247-3',
                '恐怖' => 'u6050_u6016_u7247-6',
                '风月' => 'u98ce_u6708_u7247-3',
                '剧情' => 'u5267_u60c5_u7247-47',
                '音乐' => 'u97f3_u4e50_u7247-1',
                '动画' => 'u52a8_u753b_u7247-1',
                '纪录' => 'u7eaa_u5f55_u7247-1'
        );
        $list = '';
        foreach ($lb as $k => $v) {
                $list .= '<m label="' . $k . '" list_src="' . $fname . '?u=' . $v . '" />' . "\n";
        }
        return $list;
}
$fname = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["SCRIPT_NAME"];
$xml = "<?xml version=\"1.0\" encoding=\"GBK\" ?>\n<list>\n";
if (isset ($_GET['u'])) {
        $xml .= get_u($_GET['u']);
}
elseif (isset ($_GET['n'])) {
        $xml .= get_n($_GET['n']);
}
elseif (isset ($_GET['id'])) {
        $xml .= get_id($_GET['id']);
} else {
        $xml .= default_list();
}
$xml .= "</list>\n";
echo $xml;
?>