1
1
<?php
2
2
3
-
3
+
4
4
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 " ;
8
8
9
9
public static function parse ($ url ){
10
10
$ html = Base::_cget ($ url );
@@ -39,63 +39,61 @@ private static function randomFloat($min = 0, $max = 1) {
39
39
return $ min + mt_rand () / mt_getrandmax () * ($ max - $ min );
40
40
}
41
41
42
- private static function calmd ($ t ,$ fileId ){
42
+ private static function calmd ($ t ,$ fileId ){
43
43
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 );
47
47
}
48
48
49
49
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 ;
63
63
}
64
64
private static function getVRSXORCode ($ _arg1 , $ _arg2 ){
65
65
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 ));
74
74
}
75
75
76
76
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
+ }
86
86
/**
87
87
* [parseFlv2 解析网站flv格式的视频,第二种方法]
88
88
* @param [type] $tvid [description]
89
89
* @param [type] $vid [description]
90
90
* @return [type] [description]
91
91
*/
92
92
private static function parseFlv2 ($ tvid ,$ vid ){
93
-
94
93
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
-
98
94
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 );
99
97
100
98
$ video_datas = json_decode (Base::_cget ($ api_url ),true );
101
99
@@ -107,32 +105,32 @@ private static function parseFlv2($tvid,$vid){
107
105
108
106
109
107
$ time_datas = json_decode (Base::_cget ($ time_url ),true );
110
-
111
108
112
- $ server_time = $ time_datas ['t ' ];
109
+
110
+ $ server_time = $ time_datas ['t ' ];
113
111
114
112
115
- $ urls_data = $ data = array ();
113
+ $ urls_data = $ data = array ();
116
114
if (is_array ($ vs ) && count ($ vs )>0 ){
117
115
foreach ($ vs as $ val ){
118
116
//720p 和1080p 的视频地址暂时无法获得。
119
117
$ data ['seconds ' ] = $ val ['duration ' ];
120
118
foreach ($ val ['fs ' ] as $ v ){
121
119
122
120
$ this_link = $ v ['l ' ];
123
-
121
+
124
122
125
123
126
124
if ($ val ['bid ' ] == 4 || $ val ['bid ' ] == 5 || $ val ['bid ' ] == 10 ){
127
- $ this_link = static ::getVrsEncodeCode ($ this_link );
125
+ $ this_link = static ::getVrsEncodeCode ($ this_link );
128
126
}
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
+
131
133
132
- $ fileId = explode ('. ' ,$ sp [$ sp_length -1 ])[0 ];
133
- $ this_key = static ::calmd ($ server_time ,$ fileId );
134
-
135
-
136
134
137
135
138
136
$ this_link = $ this_link .'?ran= ' .self ::$ deadpara .'&qyid=08ca8cb480c0384cb5d3db068161f44f&qypid= ' .$ tvid .'_11&retry=1 ' ;
@@ -147,7 +145,7 @@ private static function parseFlv2($tvid,$vid){
147
145
if ($ val ['bid ' ] == 5 )$ urls_data ['FULL_HD ' ][] = $ final_url ;
148
146
if ($ val ['bid ' ] == 10 )$ urls_data ['FOUR_K ' ][] = $ final_url ;
149
147
}
150
-
148
+
151
149
}
152
150
153
151
if (!empty ($ urls_data ['fluent ' ])) $ data ['极速 ' ] = self ::getVideoUrl ($ urls_data ['fluent ' ]);
@@ -158,7 +156,7 @@ private static function parseFlv2($tvid,$vid){
158
156
if (!empty ($ urls_data ['FULL_HD ' ])) $ data ['1080P ' ] = self ::getVideoUrl ($ urls_data ['FULL_HD ' ]);
159
157
if (!empty ($ urls_data ['FOUR_K ' ])) $ data ['4K ' ] = self ::getVideoUrl ($ urls_data ['FOUR_K ' ]);
160
158
161
-
159
+
162
160
163
161
return $ data ;
164
162
}else {
@@ -174,10 +172,10 @@ private static function parseFlv2($tvid,$vid){
174
172
private static function getVideoUrl ($ url_data ){
175
173
176
174
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,重新返回真正的下载地址
179
177
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,客户端需要重新向自己的服务器加载
181
179
182
180
// {
183
181
// "t": "CT|ShangHai-101.81.48.14",
@@ -188,79 +186,79 @@ private static function getVideoUrl($url_data){
188
186
// "e": "0"
189
187
// }
190
188
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 ' ])){
197
194
198
- // // $urls[] = $data[$val]['results'];
199
- // // }
200
- // $urls[] = $val;
201
- // }
195
+ $ urls [] = $ data [$ val ]['results ' ];
196
+ }
197
+ // $urls[] = $val;
198
+ }
202
199
203
- // return $urls;
204
- return $ url_data ;
200
+ return $ urls ;
201
+ // return $url_data;
205
202
}
206
203
207
204
/**
208
205
* [rolling_curl curl并发]
209
206
* @param [type] $urls [urls数组]
210
207
* @return [type] [description]
211
208
*/
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