V1.class.php
2.26 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
<?php
class Util_Video_Api_V1 extends Util_Video_Api
{
private $tvxmlurl = 'http://www.v1.cn/gqxml/{id}.xml';
private $xmlurl = 'http://www.v1.cn/xml/video/{id}.xml';
/**
* @param unknown_type $url
*/
public function getData($url)
{
$id = $this->getid($url);
if(preg_match('/^http:\/\/tv.v1.cn/is', $url))
{
$id = str_replace(',', '/', $id);
$infourl = str_ireplace('{id}', $id, $this->tvxmlurl);
}
else
{
$infourl = str_ireplace('{id}', $id, $this->xmlurl);
}
$this->id = $id;
$infodat = Util_Video_ApiConnect::get($infourl);
if(!function_exists("simplexml_load_file"))
{
throw new Util_Video_ApiException('simplexml_load_file 不存在');
}
$infodat = str_replace("<![CDATA[", '', $infodat);
$infodat = str_replace("]]>", '', $infodat);
$infodat = @simplexml_load_string($infodat);
if($infodat == null)
{
throw new Util_Video_ApiException('数据解析失败');
}
$dataobj = new Util_Video_Data($this->id);
if(is_object($infodat->items->item))
{
$dataobj->swf = (string) $infodat->items->item->flv;
$dataobj->thumb = (string) $infodat->items->item->image;
$dataobj->time = (string) $infodat->items->item->publishdate;
$dataobj->title = (string) $infodat->items->item->title;
}
else
{
$dataobj->swf = (string) $infodat->videoInfo->url;
$dataobj->thumb = (string) $infodat->videoInfo->image;
$dataobj->time = "";
$dataobj->title = (string) $infodat->videoInfo->title;
}
$dataobj->source = '来自于v1.cn';
return $dataobj;
}
private function getid($url)
{
$url = $this->getUrl($url);
if(preg_match("@^http:\/\/.*.v1.cn@is", $url))
{
$htmldat = Util_Video_ApiConnect::get($url);
if(preg_match_all('/{id:\"(.*)\"}/isU', $htmldat, $out, 2))
{
$id = $out[0][1];
}
return $id;
}
else
{
throw new VideoApiException('url地址不正确');
}
}
}
?>