1 from __future__ import unicode_literals
8 from .common import InfoExtractor
28 class DaisukiIE(InfoExtractor):
29 _VALID_URL = r'https?://(?:www\.)?daisuki\.net/[^/]+/[^/]+/[^/]+/watch\.[^.]+\.(?P<id>\d+)\.html'
32 'url': 'http://www.daisuki.net/tw/en/anime/watch.TheIdolMasterCG.11213.html',
36 'title': '#01 Who is in the pumpkin carriage? - THE IDOLM@STER CINDERELLA GIRLS',
37 'creator': 'BANDAI NAMCO Entertainment',
40 'skip_download': True, # AES-encrypted HLS stream
44 # The public key in PEM format can be found in clientlibs_anime_watch.min.js
45 _RSA_KEY = (0xc5524c25e8e14b366b3754940beeb6f96cb7e2feef0b932c7659a0c5c3bf173d602464c2df73d693b513ae06ff1be8f367529ab30bf969c5640522181f2a0c51ea546ae120d3d8d908595e4eff765b389cde080a1ef7f1bbfb07411cc568db73b7f521cedf270cbfbe0ddbc29b1ac9d0f2d8f4359098caffee6d07915020077d, 65537)
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
50 webpage = self._download_webpage(url, video_id)
52 flashvars = self._parse_json(self._search_regex(
53 r'(?s)var\s+flashvars\s*=\s*({.+?});', webpage, 'flashvars'),
54 video_id, transform_source=js_to_json)
59 for key in ('device_cd', 'mv_id', 'ss1_prm', 'ss2_prm', 'ss3_prm', 'ss_id'):
60 data[key] = flashvars.get(key, '')
64 # Some AES keys are rejected. Try it with different AES keys
66 aes_key = [random.randint(0, 254) for _ in range(32)]
67 padded_aeskey = intlist_to_bytes(pkcs1pad(aes_key, 128))
70 encrypted_aeskey = long_to_bytes(pow(bytes_to_long(padded_aeskey), e, n))
71 init_data = self._download_json('http://www.daisuki.net/bin/bgn/init', video_id, query={
72 's': flashvars.get('s', ''),
73 'c': flashvars.get('ss3_prm', ''),
75 'd': base64.b64encode(intlist_to_bytes(aes_cbc_encrypt(
76 bytes_to_intlist(json.dumps(data)),
77 aes_key, iv))).decode('ascii'),
78 'a': base64.b64encode(encrypted_aeskey).decode('ascii'),
79 }, note='Downloading JSON metadata' + (' (try #%d)' % (idx + 1) if idx > 0 else ''))
81 if 'rtn' in init_data:
82 encrypted_rtn = init_data['rtn']
85 self._sleep(5, video_id)
87 if encrypted_rtn is None:
88 raise ExtractorError('Failed to fetch init data')
90 rtn = self._parse_json(
91 intlist_to_bytes(aes_cbc_decrypt(bytes_to_intlist(
92 base64.b64decode(encrypted_rtn)),
93 aes_key, iv)).decode('utf-8').rstrip('\0'),
96 formats = self._extract_m3u8_formats(
97 rtn['play_url'], video_id, ext='mp4', entry_protocol='m3u8_native')
99 title = remove_end(self._og_search_title(webpage), ' - DAISUKI')
101 creator = self._html_search_regex(
102 r'Creator\s*:\s*([^<]+)', webpage, 'creator', fatal=False)
112 class DaisukiPlaylistIE(InfoExtractor):
113 _VALID_URL = r'https?://(?:www\.)daisuki\.net/[^/]+/[^/]+/[^/]+/detail\.(?P<id>[a-zA-Z0-9]+)\.html'
116 'url': 'http://www.daisuki.net/tw/en/anime/detail.TheIdolMasterCG.html',
118 'id': 'TheIdolMasterCG',
119 'title': 'THE IDOLM@STER CINDERELLA GIRLS',
120 'description': 'md5:0f2c028a9339f7a2c7fbf839edc5c5d8',
122 'playlist_count': 26,
125 def _real_extract(self, url):
126 playlist_id = self._match_id(url)
128 webpage = self._download_webpage(url, playlist_id)
130 episode_pattern = r'''(?sx)
131 <img[^>]+delay="[^"]+/(\d+)/movie\.jpg".+?
132 <p[^>]+class=".*?\bepisodeNumber\b.*?">(?:<a[^>]+>)?([^<]+)'''
134 '_type': 'url_transparent',
135 'url': url.replace('detail', 'watch').replace('.html', '.' + movie_id + '.html'),
136 'episode_id': episode_id,
137 'episode_number': int_or_none(episode_id),
138 } for movie_id, episode_id in re.findall(episode_pattern, webpage)]
140 playlist_title = remove_end(
141 self._og_search_title(webpage, fatal=False), ' - Anime - DAISUKI')
142 playlist_description = clean_html(get_element_by_id('synopsisTxt', webpage))
144 return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)