From 8bc81d9a70448e5078af86e07c35b12f3f8b1b6a Mon Sep 17 00:00:00 2001 From: Zhang Ning Date: Wed, 29 Jun 2016 20:18:18 +0800 Subject: [PATCH] iqiyi: support more stream quality algorism form @ERioK thank you @ERioK Signed-off-by: Zhang Ning --- src/you_get/extractors/iqiyi.py | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/you_get/extractors/iqiyi.py b/src/you_get/extractors/iqiyi.py index 320520fa..bda2c2e8 100644 --- a/src/you_get/extractors/iqiyi.py +++ b/src/you_get/extractors/iqiyi.py @@ -11,8 +11,6 @@ import hashlib import time -from .iqiyi_sc import gen_sc - ''' Changelog: -> http://www.iqiyi.com/common/flashplayer/20150916/MainPlayer_5_2_28_c3_3_7_4.swf @@ -86,26 +84,31 @@ class Iqiyi(VideoExtractor): name = "爱奇艺 (Iqiyi)" stream_types = [ - {'id': 'high', 'container': 'mp4', 'video_profile': '高清'}, - {'id': 'standard', 'container': 'mp4', 'video_profile': '标清'}, + {'id': 'BD', 'container': 'm3u8', 'video_profile': '全高清'}, + {'id': 'FD', 'container': 'm3u8', 'video_profile': '超高清'}, + {'id': 'TD', 'container': 'm3u8', 'video_profile': '超清'}, + {'id': 'HD', 'container': 'm3u8', 'video_profile': '高清'}, + {'id': 'SD', 'container': 'm3u8', 'video_profile': '标清'}, + {'id': 'LD', 'container': 'm3u8', 'video_profile': '流畅'}, ] - + ''' supported_stream_types = [ 'high', 'standard'] stream_to_bid = { '4k': 10, 'fullhd' : 5, 'suprt-high' : 4, 'super' : 3, 'high' : 2, 'standard' :1, 'topspeed' :96} + ''' + ids = ['BD', 'FD', 'OD', 'TD', 'HD', 'SD', 'LD'] + vd_2_id = {21: 'TD', 2: 'HD', 4: 'FD', 17: 'BD', 96: 'LD', 1: 'SD'} + vd_2_profile = {21: u'超清', 2: u'高清', 4: u'超高清', 17: u'全高清', 96: u'流畅', 1: u'标清'} - def getVMS(self,rate): - #tm ->the flash run time for md5 usage - #um -> vip 1 normal 0 - #authkey -> for password protected video ,replace '' with your password - #puid user.passportid may empty? - #TODO: support password protected video + def getVMS(self): tvid, vid = self.vid t = int(time.time() * 1000) - sc = gen_sc(tvid, t).decode('utf-8') - vmsreq= 'http://cache.m.iqiyi.com/jp/tmts/{}/{}/?platForm=h5&rate={}&tvid={}&vid={}&cupid=qc_100001_100186&type=mp4&olimit=0&agenttype=13&src=d846d0c32d664d32b6b54ea48997a589&sc={}&t={}&__jsT=null'.format(tvid, vid, rate, tvid, vid, sc, t - 7) - return json.loads(get_content(vmsreq)[13:]) + src = '76f90cbd92f94a2e925d83e8ccd22cb7' + key = 'd5fb4bd9d50c4be6948c97edd7254b0e' + sc = hashlib.new('md5', bytes(str(t) + key + vid, 'utf-8')).hexdigest() + vmsreq= url = 'http://cache.m.iqiyi.com/tmts/{0}/{1}/?t={2}&sc={3}&src={4}'.format(tvid,vid,t,sc,src) + return json.loads(get_content(vmsreq)) def download_playlist_by_url(self, url, **kwargs): self.url = url @@ -128,12 +131,16 @@ class Iqiyi(VideoExtractor): r1(r'vid=([^&]+)', self.url) or \ r1(r'data-player-videoid="([^"]+)"', html) self.vid = (tvid, videoid) + self.title = match1(html, '([^<]+)').split('-')[0] + + info = self.getVMS() + assert info['code'] == 'A00000', 'can\'t play this video' + + for stream in info['data']['vidl']: + stream_id = self.vd_2_id[stream['vd']] + stream_profile = self.vd_2_profile[stream['vd']] + self.streams[stream_id] = {'video_profile': stream_profile, 'container': 'm3u8', 'src': [stream['m3u']], 'size' : 0} - for stream in self.supported_stream_types: - info = self.getVMS(self.stream_to_bid[stream]) - if info["code"] == "A00000": - self.title = info['data']['playInfo']['vn'] - self.streams[stream] = {'container': 'mp4', 'video_profile': stream, 'src' : [info['data']['m3u']], 'size' : url_size(info['data']['m3u'])} ''' if info["code"] != "A000000": log.e("[error] outdated iQIYI key")