]>
Commit | Line | Data |
---|---|---|
afb74964 | 1 | import json |
48fbb100 | 2 | |
29825140 | 3 | from .turner import TurnerBaseIE |
3fb2a230 | 4 | from ..utils import ( |
afb74964 RA |
5 | determine_ext, |
6 | float_or_none, | |
3fb2a230 | 7 | int_or_none, |
afb74964 RA |
8 | mimetype2ext, |
9 | parse_age_limit, | |
10 | parse_iso8601, | |
3b859145 | 11 | strip_or_none, |
afb74964 | 12 | try_get, |
3fb2a230 | 13 | ) |
48fbb100 | 14 | |
5f6a1245 | 15 | |
29825140 | 16 | class AdultSwimIE(TurnerBaseIE): |
3b859145 | 17 | _VALID_URL = r'https?://(?:www\.)?adultswim\.com/videos/(?P<show_path>[^/?#]+)(?:/(?P<episode_path>[^/?#]+))?' |
71155991 | 18 | |
19 | _TESTS = [{ | |
20 | 'url': 'http://adultswim.com/videos/rick-and-morty/pilot', | |
71155991 | 21 | 'info_dict': { |
11e611a7 | 22 | 'id': 'rQxZvXQ4ROaSOqq-or2Mow', |
3b859145 | 23 | 'ext': 'mp4', |
71155991 | 24 | 'title': 'Rick and Morty - Pilot', |
3b859145 | 25 | 'description': 'Rick moves in with his daughter\'s family and establishes himself as a bad influence on his grandson, Morty.', |
afb74964 RA |
26 | 'timestamp': 1543294800, |
27 | 'upload_date': '20181127', | |
58cd7e17 | 28 | }, |
3b859145 RA |
29 | 'params': { |
30 | # m3u8 download | |
31 | 'skip_download': True, | |
71155991 | 32 | }, |
3b859145 | 33 | 'expected_warnings': ['Unable to download f4m manifest'], |
cc08b11d NJ |
34 | }, { |
35 | 'url': 'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/', | |
cc08b11d NJ |
36 | 'info_dict': { |
37 | 'id': 'sY3cMUR_TbuE4YmdjzbIcQ', | |
3b859145 | 38 | 'ext': 'mp4', |
cc08b11d | 39 | 'title': 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine', |
3b859145 RA |
40 | 'description': 'Dr. Brule reports live from Wine Country with a special report on wines. \nWatch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim.', |
41 | 'upload_date': '20080124', | |
42 | 'timestamp': 1201150800, | |
cc08b11d | 43 | }, |
0f15ad7b | 44 | 'params': { |
45 | # m3u8 download | |
46 | 'skip_download': True, | |
3b859145 | 47 | }, |
afb74964 | 48 | 'skip': '404 Not Found', |
038a5e1a | 49 | }, { |
038a5e1a | 50 | 'url': 'http://www.adultswim.com/videos/decker/inside-decker-a-new-hero/', |
038a5e1a S |
51 | 'info_dict': { |
52 | 'id': 'I0LQFQkaSUaFp8PnAWHhoQ', | |
53 | 'ext': 'mp4', | |
54 | 'title': 'Decker - Inside Decker: A New Hero', | |
3b859145 RA |
55 | 'description': 'The guys recap the conclusion of the season. They announce a new hero, take a peek into the Victorville Film Archive and welcome back the talented James Dean.', |
56 | 'timestamp': 1469480460, | |
57 | 'upload_date': '20160725', | |
038a5e1a S |
58 | }, |
59 | 'params': { | |
60 | # m3u8 download | |
61 | 'skip_download': True, | |
29825140 RA |
62 | }, |
63 | 'expected_warnings': ['Unable to download f4m manifest'], | |
a5a8877f | 64 | }, { |
3b859145 RA |
65 | 'url': 'http://www.adultswim.com/videos/attack-on-titan', |
66 | 'info_dict': { | |
afb74964 | 67 | 'id': 'attack-on-titan', |
3b859145 | 68 | 'title': 'Attack on Titan', |
afb74964 | 69 | 'description': 'md5:41caa9416906d90711e31dc00cb7db7e', |
3b859145 RA |
70 | }, |
71 | 'playlist_mincount': 12, | |
72 | }, { | |
73 | 'url': 'http://www.adultswim.com/videos/streams/williams-stream', | |
a5a8877f | 74 | 'info_dict': { |
3b859145 RA |
75 | 'id': 'd8DEBj7QRfetLsRgFnGEyg', |
76 | 'ext': 'mp4', | |
77 | 'title': r're:^Williams Stream \d{4}-\d{2}-\d{2} \d{2}:\d{2}$', | |
78 | 'description': 'original programming', | |
a5a8877f | 79 | }, |
a5a8877f YCH |
80 | 'params': { |
81 | # m3u8 download | |
82 | 'skip_download': True, | |
83 | }, | |
afb74964 | 84 | 'skip': '404 Not Found', |
71155991 | 85 | }] |
86 | ||
48fbb100 | 87 | def _real_extract(self, url): |
5ad28e7f | 88 | show_path, episode_path = self._match_valid_url(url).groups() |
3b859145 | 89 | display_id = episode_path or show_path |
afb74964 RA |
90 | query = '''query { |
91 | getShowBySlug(slug:"%s") { | |
92 | %%s | |
93 | } | |
94 | }''' % show_path | |
95 | if episode_path: | |
96 | query = query % '''title | |
97 | getVideoBySlug(slug:"%s") { | |
98 | _id | |
99 | auth | |
100 | description | |
101 | duration | |
102 | episodeNumber | |
103 | launchDate | |
104 | mediaID | |
105 | seasonNumber | |
106 | poster | |
107 | title | |
108 | tvRating | |
109 | }''' % episode_path | |
110 | ['getVideoBySlug'] | |
111 | else: | |
112 | query = query % '''metaDescription | |
113 | title | |
114 | videos(first:1000,sort:["episode_number"]) { | |
115 | edges { | |
116 | node { | |
117 | _id | |
118 | slug | |
119 | } | |
120 | } | |
121 | }''' | |
122 | show_data = self._download_json( | |
123 | 'https://www.adultswim.com/api/search', display_id, | |
124 | data=json.dumps({'query': query}).encode(), | |
125 | headers={'Content-Type': 'application/json'})['data']['getShowBySlug'] | |
126 | if episode_path: | |
127 | video_data = show_data['getVideoBySlug'] | |
128 | video_id = video_data['_id'] | |
129 | episode_title = title = video_data['title'] | |
130 | series = show_data.get('title') | |
131 | if series: | |
132 | title = '%s - %s' % (series, title) | |
133 | info = { | |
134 | 'id': video_id, | |
135 | 'title': title, | |
136 | 'description': strip_or_none(video_data.get('description')), | |
137 | 'duration': float_or_none(video_data.get('duration')), | |
138 | 'formats': [], | |
139 | 'subtitles': {}, | |
140 | 'age_limit': parse_age_limit(video_data.get('tvRating')), | |
141 | 'thumbnail': video_data.get('poster'), | |
142 | 'timestamp': parse_iso8601(video_data.get('launchDate')), | |
143 | 'series': series, | |
144 | 'season_number': int_or_none(video_data.get('seasonNumber')), | |
145 | 'episode': episode_title, | |
146 | 'episode_number': int_or_none(video_data.get('episodeNumber')), | |
147 | } | |
3b859145 | 148 | |
afb74964 RA |
149 | auth = video_data.get('auth') |
150 | media_id = video_data.get('mediaID') | |
151 | if media_id: | |
152 | info.update(self._extract_ngtv_info(media_id, { | |
153 | # CDN_TOKEN_APP_ID from: | |
154 | # https://d2gg02c3xr550i.cloudfront.net/assets/asvp.e9c8bef24322d060ef87.bundle.js | |
155 | 'appId': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImFzLXR2ZS1kZXNrdG9wLXB0enQ2bSIsInByb2R1Y3QiOiJ0dmUiLCJuZXR3b3JrIjoiYXMiLCJwbGF0Zm9ybSI6ImRlc2t0b3AiLCJpYXQiOjE1MzI3MDIyNzl9.BzSCk-WYOZ2GMCIaeVb8zWnzhlgnXuJTCu0jGp_VaZE', | |
156 | }, { | |
157 | 'url': url, | |
158 | 'site_name': 'AdultSwim', | |
159 | 'auth_required': auth, | |
160 | })) | |
3b859145 | 161 | |
afb74964 RA |
162 | if not auth: |
163 | extract_data = self._download_json( | |
164 | 'https://www.adultswim.com/api/shows/v1/videos/' + video_id, | |
165 | video_id, query={'fields': 'stream'}, fatal=False) or {} | |
166 | assets = try_get(extract_data, lambda x: x['data']['video']['stream']['assets'], list) or [] | |
167 | for asset in assets: | |
168 | asset_url = asset.get('url') | |
169 | if not asset_url: | |
3b859145 | 170 | continue |
afb74964 RA |
171 | ext = determine_ext(asset_url, mimetype2ext(asset.get('mime_type'))) |
172 | if ext == 'm3u8': | |
173 | info['formats'].extend(self._extract_m3u8_formats( | |
174 | asset_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) | |
175 | elif ext == 'f4m': | |
3b859145 | 176 | continue |
afb74964 RA |
177 | # info['formats'].extend(self._extract_f4m_formats( |
178 | # asset_url, video_id, f4m_id='hds', fatal=False)) | |
179 | elif ext in ('scc', 'ttml', 'vtt'): | |
180 | info['subtitles'].setdefault('en', []).append({ | |
181 | 'url': asset_url, | |
182 | }) | |
3b859145 | 183 | |
afb74964 RA |
184 | return info |
185 | else: | |
186 | entries = [] | |
187 | for edge in show_data.get('videos', {}).get('edges', []): | |
188 | video = edge.get('node') or {} | |
189 | slug = video.get('slug') | |
190 | if not slug: | |
191 | continue | |
192 | entries.append(self.url_result( | |
193 | 'http://adultswim.com/videos/%s/%s' % (show_path, slug), | |
194 | 'AdultSwim', video.get('_id'))) | |
195 | return self.playlist_result( | |
196 | entries, show_path, show_data.get('title'), | |
197 | strip_or_none(show_data.get('metaDescription'))) |