Api.class.php
2.52 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
89
<?php
abstract class Util_Video_Api
{
protected $id = '';
private static $adapterApi = array();
public static function loadData()
{
self::$adapterApi = array(
'163',
'56',
'ku6',
'6',
'boosj',
'xiyou',
'cnlive',
'cntv',
'ifeng',
'joy',
'kankanews',
'letv',
'm1905',
'pptv',
'rbc',
'sina',
'smgbb',
'sohu',
'tudou',
'uusee',
'v1',
'xunlei',
'yinyuetai',
'youku'
);
}
public function getUrl($url)
{
if(empty($url))
{
throw new Util_Video_ApiException('url不能为空');
}
else
{
return $url;
}
}
private static function regClass($name)
{
$class_prefix = 'Util_Video_Api_';
$class = $class_prefix . $name;
if((class_exists($class) && is_subclass_of($class, __CLASS__)))
{
return new $class();
}
else
{
throw new Util_Video_ApiException($class . '类不存在');
}
}
public static function isVideoUrl($url)
{
self::loadData();
$parseUrl = parse_url($url);
foreach(self::$adapterApi as $api)
{
if(preg_match("/" . $api . "/is", $parseUrl['host']))
{
return $api;
}
}
return '';
}
public static function autoGetData($url)
{
$api = self::isVideoUrl($url);
$videoapi = self::regClass($api);
$data = $videoapi->getData($url);
if(!empty($data))
{
$data->url = $url;
}
return $data;
return '';
}
abstract public function getData($url);
}
?>