]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youku.py
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'
17 nowTime
= int(time
.time() * 1000)
18 random1
= random
.randint(1000,1998)
19 random2
= random
.randint(1000,9999)
21 return "%d%d%d" %(nowTime
,random1
,random2
)
23 def _get_file_ID_mix_string(self
, seed
):
25 source
= list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890")
27 for i
in range(len(source
)):
28 seed
= (seed
* 211 + 30031 ) % 65536
29 index
= math
.floor(seed
/ 65536 * len(source
) )
30 mixed
.append(source
[int(index
)])
31 source
.remove(source
[int(index
)])
32 #return ''.join(mixed)
35 def _get_file_id(self
, fileId
, seed
):
36 mixed
= self
._get
_file
_ID
_mix
_string
(seed
)
37 ids
= fileId
.split('*')
41 realId
.append(mixed
[int(ch
)])
42 return ''.join(realId
)
44 def _real_extract(self
, url
):
45 mobj
= re
.match(self
._VALID
_URL
, url
)
47 raise ExtractorError(u
'Invalid URL: %s' % url
)
48 video_id
= mobj
.group('ID')
50 info_url
= 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
52 jsondata
= self
._download
_webpage
(info_url
, video_id
)
54 self
.report_extraction(video_id
)
56 config
= json
.loads(jsondata
)
58 video_title
= config
['data'][0]['title']
59 seed
= config
['data'][0]['seed']
61 format
= self
._downloader
.params
.get('format', None)
62 supported_format
= list(config
['data'][0]['streamfileids'].keys())
64 if format
is None or format
== 'best':
65 if 'hd2' in supported_format
:
70 elif format
== 'worst':
78 fileid
= config
['data'][0]['streamfileids'][format
]
79 keys
= [s
['k'] for s
in config
['data'][0]['segs'][format
]]
80 except (UnicodeDecodeError, ValueError, KeyError):
81 raise ExtractorError(u
'Unable to extract info section')
85 fileid
= self
._get
_file
_id
(fileid
, seed
)
87 #column 8,9 of fileid represent the segment number
88 #fileid[7:9] should be changed
89 for index
, key
in enumerate(keys
):
91 temp_fileid
= '%s%02X%s' % (fileid
[0:8], index
, fileid
[10:])
92 download_url
= 'http://f.youku.com/player/getFlvPath/sid/%s_%02X/st/flv/fileid/%s?k=%s' % (sid
, index
, temp_fileid
, key
)
95 'id': '%s_part%02d' % (video_id
, index
),
102 files_info
.append(info
)