<?php
/*
sihu hd
http://hot.vrs.sohu.com/vrs_flash.action?vid=36858&ver=0&time=1266641760828
*/
class sohu
{
	var $curl = null;
	var $mid = 0;
	var $url = '';
	var $html = '';
	var $total = 0;
	var $specialid = 0;

	function sohu($url, $mid)
	{
		$this->curl = qbase::get_object('curl');
		$this->url = $url;
		$this->mid = $mid;
	}

	function get()
	{
		if(strpos($this->url, "/u/pw/") !== false){
			$temp = explode("/u/pw/", $this->url);
			$this->specialid = intval($temp[1]);
			return $this->get_player();
		}else if(strpos($this->url, "/u/vw/") !== false){
			$temp = explode("/u/vw/", $this->url);
			$pid = intval($temp[1]);
			return array(array($this->getName(), $pid));
		}else if(preg_match("/\/[0-9]{8}\/n[0-9]{1,9}\.shtml/", $this->url)){
			$html = $this->curl->load($this->url);
			$vid = intval($this->curl->cut($html, "var vid=\"", "\";"));
			$pid = intval($this->curl->cut($html, "var pid =\"", "\";"));
			$url = "http://hot.vrs.sohu.com/vrs_videolist.action?vid={$vid}&pid={$pid}";
			$html = explode("vrsvideolist =", $this->curl->load($url));
			$s = qbase::iconvs(trim($html[1]), 'utf-8', 'gbk');
			global $_SET;
			$temp = qbase::jsondecode($s);
			$data = array();
			if(!is_array($temp['videolist'])) return $data;
			foreach($temp['videolist'] as $val){
				$data[] = array(
					addslashes(qbase::iconvs($val['videoName'], $_SET['def_charset'], 'utf-8')), addslashes($val['videoId'])
				);
			}
			return $data;
		}
	}

	function getName(){
		$html = explode("-", $this->curl->cut($this->curl->load($this->url), "<title>", "</title>"));
		$name  = trim($html[1]);
		return addslashes($this->charsetLocal($name));
	}

	function get_player()
	{
		global $_SET;
		$s = qbase::get_object('curl')->load("http://v.blog.sohu.com/playlist.jhtml?id={$this->specialid}&m=get&outType=3");
		$temp = qbase::jsondecode($s);
		$data = array();
		if(!is_array($temp['data']['videos'])) return $data;
		foreach($temp['data']['videos'] as $val){
			$data[] = array(
				qbase::iconvs(addslashes($val['title']), $_SET['def_charset'], 'utf-8'), intval($val['id'])
			);
		}
		return $data;
	}

	function charsetLocal($s){
		global $_SET;
		return qbase::iconvs($s, $_SET['def_charset'], 'gbk');
	}
}
?>