]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youku.py
9 from .common
import InfoExtractor
15 class YoukuIE(InfoExtractor
):
16 _VALID_URL
= r
'(?:http://)?(v|player)\.youku\.com/(v_show/id_|player\.php/sid/)(?P<ID>[A-Za-z0-9]+)(\.html|/v.swf)'
18 u
"url": u
"http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html",
19 u
"file": u
"XNDgyMDQ2NTQw_part00.flv",
20 u
"md5": u
"ffe3f2e435663dc2d1eea34faeff5b5b",
21 u
"params": { u
"test": False },
23 u
"title": u
"youtube-dl test video \"'/\\ä↭𝕐"
29 nowTime
= int(time
.time() * 1000)
30 random1
= random
.randint(1000,1998)
31 random2
= random
.randint(1000,9999)
33 return "%d%d%d" %(nowTime
,random1
,random2
)
35 def _get_file_ID_mix_string(self
, seed
):
37 source
= list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
39 for i
in range(len(source
)):
40 seed
= (seed
* 211 + 30031 ) % 65536
41 index
= math
.floor(seed
/ 65536 * len(source
) )
42 mixed
.append(source
[int(index
)])
43 source
.remove(source
[int(index
)])
44 #return ''.join(mixed)
47 def _get_file_id(self
, fileId
, seed
):
48 mixed
= self
._get
_file
_ID
_mix
_string
(seed
)
49 ids
= fileId
.split('*')
53 realId
.append(mixed
[int(ch
)])
54 return ''.join(realId
)
56 def _real_extract(self
, url
):
57 mobj
= re
.match(self
._VALID
_URL
, url
)
59 raise ExtractorError(u
'Invalid URL: %s' % url
)
60 video_id
= mobj
.group('ID')
62 info_url
= 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
64 jsondata
= self
._download
_webpage
(info_url
, video_id
)
66 self
.report_extraction(video_id
)
68 config
= json
.loads(jsondata
)
70 video_title
= config
['data'][0]['title']
71 seed
= config
['data'][0]['seed']
73 format
= self
._downloader
.params
.get('format', None)
74 supported_format
= list(config
['data'][0]['streamfileids'].keys())
76 if format
is None or format
== 'best':
77 if 'hd2' in supported_format
:
82 elif format
== 'worst':
90 fileid
= config
['data'][0]['streamfileids'][format
]
91 keys
= [s
['k'] for s
in config
['data'][0]['segs'][format
]]
92 except (UnicodeDecodeError, ValueError, KeyError):
93 raise ExtractorError(u
'Unable to extract info section')
97 fileid
= self
._get
_file
_id
(fileid
, seed
)
99 #column 8,9 of fileid represent the segment number
100 #fileid[7:9] should be changed
101 for index
, key
in enumerate(keys
):
103 temp_fileid
= '%s%02X%s' % (fileid
[0:8], index
, fileid
[10:])
104 download_url
= 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid
, index
, temp_fileid
, key
)
107 'id': '%s_part%02d' % (video_id
, index
),
111 'title': video_title
,
114 files_info
.append(info
)