]>
Commit | Line | Data |
---|---|---|
2c3e0af9 RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
ae8d5a5c | 6 | from .adobepass import AdobePassIE |
1bdae7d3 | 7 | from ..compat import compat_str |
2c3e0af9 RA |
8 | from ..utils import ( |
9 | int_or_none, | |
10 | determine_ext, | |
11 | parse_age_limit, | |
3b4775e0 | 12 | remove_start, |
13 | remove_end, | |
1bdae7d3 | 14 | try_get, |
014b7e6b RA |
15 | urlencode_postdata, |
16 | ExtractorError, | |
2c3e0af9 RA |
17 | ) |
18 | ||
19 | ||
ae8d5a5c RA |
20 | class GoIE(AdobePassIE): |
21 | _SITE_INFO = { | |
22 | 'abc': { | |
23 | 'brand': '001', | |
24 | 'requestor_id': 'ABC', | |
25 | }, | |
26 | 'freeform': { | |
27 | 'brand': '002', | |
28 | 'requestor_id': 'ABCFamily', | |
29 | }, | |
30 | 'watchdisneychannel': { | |
31 | 'brand': '004', | |
118afcf5 | 32 | 'resource_id': 'Disney', |
ae8d5a5c RA |
33 | }, |
34 | 'watchdisneyjunior': { | |
35 | 'brand': '008', | |
118afcf5 | 36 | 'resource_id': 'DisneyJunior', |
ae8d5a5c RA |
37 | }, |
38 | 'watchdisneyxd': { | |
39 | 'brand': '009', | |
118afcf5 | 40 | 'resource_id': 'DisneyXD', |
a30c2f40 S |
41 | }, |
42 | 'disneynow': { | |
43 | 'brand': '011', | |
44 | 'resource_id': 'Disney', | |
29f7c58a | 45 | }, |
46 | 'fxnow.fxnetworks': { | |
47 | 'brand': '025', | |
48 | 'requestor_id': 'dtci', | |
49 | }, | |
2c3e0af9 | 50 | } |
aef9f87e S |
51 | _VALID_URL = r'''(?x) |
52 | https?:// | |
3b4775e0 | 53 | (?P<sub_domain> |
54 | (?:%s\.)?go|fxnow\.fxnetworks| | |
55 | (?:www\.)?(?:abc|freeform|disneynow) | |
aef9f87e S |
56 | )\.com/ |
57 | (?: | |
58 | (?:[^/]+/)*(?P<id>[Vv][Dd][Kk][Aa]\w+)| | |
59 | (?:[^/]+/)*(?P<display_id>[^/?\#]+) | |
60 | ) | |
3b4775e0 | 61 | ''' % r'\.|'.join(list(_SITE_INFO.keys())) |
2c3e0af9 | 62 | _TESTS = [{ |
bf2a5555 | 63 | 'url': 'http://abc.go.com/shows/designated-survivor/video/most-recent/VDKA3807643', |
2c3e0af9 | 64 | 'info_dict': { |
bf2a5555 | 65 | 'id': 'VDKA3807643', |
2c3e0af9 | 66 | 'ext': 'mp4', |
bf2a5555 RA |
67 | 'title': 'The Traitor in the White House', |
68 | 'description': 'md5:05b009d2d145a1e85d25111bd37222e8', | |
2c3e0af9 RA |
69 | }, |
70 | 'params': { | |
71 | # m3u8 download | |
72 | 'skip_download': True, | |
73 | }, | |
dd90a21c | 74 | 'skip': 'This content is no longer available.', |
2c3e0af9 | 75 | }, { |
bf2a5555 RA |
76 | 'url': 'http://watchdisneyxd.go.com/doraemon', |
77 | 'info_dict': { | |
78 | 'title': 'Doraemon', | |
79 | 'id': 'SH55574025', | |
80 | }, | |
81 | 'playlist_mincount': 51, | |
dd90a21c S |
82 | }, { |
83 | 'url': 'http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood', | |
84 | 'info_dict': { | |
85 | 'id': 'VDKA3609139', | |
86 | 'ext': 'mp4', | |
87 | 'title': 'This Guilty Blood', | |
88 | 'description': 'md5:f18e79ad1c613798d95fdabfe96cd292', | |
89 | 'age_limit': 14, | |
90 | }, | |
91 | 'params': { | |
92 | 'geo_bypass_ip_block': '3.244.239.0/24', | |
93 | # m3u8 download | |
94 | 'skip_download': True, | |
95 | }, | |
96 | }, { | |
97 | 'url': 'https://abc.com/shows/the-rookie/episode-guide/season-02/03-the-bet', | |
98 | 'info_dict': { | |
99 | 'id': 'VDKA13435179', | |
100 | 'ext': 'mp4', | |
101 | 'title': 'The Bet', | |
102 | 'description': 'md5:c66de8ba2e92c6c5c113c3ade84ab404', | |
103 | 'age_limit': 14, | |
104 | }, | |
105 | 'params': { | |
106 | 'geo_bypass_ip_block': '3.244.239.0/24', | |
107 | # m3u8 download | |
108 | 'skip_download': True, | |
109 | }, | |
29f7c58a | 110 | }, { |
111 | 'url': 'https://fxnow.fxnetworks.com/shows/better-things/video/vdka12782841', | |
112 | 'info_dict': { | |
113 | 'id': 'VDKA12782841', | |
114 | 'ext': 'mp4', | |
115 | 'title': 'First Look: Better Things - Season 2', | |
116 | 'description': 'md5:fa73584a95761c605d9d54904e35b407', | |
117 | }, | |
118 | 'params': { | |
119 | 'geo_bypass_ip_block': '3.244.239.0/24', | |
120 | # m3u8 download | |
121 | 'skip_download': True, | |
122 | }, | |
1bdae7d3 | 123 | }, { |
124 | 'url': 'https://abc.com/shows/modern-family/episode-guide/season-01/101-pilot', | |
125 | 'info_dict': { | |
126 | 'id': 'VDKA22600213', | |
127 | 'ext': 'mp4', | |
128 | 'title': 'Pilot', | |
129 | 'description': 'md5:74306df917cfc199d76d061d66bebdb4', | |
130 | }, | |
131 | 'params': { | |
132 | # m3u8 download | |
133 | 'skip_download': True, | |
134 | }, | |
692fa200 S |
135 | }, { |
136 | 'url': 'http://abc.go.com/shows/the-catch/episode-guide/season-01/10-the-wedding', | |
137 | 'only_matching': True, | |
138 | }, { | |
139 | 'url': 'http://abc.go.com/shows/world-news-tonight/episode-guide/2017-02/17-021717-intense-stand-off-between-man-with-rifle-and-police-in-oakland', | |
140 | 'only_matching': True, | |
52007de8 S |
141 | }, { |
142 | # brand 004 | |
143 | 'url': 'http://disneynow.go.com/shows/big-hero-6-the-series/season-01/episode-10-mr-sparkles-loses-his-sparkle/vdka4637915', | |
144 | 'only_matching': True, | |
145 | }, { | |
146 | # brand 008 | |
147 | 'url': 'http://disneynow.go.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013', | |
148 | 'only_matching': True, | |
4f71473e S |
149 | }, { |
150 | 'url': 'https://disneynow.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013', | |
151 | 'only_matching': True, | |
3b4775e0 | 152 | }, { |
153 | 'url': 'https://www.freeform.com/shows/cruel-summer/episode-guide/season-01/01-happy-birthday-jeanette-turner', | |
154 | 'only_matching': True, | |
2c3e0af9 RA |
155 | }] |
156 | ||
bf2a5555 RA |
157 | def _extract_videos(self, brand, video_id='-1', show_id='-1'): |
158 | display_id = video_id if video_id != '-1' else show_id | |
159 | return self._download_json( | |
160 | 'http://api.contents.watchabc.go.com/vp2/ws/contents/3000/videos/%s/001/-1/%s/-1/%s/-1/-1.json' % (brand, show_id, video_id), | |
161 | display_id)['video'] | |
162 | ||
2c3e0af9 | 163 | def _real_extract(self, url): |
a30c2f40 | 164 | mobj = re.match(self._VALID_URL, url) |
3b4775e0 | 165 | sub_domain = remove_start(remove_end(mobj.group('sub_domain') or '', '.go'), 'www.') |
a30c2f40 | 166 | video_id, display_id = mobj.group('id', 'display_id') |
52007de8 S |
167 | site_info = self._SITE_INFO.get(sub_domain, {}) |
168 | brand = site_info.get('brand') | |
169 | if not video_id or not site_info: | |
170 | webpage = self._download_webpage(url, display_id or video_id) | |
1bdae7d3 | 171 | data = self._parse_json( |
172 | self._search_regex( | |
173 | r'["\']__abc_com__["\']\s*\]\s*=\s*({.+?})\s*;', webpage, | |
174 | 'data', default='{}'), | |
175 | display_id or video_id, fatal=False) | |
176 | # https://abc.com/shows/modern-family/episode-guide/season-01/101-pilot | |
177 | layout = try_get(data, lambda x: x['page']['content']['video']['layout'], dict) | |
178 | video_id = None | |
179 | if layout: | |
180 | video_id = try_get( | |
181 | layout, | |
182 | (lambda x: x['videoid'], lambda x: x['video']['id']), | |
183 | compat_str) | |
184 | if not video_id: | |
185 | video_id = self._search_regex( | |
186 | ( | |
187 | # There may be inner quotes, e.g. data-video-id="'VDKA3609139'" | |
188 | # from http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood | |
189 | r'data-video-id=["\']*(VDKA\w+)', | |
190 | # page.analytics.videoIdCode | |
191 | r'\bvideoIdCode["\']\s*:\s*["\']((?:vdka|VDKA)\w+)', | |
192 | # https://abc.com/shows/the-rookie/episode-guide/season-02/03-the-bet | |
193 | r'\b(?:video)?id["\']\s*:\s*["\'](VDKA\w+)' | |
194 | ), webpage, 'video id', default=video_id) | |
52007de8 S |
195 | if not site_info: |
196 | brand = self._search_regex( | |
197 | (r'data-brand=\s*["\']\s*(\d+)', | |
198 | r'data-page-brand=\s*["\']\s*(\d+)'), webpage, 'brand', | |
199 | default='004') | |
200 | site_info = next( | |
201 | si for _, si in self._SITE_INFO.items() | |
202 | if si.get('brand') == brand) | |
bf2a5555 RA |
203 | if not video_id: |
204 | # show extraction works for Disney, DisneyJunior and DisneyXD | |
205 | # ABC and Freeform has different layout | |
206 | show_id = self._search_regex(r'data-show-id=["\']*(SH\d+)', webpage, 'show id') | |
207 | videos = self._extract_videos(brand, show_id=show_id) | |
208 | show_title = self._search_regex(r'data-show-title="([^"]+)"', webpage, 'show title', fatal=False) | |
209 | entries = [] | |
210 | for video in videos: | |
211 | entries.append(self.url_result( | |
212 | video['url'], 'Go', video.get('id'), video.get('title'))) | |
213 | entries.reverse() | |
214 | return self.playlist_result(entries, show_id, show_title) | |
215 | video_data = self._extract_videos(brand, video_id)[0] | |
216 | video_id = video_data['id'] | |
2c3e0af9 RA |
217 | title = video_data['title'] |
218 | ||
219 | formats = [] | |
220 | for asset in video_data.get('assets', {}).get('asset', []): | |
221 | asset_url = asset.get('value') | |
222 | if not asset_url: | |
223 | continue | |
224 | format_id = asset.get('format') | |
225 | ext = determine_ext(asset_url) | |
226 | if ext == 'm3u8': | |
014b7e6b | 227 | video_type = video_data.get('type') |
8e1409fd RA |
228 | data = { |
229 | 'video_id': video_data['id'], | |
230 | 'video_type': video_type, | |
231 | 'brand': brand, | |
232 | 'device': '001', | |
233 | } | |
234 | if video_data.get('accesslevel') == '1': | |
118afcf5 RA |
235 | requestor_id = site_info.get('requestor_id', 'DisneyChannels') |
236 | resource = site_info.get('resource_id') or self._get_mvpd_resource( | |
8e1409fd RA |
237 | requestor_id, title, video_id, None) |
238 | auth = self._extract_mvpd_auth( | |
239 | url, video_id, requestor_id, resource) | |
240 | data.update({ | |
241 | 'token': auth, | |
242 | 'token_type': 'ap', | |
243 | 'adobe_requestor_id': requestor_id, | |
244 | }) | |
245 | else: | |
5f95927a | 246 | self._initialize_geo_bypass({'countries': ['US']}) |
8e1409fd RA |
247 | entitlement = self._download_json( |
248 | 'https://api.entitlement.watchabc.go.com/vp2/ws-secure/entitlement/2020/authorize.json', | |
bf2a5555 | 249 | video_id, data=urlencode_postdata(data)) |
8e1409fd RA |
250 | errors = entitlement.get('errors', {}).get('errors', []) |
251 | if errors: | |
252 | for error in errors: | |
253 | if error.get('code') == 1002: | |
254 | self.raise_geo_restricted( | |
255 | error['message'], countries=['US']) | |
256 | error_message = ', '.join([error['message'] for error in errors]) | |
257 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True) | |
258 | asset_url += '?' + entitlement['uplynkData']['sessionKey'] | |
2c3e0af9 RA |
259 | formats.extend(self._extract_m3u8_formats( |
260 | asset_url, video_id, 'mp4', m3u8_id=format_id or 'hls', fatal=False)) | |
261 | else: | |
8e1409fd | 262 | f = { |
2c3e0af9 RA |
263 | 'format_id': format_id, |
264 | 'url': asset_url, | |
265 | 'ext': ext, | |
8e1409fd RA |
266 | } |
267 | if re.search(r'(?:/mp4/source/|_source\.mp4)', asset_url): | |
268 | f.update({ | |
269 | 'format_id': ('%s-' % format_id if format_id else '') + 'SOURCE', | |
f983b875 | 270 | 'quality': 1, |
8e1409fd RA |
271 | }) |
272 | else: | |
273 | mobj = re.search(r'/(\d+)x(\d+)/', asset_url) | |
274 | if mobj: | |
275 | height = int(mobj.group(2)) | |
276 | f.update({ | |
277 | 'format_id': ('%s-' % format_id if format_id else '') + '%dP' % height, | |
278 | 'width': int(mobj.group(1)), | |
279 | 'height': height, | |
280 | }) | |
281 | formats.append(f) | |
2c3e0af9 RA |
282 | self._sort_formats(formats) |
283 | ||
284 | subtitles = {} | |
285 | for cc in video_data.get('closedcaption', {}).get('src', []): | |
286 | cc_url = cc.get('value') | |
287 | if not cc_url: | |
288 | continue | |
289 | ext = determine_ext(cc_url) | |
290 | if ext == 'xml': | |
291 | ext = 'ttml' | |
292 | subtitles.setdefault(cc.get('lang'), []).append({ | |
293 | 'url': cc_url, | |
294 | 'ext': ext, | |
295 | }) | |
296 | ||
297 | thumbnails = [] | |
298 | for thumbnail in video_data.get('thumbnails', {}).get('thumbnail', []): | |
299 | thumbnail_url = thumbnail.get('value') | |
300 | if not thumbnail_url: | |
301 | continue | |
302 | thumbnails.append({ | |
303 | 'url': thumbnail_url, | |
304 | 'width': int_or_none(thumbnail.get('width')), | |
305 | 'height': int_or_none(thumbnail.get('height')), | |
306 | }) | |
307 | ||
308 | return { | |
309 | 'id': video_id, | |
310 | 'title': title, | |
311 | 'description': video_data.get('longdescription') or video_data.get('description'), | |
312 | 'duration': int_or_none(video_data.get('duration', {}).get('value'), 1000), | |
313 | 'age_limit': parse_age_limit(video_data.get('tvrating', {}).get('rating')), | |
314 | 'episode_number': int_or_none(video_data.get('episodenumber')), | |
315 | 'series': video_data.get('show', {}).get('title'), | |
316 | 'season_number': int_or_none(video_data.get('season', {}).get('num')), | |
317 | 'thumbnails': thumbnails, | |
318 | 'formats': formats, | |
319 | 'subtitles': subtitles, | |
320 | } |