cntv.class.php
1.59 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
<?php
class Util_Video_Api_Cntv extends Util_Video_Api
{
private $jsonurl = 'http://vdd.player.cntv.cn/index.php?pid={pid}';
/**
* @param unknown_type $url
*/
public function getData($url)
{
$id = $this->getid($url);
$infourl = str_ireplace("{pid}", $id, $this->jsonurl);
$infodat = Util_Video_ApiConnect::get($infourl);
$infodat = json_decode($infodat);
if($infodat == null)
{
throw new Util_Video_ApiException('数据解析失败');
}
$dataobj = new Util_Video_Data($this->id);
if(is_object($infodat->video->chapters[0]))
{
$dataobj->swf = $infodat->video->chapters[0]->url;
$dataobj->thumb = $infodat->video->chapters[0]->image;
}
else
{
$dataobj->swf = str_ireplace("mp4:", 'http://', $infodat->video->streams[0]->streamName);
}
$dataobj->time = "";
$dataobj->source = '来自于cntv.cn';
$dataobj->title = $infodat->title;
return $dataobj;
}
private function getid($url)
{
$url = $this->getUrl($url);
if(preg_match("/^http:\/\/(.*).cntv.cn/is", $url))
{
$htmldat = Util_Video_ApiConnect::get($url);
if(preg_match_all("/<!--repaste.video.code.begin-->(.*)<!--repaste.video.code.end-->/siU", $htmldat, $out, 2))
{
$pid = $out[0][1];
}
}
if(empty($pid))
{
throw new VideoApiException('没有数据');
}
$this->id = $pid;
return $pid;
}
}
?>