forked from wukes/youtube-php-mirroring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.php
189 lines (162 loc) · 5.39 KB
/
video.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
$v=$_GET[v];
//判断设备
function fcurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function isMobile(){
$useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
function CheckSubstrs($substrs,$text){
foreach($substrs as $substr)
if(false!==strpos($text,$substr)){
return true;
}
return false;
}
$mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
CheckSubstrs($mobile_token_list,$useragent);
if ($found_mobile){
return true;
}else{
return false;
}
}
if (isMobile()){
//如果手机访问
header("Location: m_video.php?v=$v");
//确保重定向后,后续代码不会被执行
exit;
}
else{
}
//获取原始下载地址
require 'inc/parser.php';
$geturl= $ym.$parser.'/index.php?videoid='."$v";
$w=fcurl($geturl);
$cv=json_decode($w);
//print_r($cv);
//echo $cv[Download][1][url];
function object_array($array)
{
if(is_object($array))
{
$array = (array)$array;
}
if(is_array($array))
{
foreach($array as $key=>$value)
{
$array[$key] = object_array($value);
}
}
return $array;
}
$rr=object_array($cv);
$vname=$rr[title];//视频名称
$furl=$rr[Download][2][url];//flv视频地址
$murl=$rr[Download][1][url];//mp4视频地址
$pagetitle=$vname;
//加密传输视频
// Declare the class
class GoogleUrlApi {
// Constructor
function GoogleURLAPI($key,$apiURL = 'https://www.googleapis.com/urlshortener/v1/url') {
// Keep the API Url
$this->apiURL = $apiURL.'?key='.$key;
}
// Shorten a URL
function shorten($url) {
// Send information along
$response = $this->send($url);
// Return the result
return isset($response['id']) ? $response['id'] : false;
}
// Expand a URL
function expand($url) {
// Send information along
$response = $this->send($url,false);
// Return the result
return isset($response['longUrl']) ? $response['longUrl'] : false;
}
// Send information to Google
function send($url,$shorten = true) {
// Create cURL
$ch = curl_init();
// If we're shortening a URL...
if($shorten) {
curl_setopt($ch,CURLOPT_URL,$this->apiURL);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode(array("longUrl"=>$url)));
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type: application/json"));
}
else {
curl_setopt($ch,CURLOPT_URL,$this->apiURL.'&shortUrl='.$url);
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// Execute the post
$result = curl_exec($ch);
// Close the connection
curl_close($ch);
// Return the result
return json_decode($result,true);
}
}
require 'pheader.php';
// Create instance with key
$key = $gurl_api;
$googer = new GoogleURLAPI($key);
// Test: Shorten a URL
//加密后的视频流链接
$flvurl1 = $googer->shorten("$furl");//flv
$mp4url1 = $googer->shorten("$murl");//mp4
//获取视频列表
$flvurl= $ym.$ytproxy.'/browse.php?u='.$flvurl1;
$mp4url= $ym.$ytproxy.'/browse.php?u='.$mp4url1;
$vname1=$vname;
$vname1=substr($vname1, 0, 4);
$API_key=$youtube_api;
$jsonurl='https://www.googleapis.com/youtube/v3/search?key='.$API_key.'&part=snippet&q='.$vname1.'&maxResults=20&type=video';
//To try without API key: $video_list = json_decode(file_get_contents(''));
$video_list = json_decode(fcurl($jsonurl));
$video_list1=object_array($video_list);
?>
<script src="js/jquery.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div class="wrapper container">
<div class="pull-left" id="a1" style="width:850px">
<!--ckplayer配置开始-->
<script type="text/javascript" src="/ckplayer/ckplayer.js" charset="utf-8"></script>
<script type="text/javascript">
var flashvars={
f:'<?php echo $flvurl;?>',
c:0,
p:1
};
var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always',wmode:'transparent'};
var video=['<?php echo $mp4url;?>->video/mp4'];
CKobject.embed('/ckplayer/ckplayer.swf','a1','ckplayer_a1','100%','550px',false,flashvars,video,params);
</script>
<!--ckplayer配置结束-->
<h1><strong><?php echo $vname;?></strong></h1>
</div>
<div class="pull-right" style="width:270px">
<a href="#" class="list-group-item active">
相关视频
</a>
<?php
for($i=0;$i<=20;$i++){
echo'<a href="video.php?v='.$video_list1[items][$i][id][videoId] .'"target="_blank" class="list-group-item">'.$video_list1[items][$i][snippet][title].'</a>';
}
?>
</div>
</div>
<?php require 'footer.php';?>