]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youku.py
   3 from __future__ 
import unicode_literals
 
  10 from .common 
import InfoExtractor
 
  16 class YoukuIE(InfoExtractor
): 
  19             http://(?:v|player)\.youku\.com/(?:v_show/id_|player\.php/sid/)| 
  21         (?P<id>[A-Za-z0-9]+)(?:\.html|/v\.swf|) 
  24         'url': 'http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html', 
  25         'md5': 'ffe3f2e435663dc2d1eea34faeff5b5b', 
  30             'id': 'XNDgyMDQ2NTQw_part00', 
  32             'title': 'youtube-dl test video "\'/\\ä↭𝕐' 
  37         nowTime 
= int(time
.time() * 1000) 
  38         random1 
= random
.randint(1000, 1998) 
  39         random2 
= random
.randint(1000, 9999) 
  41         return "%d%d%d" % (nowTime
, random1
, random2
) 
  43     def _get_file_ID_mix_string(self
, seed
): 
  45         source 
= list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890") 
  47         for i 
in range(len(source
)): 
  48             seed 
= (seed 
* 211 + 30031) % 65536 
  49             index 
= math
.floor(seed 
/ 65536 * len(source
)) 
  50             mixed
.append(source
[int(index
)]) 
  51             source
.remove(source
[int(index
)]) 
  52         # return ''.join(mixed) 
  55     def _get_file_id(self
, fileId
, seed
): 
  56         mixed 
= self
._get
_file
_ID
_mix
_string
(seed
) 
  57         ids 
= fileId
.split('*') 
  61                 realId
.append(mixed
[int(ch
)]) 
  62         return ''.join(realId
) 
  64     def _real_extract(self
, url
): 
  65         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  66         video_id 
= mobj
.group('id') 
  68         info_url 
= 'http://v.youku.com/player/getPlayList/VideoIDS/' + video_id
 
  70         config 
= self
._download
_json
(info_url
, video_id
) 
  72         error_code 
= config
['data'][0].get('error_code') 
  74             # -8 means blocked outside China. 
  75             error 
= config
['data'][0].get('error')  # Chinese and English, separated by newline. 
  76             raise ExtractorError(error 
or 'Server reported error %i' % error_code
, 
  79         video_title 
= config
['data'][0]['title'] 
  80         seed 
= config
['data'][0]['seed'] 
  82         format 
= self
._downloader
.params
.get('format', None) 
  83         supported_format 
= list(config
['data'][0]['streamfileids'].keys()) 
  85         # TODO proper format selection 
  86         if format 
is None or format 
== 'best': 
  87             if 'hd2' in supported_format
: 
  92         elif format 
== 'worst': 
  99         fileid 
= config
['data'][0]['streamfileids'][format
] 
 100         keys 
= [s
['k'] for s 
in config
['data'][0]['segs'][format
]] 
 101         # segs is usually a dictionary, but an empty *list* if an error occured. 
 104         sid 
= self
._gen
_sid
() 
 105         fileid 
= self
._get
_file
_id
(fileid
, seed
) 
 107         # column 8,9 of fileid represent the segment number 
 108         # fileid[7:9] should be changed 
 109         for index
, key 
in enumerate(keys
): 
 110             temp_fileid 
= '%s%02X%s' % (fileid
[0:8], index
, fileid
[10:]) 
 111             download_url 
= 'http://k.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
)