]>
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/)|youku:)(?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
)
69 error_code
= config
['data'][0].get('error_code')
71 # -8 means blocked outside China.
72 error
= config
['data'][0].get('error') # Chinese and English, separated by newline.
73 raise ExtractorError(error
or u
'Server reported error %i' % error_code
,
76 video_title
= config
['data'][0]['title']
77 seed
= config
['data'][0]['seed']
79 format
= self
._downloader
.params
.get('format', None)
80 supported_format
= list(config
['data'][0]['streamfileids'].keys())
82 if format
is None or format
== 'best':
83 if 'hd2' in supported_format
:
88 elif format
== 'worst':
96 fileid
= config
['data'][0]['streamfileids'][format
]
97 keys
= [s
['k'] for s
in config
['data'][0]['segs'][format
]]
98 # segs is usually a dictionary, but an empty *list* if an error occured.
99 except (UnicodeDecodeError, ValueError, KeyError):
100 raise ExtractorError(u
'Unable to extract info section')
103 sid
= self
._gen
_sid
()
104 fileid
= self
._get
_file
_id
(fileid
, seed
)
106 #column 8,9 of fileid represent the segment number
107 #fileid[7:9] should be changed
108 for index
, key
in enumerate(keys
):
110 temp_fileid
= '%s%02X%s' % (fileid
[0:8], index
, fileid
[10:])
111 download_url
= 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid
, index
, temp_fileid
, key
)
114 'id': '%s_part%02d' % (video_id
, index
),
118 'title': video_title
,
121 files_info
.append(info
)