]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/daisuki.py
   1 from __future__ 
import unicode_literals
 
   8 from .common 
import InfoExtractor
 
  13 from ..compat 
import compat_b64decode
 
  27 class DaisukiMottoIE(InfoExtractor
): 
  28     _VALID_URL 
= r
'https?://motto\.daisuki\.net/framewatch/embed/[^/]+/(?P<id>[0-9a-zA-Z]{3})' 
  31         'url': 'http://motto.daisuki.net/framewatch/embed/embedDRAGONBALLSUPERUniverseSurvivalsaga/V2e/760/428', 
  35             'title': '#117 SHOWDOWN OF LOVE! ANDROIDS VS UNIVERSE 2!!', 
  43             'skip_download': True,  # AES-encrypted HLS stream 
  47     # The public key in PEM format can be found in clientlibs_anime_watch.min.js 
  48     _RSA_KEY 
= (0xc5524c25e8e14b366b3754940beeb6f96cb7e2feef0b932c7659a0c5c3bf173d602464c2df73d693b513ae06ff1be8f367529ab30bf969c5640522181f2a0c51ea546ae120d3d8d908595e4eff765b389cde080a1ef7f1bbfb07411cc568db73b7f521cedf270cbfbe0ddbc29b1ac9d0f2d8f4359098caffee6d07915020077d, 65537) 
  50     def _real_extract(self
, url
): 
  51         video_id 
= self
._match
_id
(url
) 
  53         webpage 
= self
._download
_webpage
(url
, video_id
) 
  55         flashvars 
= self
._parse
_json
(self
._search
_regex
( 
  56             r
'(?s)var\s+flashvars\s*=\s*({.+?});', webpage
, 'flashvars'), 
  57             video_id
, transform_source
=js_to_json
) 
  62         for key 
in ('device_cd', 'mv_id', 'ss1_prm', 'ss2_prm', 'ss3_prm', 'ss_id'): 
  63             data
[key
] = flashvars
.get(key
, '') 
  67         # Some AES keys are rejected. Try it with different AES keys 
  69             aes_key 
= [random
.randint(0, 254) for _ 
in range(32)] 
  70             padded_aeskey 
= intlist_to_bytes(pkcs1pad(aes_key
, 128)) 
  73             encrypted_aeskey 
= long_to_bytes(pow(bytes_to_long(padded_aeskey
), e
, n
)) 
  74             init_data 
= self
._download
_json
( 
  75                 'http://motto.daisuki.net/fastAPI/bgn/init/', 
  77                     's': flashvars
.get('s', ''), 
  78                     'c': flashvars
.get('ss3_prm', ''), 
  80                     'd': base64
.b64encode(intlist_to_bytes(aes_cbc_encrypt( 
  81                         bytes_to_intlist(json
.dumps(data
)), 
  82                         aes_key
, iv
))).decode('ascii'), 
  83                     'a': base64
.b64encode(encrypted_aeskey
).decode('ascii'), 
  84                 }, note
='Downloading JSON metadata' + (' (try #%d)' % (idx 
+ 1) if idx 
> 0 else '')) 
  86             if 'rtn' in init_data
: 
  87                 encrypted_rtn 
= init_data
['rtn'] 
  90             self
._sleep
(5, video_id
) 
  92         if encrypted_rtn 
is None: 
  93             raise ExtractorError('Failed to fetch init data') 
  95         rtn 
= self
._parse
_json
( 
  96             intlist_to_bytes(aes_cbc_decrypt(bytes_to_intlist( 
  97                 compat_b64decode(encrypted_rtn
)), 
  98                 aes_key
, iv
)).decode('utf-8').rstrip('\0'), 
 101         title 
= rtn
['title_str'] 
 103         formats 
= self
._extract
_m
3u8_formats
( 
 104             rtn
['play_url'], video_id
, ext
='mp4', entry_protocol
='m3u8_native') 
 107         caption_url 
= rtn
.get('caption_url') 
 109             # mul: multiple languages 
 110             subtitles
['mul'] = [{ 
 119             'subtitles': subtitles
, 
 123 class DaisukiMottoPlaylistIE(InfoExtractor
): 
 124     _VALID_URL 
= r
'https?://motto\.daisuki\.net/(?P<id>information)/' 
 127         'url': 'http://motto.daisuki.net/information/', 
 129             'title': 'DRAGON BALL SUPER', 
 131         'playlist_mincount': 117, 
 134     def _real_extract(self
, url
): 
 135         playlist_id 
= self
._match
_id
(url
) 
 137         webpage 
= self
._download
_webpage
(url
, playlist_id
) 
 140         for li 
in re
.findall(r
'(<li[^>]+?data-product_id="[a-zA-Z0-9]{3}"[^>]+>)', webpage
): 
 141             attr 
= extract_attributes(li
) 
 142             ad_id 
= attr
.get('data-ad_id') 
 143             product_id 
= attr
.get('data-product_id') 
 144             if ad_id 
and product_id
: 
 145                 episode_id 
= attr
.get('data-chapter') 
 147                     '_type': 'url_transparent', 
 148                     'url': 'http://motto.daisuki.net/framewatch/embed/%s/%s/760/428' % (ad_id
, product_id
), 
 149                     'episode_id': episode_id
, 
 150                     'episode_number': int_or_none(episode_id
), 
 151                     'ie_key': 'DaisukiMotto', 
 154         return self
.playlist_result(entries
, playlist_title
='DRAGON BALL SUPER')