<?php
class qiyi
{
	private $curl = null;
	private $mid = 0;
	private $url = '';
	private $html = '';
	private $total = 0;
	private $specialid = 0;

	function qiyi($url, $mid)
	{
		$this->curl = qbase::get_object('curl');
		$this->url = $url;
		$this->mid = $mid;
	}
	//qbase::load($url, 0, '', '', false, '', 90);
	function get(){
		$data = array();
		if(preg_match("/\/[0-9]{8}\/n([0-9]{1,10})\.html/", $this->url, $match)){
			//单个媒体页面
			$html = $this->curl->cut(qbase::load($this->url), "var info", "</script>");
			$pid = intval($this->curl->cut($html, "pid : \"", "\","));
			$ptype = intval($this->curl->cut($html, "ptype : \"", "\","));
			$videoId = intval($this->curl->cut($html, "videoId : \"", "\","));
			$name = $this->charsetLocal(trim($this->curl->cut($html, "videoName : \"", "\",")));
			$data[] = array($name, "{$pid}-{$ptype}-{$videoId}");
		}else if(preg_match("/\/[a-z]{5,10}\/[a-z0-9]{1,64}\.html/", $this->url, $match)){
			//可能是剧集
			$html = $this->curl->cut(qbase::load($this->url), "var info", "</script>");
			$pid = intval($this->curl->cut($html, "pid : \"", "\","));
			$ptype = intval($this->curl->cut($html, "ptype : \"", "\","));
			$albumId = intval($this->curl->cut($html, "albumId\":", ",\""));
			if(!$albumId){
				$albumId = intval($this->curl->cut($html, "info.albumId='", "';"));
			}
			$url = "http://cache.video.qiyi.com/l/{$pid}/{$ptype}/{$albumId}";
			$html = $this->curl->cut(qbase::load($url), "frameElement.callback(", ");</script>");
			$html = $this->charsetLocal($html);
			preg_match_all("/\"videoId\":([0-9]{1,9}),\"videoOrder\":\"([0-9]{1,9})\",\"videoName\":\"(.*?)\",\"play/", $html, $temp);
			foreach($temp[3] as $key=>$val){
				$data[] = array(
					$val, "{$pid}-{$ptype}-{$temp[1][$key]}"
				);
			}
		}
		return $data;
	}

	function charsetLocal($s){
		global $_SET;
		return qbase::iconvs($s, $_SET['def_charset'], 'utf-8');
	}

	function linkToUrl($code){
		return $code;
	}
}
?>