Youku.class.php
4.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
class Util_Video_Api_Youku extends Util_Video_Api
{
private $jsonurl = "http://v.youku.com/player/getPlayList/VideoIDS/{id}/timezone/+08/version/5/source/out?password=&ran={rand}&n=";
private $htmlurl = "http://v.youku.com/v_show/{id}.html";
private $review = "http://v.youku.com/v_vpcommentContent/id_{id}_time_{time}_page_{page}.html?__rt=1&__ro=videobodycommentlist";
//优酷网
const YOUKU_VIDEO_PID = 'XMjA5Ng=='; // 优酷视频PID
private static $youku_video_api = 'http://api.youku.com/api_ptvideoinfo?pid=%s&id=%s'; // 优酷视频接口
public function getData($url)
{
if(empty($url))
{
throw new Util_Video_ApiException("没有数据");
}
$api_url = sprintf ( self::$youku_video_api, self::YOUKU_VIDEO_PID, $url );
$result = Util_Video_ApiConnect::get($api_url);
$data = new Util_Video_Data($this->id);
if ($result)
{
$vinfo = ( array ) simplexml_load_string ( $result, 'SimpleXMLElement', LIBXML_NOCDATA );
$vinfo = ( array ) $vinfo ['item'];
if (isset($vinfo['code']) && $vinfo ['code'] == 2)
{
throw new Util_Video_ApiException("已删除");
}
if(isset($vinfo ['title']) && isset($vinfo ['shareswf']))
{
$data->swf = $vinfo ['shareswf'];
$data->title = htmlspecialchars ( $vinfo ['title'] );
$data->thumb = $vinfo ['imagelink'];
}
else
{
return $this->getViolentData($url);
}
}
else
{
return $this->getViolentData($url);
}
if(empty($data))
{
throw new Util_Video_ApiException("没有数据");
}
return $data;
}
/**
* 暴力破解
*/
private function getViolentData($url)
{
$jsonurl = str_ireplace("{rand}", rand(100, 999), $this->jsonurl);
$idandswf = $this->getid($url);
$jsonurl = str_ireplace("{id}", $this->id, $jsonurl);
$dat = Util_Video_ApiConnect::get($jsonurl);
$jsonobj = json_decode($dat);
if(empty($jsonobj))
{
throw new Util_Video_ApiException("没有数据");
}
$dataobj = new Util_Video_Data($this->id);
$dataobj->swf = $idandswf['swf'];
$dataobj->thumb = $jsonobj->data[0]->logo;
$dataobj->time = $jsonobj->data[0]->seconds;
$dataobj->title = $jsonobj->data[0]->title;
$dataobj->source = '来自于youku.com';
return $dataobj;
}
private function getid($url)
{
$url = $this->getUrl($url);
if(!preg_match("/^http:\/\/.*/i", $url))
{
$url = str_ireplace("{id}", $url, $htmlurl);
}
$content = Util_Video_ApiConnect::get($url);
if(preg_match_all("/<embed\s*src=\"(.*)\"/siU", $content, $flashurl, 2))
{
$swf = $flashurl[0][1];
$urlid = preg_replace("/\/.*$/si", "", preg_replace("/^.*sid\//si", "", $swf));
}
else
{
throw new Util_Video_ApiException('数据解析失败');
}
$this->id = $urlid;
return array(
"swf" => $swf,
"id" => $urlid
);
}
public function getreview($url = null)
{
$this->getid($url);
$review = str_ireplace("{time}", time(), $this->review);
$review = str_ireplace("{id}", $this->id, $review);
$reviewpage = str_ireplace("{page}", 1, $review);
$reviewpage = Util_Video_ApiConnect::get($reviewpage);
$page = array();
if(preg_match_all("/class=\"\s*pages\s*\"\s*>(.*)<\s*\/\s*ul\s*>/siU", $reviewpage, $out, 2))
{
if(preg_match_all("/<\s*li.*>(.*)<\s*\/li\s*>/siU", $out[0][1], $out1, 2))
{
foreach($out1 as $v)
{
$page[] = strip_tags($v[1]);
}
$reviewarr = array(
$reviewpage
);
array_shift($page);
if(is_array($page))
{
foreach($page as $v)
{
$url = str_ireplace("{page}", $v, $review);
$reviewarr[] = Util_Video_ApiConnect::get($url);
}
}
}
}
return array();
}
}
?>