Sohu.class.php
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class Util_Video_Api_Sohu extends Util_Video_Api
{
private $htmlurl = 'http://tv.sohu.com/{num}.shtml';
private $jsonurl = 'http://hot.vrs.sohu.com/vrs_flash.action?vid={id}';
private $mytvjsonurl = 'http://my.tv.sohu.com/videinfo.jhtml?m=viewtv&vid={id}';
private $swfurl = 'http://share.vrs.sohu.com/{picid}/v.swf';
public function getData($url)
{
$id = $this->getid($url);
if($id['mytv'])
{
$infourl = str_ireplace("{id}", $id['id'], $this->mytvjsonurl);
}
else
{
$infourl = str_ireplace("{id}", $id['id'], $this->jsonurl);
}
$infodat = Util_Video_ApiConnect::get($infourl);
$infodat = json_decode($infodat);
$dataobj = new Util_Video_Data($this->id);
/*$keyurl = 'http://'.$infodat->allot.'?prot='.$infodat->prot.'&file=';
$keyurl = str_replace('http://data.vod.itc.cn', $keyurl,$infodat->data->clipsURL[0]);
$keyurl .='&new='.(string)$infodat->data->su[0].'&t='.(1/rand(1,100000));
$keydat = VideoApiConnect::get($keyurl);*/
//$keydat = explode('|',$keydat);
//$swfurl = $keydat[0].substr((string)$infodat->data->su[0],1).'?key='.$keydat[count($keydat)-2];
//$dataobj->type = 'mp4';
if(!empty($infodat))
{
$dataobj->thumb = $infodat->data->coverImg;
$picID = explode('_', $dataobj->thumb);
if(empty($picID[2]))
{
$dataobj->swf = str_ireplace("{picid}", $id['id'], $this->swfurl);
}
else
{
$dataobj->swf = str_ireplace("{picid}", $picID[2], $this->swfurl);
}
$dataobj->thumb = $infodat->data->coverImg;
$dataobj->time = "";
$dataobj->source = 'sohu.com';
$dataobj->title = $infodat->data->tvName;
return $dataobj;
}
else
{
throw new Util_Video_ApiException('没有数据');
}
}
private function getid($url)
{
$url = $this->getUrl($url);
if(preg_match("/^http:\/\/my.tv.sohu.com/is", $url))
{
$id = substr(strrchr($url, '/'), 1);
$this->id = $id;
return array(
'mytv' => 1,
'id' => $id
);
}
$url = str_replace("http://tv.sohu.com/", '', $url);
$num = str_replace(strchr($url, '.'), '', $url);
$url = str_ireplace("{num}", $num, $this->htmlurl);
$htmldat = Util_Video_ApiConnect::get($url, array(
CURLOPT_ENCODING => "gzip"
));
if(preg_match_all("/var vid=\"(.*)\"/siU", $htmldat, $out, 2))
{
$id = $out[0][1];
}
$this->id = $id;
return array(
'mytv' => 0,
'id' => $id
);
}
}
?>