Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Commit 7db0047

Browse files
committed
Merge pull request #8 from xyuanmu/master
Update iqiyi.class.php
2 parents 6cc112d + 2795a98 commit 7db0047

File tree

1 file changed

+123
-125
lines changed

1 file changed

+123
-125
lines changed

core/iqiyi.class.php

+123-125
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
3+
44
class Iqiyi {
5-
6-
static public $deadpara = 1000;
7-
static public $enc_key = "ts56gh";
5+
6+
static public $deadpara = 832;
7+
static public $enc_key = "a6f2a01ab9ad4510be0449fab528b82c";
88

99
public static function parse($url){
1010
$html = Base::_cget($url);
@@ -39,63 +39,61 @@ private static function randomFloat($min = 0, $max = 1) {
3939
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
4040
}
4141

42-
private static function calmd($t,$fileId){
42+
private static function calmd($t,$fileId){
4343

44-
$local3 = ")(*&^flash@#$%a";
45-
$local4 = floor(($t / (600)));
46-
return md5(($local4.$local3) . $fileId);
44+
$local3 = ")(*&^flash@#$%a";
45+
$local4 = floor(($t / (600)));
46+
return md5(($local4.$local3) . $fileId);
4747
}
4848

4949
private static function getVrsEncodeCode($_arg1){
50-
$_local6;
51-
$_local2 = "";
52-
$_local3 = explode("-",$_arg1);
53-
$_local4 = count($_local3);
54-
55-
$_local5 = ($_local4 - 1);
56-
57-
while ($_local5 >= 0) {
58-
$_local6 = static::getVRSXORCode(intval($_local3[(($_local4 - $_local5) - 1)], 16), $_local5);
59-
$_local2 = (static::fromCharCode($_local6).$_local2);
60-
$_local5--;
61-
};
62-
return $_local2;
50+
$_local6;
51+
$_local2 = "";
52+
$_local3 = explode("-",$_arg1);
53+
$_local4 = count($_local3);
54+
55+
$_local5 = ($_local4 - 1);
56+
57+
while ($_local5 >= 0) {
58+
$_local6 = static::getVRSXORCode(intval($_local3[(($_local4 - $_local5) - 1)], 16), $_local5);
59+
$_local2 = (static::fromCharCode($_local6).$_local2);
60+
$_local5--;
61+
};
62+
return $_local2;
6363
}
6464
private static function getVRSXORCode($_arg1, $_arg2){
6565

66-
$_local3 = ($_arg2 % 3);
67-
if ($_local3 == 1){
68-
return (($_arg1 ^ 121));
69-
};
70-
if ($_local3 == 2){
71-
return (($_arg1 ^ 72));
72-
};
73-
return (($_arg1 ^ 103));
66+
$_local3 = ($_arg2 % 3);
67+
if ($_local3 == 1){
68+
return (($_arg1 ^ 121));
69+
};
70+
if ($_local3 == 2){
71+
return (($_arg1 ^ 72));
72+
};
73+
return (($_arg1 ^ 103));
7474
}
7575

7676
private static function fromCharCode($codes){
77-
if (is_scalar($codes)) {
78-
$codes = func_get_args();
79-
}
80-
$str = '';
81-
foreach ($codes as $code) {
82-
$str .= chr($code);
83-
}
84-
return $str;
85-
}
77+
if (is_scalar($codes)) {
78+
$codes = func_get_args();
79+
}
80+
$str = '';
81+
foreach ($codes as $code) {
82+
$str .= chr($code);
83+
}
84+
return $str;
85+
}
8686
/**
8787
* [parseFlv2 解析网站flv格式的视频,第二种方法]
8888
* @param [type] $tvid [description]
8989
* @param [type] $vid [description]
9090
* @return [type] [description]
9191
*/
9292
private static function parseFlv2($tvid,$vid){
93-
9493

95-
$api_url = "http://cache.video.qiyi.com/vms?key=fvip&src=1702633101b340d8917a69cf8a4b8c7c";
96-
$api_url = $api_url."&tvId=".$tvid."&vid=".$vid."&vinfo=1&tm=".self::$deadpara."&enc=".static::calenc($tvid)."&qyid=08ca8cb480c0384cb5d3db068161f44f&&puid=&authKey=".static::calauthKey($tvid)."&tn=".static::randomFloat();
97-
9894

95+
$api_url = "http://cache.video.qiyi.com/vms?key=fvip&src=1702633101b340d8917a69cf8a4b8c7c";
96+
$api_url = $api_url."&tvId=".$tvid."&vid=".$vid."&vinfo=1&tm=".self::$deadpara."&enc=".static::calenc($tvid);
9997

10098
$video_datas = json_decode(Base::_cget($api_url),true);
10199

@@ -107,32 +105,32 @@ private static function parseFlv2($tvid,$vid){
107105

108106

109107
$time_datas = json_decode(Base::_cget($time_url),true);
110-
111108

112-
$server_time = $time_datas['t'];
109+
110+
$server_time = $time_datas['t'];
113111

114112

115-
$urls_data = $data = array();
113+
$urls_data = $data = array();
116114
if(is_array($vs) && count($vs)>0){
117115
foreach($vs as $val){
118116
//720p 和1080p 的视频地址暂时无法获得。
119117
$data['seconds'] = $val['duration'];
120118
foreach ($val['fs'] as $v){
121119

122120
$this_link = $v['l'];
123-
121+
124122

125123

126124
if($val['bid'] == 4 || $val['bid'] == 5 || $val['bid'] == 10){
127-
$this_link = static::getVrsEncodeCode($this_link);
125+
$this_link = static::getVrsEncodeCode($this_link);
128126
}
129-
$sp = explode('/',$this_link);
130-
$sp_length = count($sp);
127+
$sp = explode('/',$this_link);
128+
$sp_length = count($sp);
129+
130+
$fileId = explode('.',$sp[$sp_length-1])[0];
131+
$this_key = static::calmd($server_time,$fileId);
132+
131133

132-
$fileId = explode('.',$sp[$sp_length-1])[0];
133-
$this_key = static::calmd($server_time,$fileId);
134-
135-
136134

137135

138136
$this_link = $this_link.'?ran='.self::$deadpara.'&qyid=08ca8cb480c0384cb5d3db068161f44f&qypid='.$tvid.'_11&retry=1';
@@ -147,7 +145,7 @@ private static function parseFlv2($tvid,$vid){
147145
if($val['bid'] == 5)$urls_data['FULL_HD'][] = $final_url;
148146
if($val['bid'] == 10)$urls_data['FOUR_K'][] = $final_url;
149147
}
150-
148+
151149
}
152150

153151
if(!empty($urls_data['fluent'])) $data['极速'] = self::getVideoUrl($urls_data['fluent']);
@@ -158,7 +156,7 @@ private static function parseFlv2($tvid,$vid){
158156
if(!empty($urls_data['FULL_HD'])) $data['1080P'] = self::getVideoUrl($urls_data['FULL_HD']);
159157
if(!empty($urls_data['FOUR_K'])) $data['4K'] = self::getVideoUrl($urls_data['FOUR_K']);
160158

161-
159+
162160

163161
return $data;
164162
}else{
@@ -174,10 +172,10 @@ private static function parseFlv2($tvid,$vid){
174172
private static function getVideoUrl($url_data){
175173

176174

177-
//http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v
178-
//现在返回的是这个地址,客户端需要请求这个地址然后返回下面的数据,l是最终的下载地址,因为这个下载地址是有时间限制的,如果无法下载,请再次请求上面那个url,重新返回真正的下载地址
175+
// $url_data = http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v
176+
//客户端需要请求这个地址然后返回下面的数据,l是最终的下载地址,因为这个下载地址是有时间限制的,如果无法下载,请再次请求上面那个url,重新返回真正的下载地址
179177

180-
//http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v 这个地址也有时间限制,时间长了话,请求服务器会返回405,客户端需要重新向自己的服务器加载
178+
//视频地址:http://data.video.qiyi.com/4739e996fde3348eeef0da8684310ab4/videos/v0/20141221/38/e6/1974401616a8737fa3dd595db0eaefba.f4v 这个地址也有时间限制,时间长了话,请求服务器会返回405,客户端需要重新向自己的服务器加载
181179

182180
// {
183181
// "t": "CT|ShangHai-101.81.48.14",
@@ -188,79 +186,79 @@ private static function getVideoUrl($url_data){
188186
// "e": "0"
189187
// }
190188

191-
// $data = self::rolling_curl($url_data);
192-
// var_dump($data);
193-
// $urls = array();
194-
// foreach($url_data as $val){
195-
// //按顺序排列视频 url
196-
// // if(empty($data[$val]['error'])){
189+
$data = self::rolling_curl($url_data);
190+
$urls = array();
191+
foreach($url_data as $val){
192+
//按顺序排列视频 url
193+
if(empty($data[$val]['error'])){
197194

198-
// // $urls[] = $data[$val]['results'];
199-
// // }
200-
// $urls[] $val
201-
// }
195+
$urls[] = $data[$val]['results'];
196+
}
197+
// $urls[] = $val;
198+
}
202199

203-
// return $urls;
204-
return $url_data;
200+
return $urls;
201+
// return $url_data;
205202
}
206203

207204
/**
208205
* [rolling_curl curl并发]
209206
* @param [type] $urls [urls数组]
210207
* @return [type] [description]
211208
*/
212-
private static function rolling_curl($urls)
213-
{
214-
$queue = curl_multi_init();
215-
$map = array();
216-
foreach ($urls as $url) {
217-
$ch = curl_init();
218-
curl_setopt($ch, CURLOPT_URL, $url);
219-
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
220-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
221-
curl_setopt($ch, CURLOPT_HEADER, 0);
222-
curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
223-
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
224-
curl_multi_add_handle($queue, $ch);
225-
$map[(string)$ch] = $url;
226-
}
227-
$responses = array();
228-
do {
229-
while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
230-
if ($code != CURLM_OK) {
231-
break;
232-
}
233-
// a request was just completed -- find out which one
234-
while ($done = curl_multi_info_read($queue)) {
235-
// get the info and content returned on the request
236-
$info = curl_getinfo($done['handle']);
237-
$error = curl_error($done['handle']);
238-
$results = self::callback_match(curl_multi_getcontent($done['handle']));
239-
$responses[$map[(string)$done['handle']]] = compact('error','results');
240-
// remove the curl handle that just completed
241-
curl_multi_remove_handle($queue, $done['handle']);
242-
curl_close($done['handle']);
243-
}
244-
// Block for data in / output; error handling is done by curl_multi_exec
245-
if ($active > 0) {
246-
curl_multi_select($queue, 0.5);
247-
}
248-
} while ($active);
249-
curl_multi_close($queue);
250-
251-
return $responses;
252-
}
253-
254-
/**
255-
* [callback_match 回调获取视频的地址]
256-
* @param [type] $data [description]
257-
* @return [type] [description]
258-
*/
259-
private static function callback_match($data){
260-
// preg_match('#"l":"([^"]+)"#iU',$data,$matchs);
261-
// $url = str_replace('.mp4', '.f4v', $matchs[1]);
262-
263-
// return json_decode($data,true);
264-
return $data;
265-
}
266-
}
209+
private static function rolling_curl($urls)
210+
{
211+
$queue = curl_multi_init();
212+
$map = array();
213+
foreach ($urls as $url) {
214+
$ch = curl_init();
215+
curl_setopt($ch, CURLOPT_URL, $url);
216+
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
217+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
218+
curl_setopt($ch, CURLOPT_HEADER, 0);
219+
curl_setopt($ch, CURLOPT_USERAGENT, Base::USER_AGENT);
220+
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
221+
curl_multi_add_handle($queue, $ch);
222+
$map[(string)$ch] = $url;
223+
}
224+
$responses = array();
225+
do {
226+
while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM);
227+
if ($code != CURLM_OK) {
228+
break;
229+
}
230+
// a request was just completed -- find out which one
231+
while ($done = curl_multi_info_read($queue)) {
232+
// get the info and content returned on the request
233+
$info = curl_getinfo($done['handle']);
234+
$error = curl_error($done['handle']);
235+
$results = self::callback_match(curl_multi_getcontent($done['handle']));
236+
$responses[$map[(string)$done['handle']]] = compact('error','results');
237+
// remove the curl handle that just completed
238+
curl_multi_remove_handle($queue, $done['handle']);
239+
curl_close($done['handle']);
240+
}
241+
// Block for data in / output; error handling is done by curl_multi_exec
242+
if ($active > 0) {
243+
curl_multi_select($queue, 0.5);
244+
}
245+
} while ($active);
246+
curl_multi_close($queue);
247+
248+
return $responses;
249+
}
250+
251+
/**
252+
* [callback_match 回调获取视频的地址]
253+
* @param [type] $data [description]
254+
* @return [type] [description]
255+
*/
256+
private static function callback_match($data){
257+
258+
preg_match('#"l":"([^"]+)&src=(.*?)"#iU',$data,$matchs);
259+
$url = $matchs[1];
260+
261+
// return json_decode($data,true);
262+
return $url;
263+
}
264+
}

0 commit comments

Comments
 (0)