7 from .common import InfoExtractor
13 class YoukuIE(InfoExtractor):
14 _VALID_URL = r'(?:http://)?v\.youku\.com/v_show/id_(?P<ID>[A-Za-z0-9]+)\.html'
16 u"url": u"http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html",
17 u"file": u"XNDgyMDQ2NTQw_part00.flv",
18 u"md5": u"ffe3f2e435663dc2d1eea34faeff5b5b",
19 u"params": { u"test": false },
21 u"title": u"youtube-dl test video \"'/\\ä↭𝕐"
27 nowTime = int(time.time() * 1000)
28 random1 = random.randint(1000,1998)
29 random2 = random.randint(1000,9999)
31 return "%d%d%d" %(nowTime,random1,random2)
33 def _get_file_ID_mix_string(self, seed):
35 source = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
37 for i in range(len(source)):
38 seed = (seed * 211 + 30031 ) % 65536
39 index = math.floor(seed / 65536 * len(source) )
40 mixed.append(source[int(index)])
41 source.remove(source[int(index)])
42 #return ''.join(mixed)
45 def _get_file_id(self, fileId, seed):
46 mixed = self._get_file_ID_mix_string(seed)
47 ids = fileId.split('*')
51 realId.append(mixed[int(ch)])
52 return ''.join(realId)
54 def _real_extract(self, url):
55 mobj = re.match(self._VALID_URL, url)
57 raise ExtractorError(u'Invalid URL: %s' % url)
58 video_id = mobj.group('ID')
60 info_url = 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
62 jsondata = self._download_webpage(info_url, video_id)
64 self.report_extraction(video_id)
66 config = json.loads(jsondata)
68 video_title = config['data'][0]['title']
69 seed = config['data'][0]['seed']
71 format = self._downloader.params.get('format', None)
72 supported_format = list(config['data'][0]['streamfileids'].keys())
74 if format is None or format == 'best':
75 if 'hd2' in supported_format:
80 elif format == 'worst':
88 fileid = config['data'][0]['streamfileids'][format]
89 keys = [s['k'] for s in config['data'][0]['segs'][format]]
90 except (UnicodeDecodeError, ValueError, KeyError):
91 raise ExtractorError(u'Unable to extract info section')
95 fileid = self._get_file_id(fileid, seed)
97 #column 8,9 of fileid represent the segment number
98 #fileid[7:9] should be changed
99 for index, key in enumerate(keys):
101 temp_fileid = '%s%02X%s' % (fileid[0:8], index, fileid[10:])
102 download_url = 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid, index, temp_fileid, key)
105 'id': '%s_part%02d' % (video_id, index),
109 'title': video_title,
112 files_info.append(info)