3
3
'''
4
4
# 作者: weimo
5
5
# 创建日期: 2020-01-04 19:14:43
6
- # 上次编辑时间: 2020-01-05 14:47:16
6
+ # 上次编辑时间 : 2020-01-11 17:42:30
7
7
# 一个人的命运啊,当然要靠自我奋斗,但是...
8
8
'''
9
9
import re
@@ -192,4 +192,64 @@ def get_vinfos_by_url(url):
192
192
else :
193
193
return get_vinfos (aid , locale = locale )
194
194
195
- #-------------------------------------------iqiyi--------------------------------------------
195
+ #-------------------------------------------iqiyi--------------------------------------------
196
+
197
+ #-------------------------------------------youku--------------------------------------------
198
+
199
+ def get_vinfos_by_url_youku (url , isall = False ):
200
+ vid_patterns = ["[\s\S]+?youku.com/video/id_(/+?)\.html" , "[\s\S]+?youku.com/v_show/id_(.+?)\.html" ]
201
+ video_id = matchit (vid_patterns , url )
202
+ show_id_patterns = ["[\s\S]+?youku.com/v_nextstage/id_(/+?)\.html" , "[\s\S]+?youku.com/show/id_z(.+?)\.html" , "[\s\S]+?youku.com/show_page/id_z(.+?)\.html" , "[\s\S]+?youku.com/alipay_video/id_(.+?)\.html" ]
203
+ show_id = matchit (show_id_patterns , url )
204
+ if video_id is None and show_id is None :
205
+ return None
206
+ if video_id :
207
+ return get_vinfos_by_video_id (video_id , isall = isall )
208
+ if show_id .__len__ () == 20 and show_id == show_id .lower ():
209
+ return get_vinfos_by_show_id (show_id )
210
+ else :
211
+ return get_vinfos_by_video_id (show_id , isall = isall )
212
+
213
+ def get_vinfos_by_video_id (video_id , isall = False ):
214
+ api_url = "https://openapi.youku.com/v2/videos/show.json?client_id=53e6cc67237fc59a&package=com.huawei.hwvplayer.youku&ext=show&video_id={}" .format (video_id )
215
+ try :
216
+ r = requests .get (api_url , headers = chrome , timeout = 5 ).content .decode ("utf-8" )
217
+ except Exception as e :
218
+ print ("get_vinfos_by_video_id error info -->" , e )
219
+ return None
220
+ data = json .loads (r )
221
+ if isall :
222
+ show_id = data ["show" ]["id" ]
223
+ return get_vinfos_by_show_id (show_id )
224
+ duration = 0
225
+ if data .get ("duration" ):
226
+ duration = int (float (data ["duration" ]))
227
+ if data .get ("title" ):
228
+ name = data ["title" ] + "_" + str (duration )
229
+ else :
230
+ name = "优酷未知" + "_" + str (duration )
231
+ vinfo = [name , duration , video_id ]
232
+ return [vinfo ]
233
+
234
+ def get_vinfos_by_show_id (show_id ):
235
+ api_url = "https://openapi.youku.com/v2/shows/videos.json?show_videotype=正片&count=100&client_id=53e6cc67237fc59a&page=1&show_id={}&package=com.huawei.hwvplayer.youku" .format (show_id )
236
+ try :
237
+ r = requests .get (api_url , headers = chrome , timeout = 5 ).content .decode ("utf-8" )
238
+ except Exception as e :
239
+ print ("get_vinfos_by_show_id error info -->" , e )
240
+ return None
241
+ data = json .loads (r )["videos" ]
242
+ if data .__len__ () == 0 :
243
+ return None
244
+ vinfos = []
245
+ for video in data :
246
+ duration = 0
247
+ if video .get ("duration" ):
248
+ duration = int (float (video ["duration" ]))
249
+ if video .get ("title" ):
250
+ name = video ["title" ] + "_" + str (duration )
251
+ else :
252
+ name = "优酷未知_{}" .format (video ["id" ]) + "_" + str (duration )
253
+ vinfos .append ([name , duration , video ["id" ]])
254
+ return vinfos
255
+ #-------------------------------------------youku--------------------------------------------
0 commit comments