]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/daisuki.py
5c9ac68a02590b3eccea83cd4d9a49ffca47a2e8
1 from __future__
import unicode_literals
8 from .common
import InfoExtractor
26 class DaisukiMottoIE(InfoExtractor
):
27 _VALID_URL
= r
'https?://motto\.daisuki\.net/framewatch/embed/[^/]+/(?P<id>[0-9a-zA-Z]{3})'
30 'url': 'http://motto.daisuki.net/framewatch/embed/embedDRAGONBALLSUPERUniverseSurvivalsaga/V2e/760/428',
34 'title': '#117 SHOWDOWN OF LOVE! ANDROIDS VS UNIVERSE 2!!',
42 'skip_download': True, # AES-encrypted HLS stream
46 # The public key in PEM format can be found in clientlibs_anime_watch.min.js
47 _RSA_KEY
= (0xc5524c25e8e14b366b3754940beeb6f96cb7e2feef0b932c7659a0c5c3bf173d602464c2df73d693b513ae06ff1be8f367529ab30bf969c5640522181f2a0c51ea546ae120d3d8d908595e4eff765b389cde080a1ef7f1bbfb07411cc568db73b7f521cedf270cbfbe0ddbc29b1ac9d0f2d8f4359098caffee6d07915020077d, 65537)
49 def _real_extract(self
, url
):
50 video_id
= self
._match
_id
(url
)
52 webpage
= self
._download
_webpage
(url
, video_id
)
54 flashvars
= self
._parse
_json
(self
._search
_regex
(
55 r
'(?s)var\s+flashvars\s*=\s*({.+?});', webpage
, 'flashvars'),
56 video_id
, transform_source
=js_to_json
)
61 for key
in ('device_cd', 'mv_id', 'ss1_prm', 'ss2_prm', 'ss3_prm', 'ss_id'):
62 data
[key
] = flashvars
.get(key
, '')
66 # Some AES keys are rejected. Try it with different AES keys
68 aes_key
= [random
.randint(0, 254) for _
in range(32)]
69 padded_aeskey
= intlist_to_bytes(pkcs1pad(aes_key
, 128))
72 encrypted_aeskey
= long_to_bytes(pow(bytes_to_long(padded_aeskey
), e
, n
))
73 init_data
= self
._download
_json
(
74 'http://motto.daisuki.net/fastAPI/bgn/init/',
76 's': flashvars
.get('s', ''),
77 'c': flashvars
.get('ss3_prm', ''),
79 'd': base64
.b64encode(intlist_to_bytes(aes_cbc_encrypt(
80 bytes_to_intlist(json
.dumps(data
)),
81 aes_key
, iv
))).decode('ascii'),
82 'a': base64
.b64encode(encrypted_aeskey
).decode('ascii'),
83 }, note
='Downloading JSON metadata' + (' (try #%d)' % (idx
+ 1) if idx
> 0 else ''))
85 if 'rtn' in init_data
:
86 encrypted_rtn
= init_data
['rtn']
89 self
._sleep
(5, video_id
)
91 if encrypted_rtn
is None:
92 raise ExtractorError('Failed to fetch init data')
94 rtn
= self
._parse
_json
(
95 intlist_to_bytes(aes_cbc_decrypt(bytes_to_intlist(
96 base64
.b64decode(encrypted_rtn
)),
97 aes_key
, iv
)).decode('utf-8').rstrip('\0'),
100 title
= rtn
['title_str']
102 formats
= self
._extract
_m
3u8_formats
(
103 rtn
['play_url'], video_id
, ext
='mp4', entry_protocol
='m3u8_native')
106 caption_url
= rtn
.get('caption_url')
108 # mul: multiple languages
109 subtitles
['mul'] = [{
118 'subtitles': subtitles
,
122 class DaisukiMottoPlaylistIE(InfoExtractor
):
123 _VALID_URL
= r
'https?://motto\.daisuki\.net/(?P<id>information)/'
126 'url': 'http://motto.daisuki.net/information/',
128 'title': 'DRAGON BALL SUPER',
130 'playlist_mincount': 117,
133 def _real_extract(self
, url
):
134 playlist_id
= self
._match
_id
(url
)
136 webpage
= self
._download
_webpage
(url
, playlist_id
)
139 for li
in re
.findall(r
'(<li[^>]+?data-product_id="[a-zA-Z0-9]{3}"[^>]+>)', webpage
):
140 attr
= extract_attributes(li
)
141 ad_id
= attr
.get('data-ad_id')
142 product_id
= attr
.get('data-product_id')
143 if ad_id
and product_id
:
144 episode_id
= attr
.get('data-chapter')
146 '_type': 'url_transparent',
147 'url': 'http://motto.daisuki.net/framewatch/embed/%s/%s/760/428' % (ad_id
, product_id
),
148 'episode_id': episode_id
,
149 'episode_number': int_or_none(episode_id
),
150 'ie_key': 'DaisukiMotto',
153 return self
.playlist_result(entries
, playlist_title
='DRAGON BALL SUPER')