2 from __future__ import unicode_literals
6 from .adobepass import AdobePassIE
16 class GoIE(AdobePassIE):
20 'requestor_id': 'ABC',
24 'requestor_id': 'ABCFamily',
26 'watchdisneychannel': {
28 'resource_id': 'Disney',
30 'watchdisneyjunior': {
32 'resource_id': 'DisneyJunior',
36 'resource_id': 'DisneyXD',
39 _VALID_URL = r'https?://(?:(?:(?P<sub_domain>%s)\.)?go|disneynow)\.com/(?:(?:[^/]+/)*(?P<id>vdka\w+)|(?:[^/]+/)*(?P<display_id>[^/?#]+))'\
40 % '|'.join(list(_SITE_INFO.keys()) + ['disneynow'])
42 'url': 'http://abc.go.com/shows/designated-survivor/video/most-recent/VDKA3807643',
46 'title': 'The Traitor in the White House',
47 'description': 'md5:05b009d2d145a1e85d25111bd37222e8',
51 'skip_download': True,
54 'url': 'http://watchdisneyxd.go.com/doraemon',
59 'playlist_mincount': 51,
61 'url': 'http://abc.go.com/shows/the-catch/episode-guide/season-01/10-the-wedding',
62 'only_matching': True,
64 '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',
65 'only_matching': True,
68 'url': 'http://disneynow.go.com/shows/big-hero-6-the-series/season-01/episode-10-mr-sparkles-loses-his-sparkle/vdka4637915',
69 'only_matching': True,
72 'url': 'http://disneynow.go.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013',
73 'only_matching': True,
75 'url': 'https://disneynow.com/shows/minnies-bow-toons/video/happy-campers/vdka4872013',
76 'only_matching': True,
79 def _extract_videos(self, brand, video_id='-1', show_id='-1'):
80 display_id = video_id if video_id != '-1' else show_id
81 return self._download_json(
82 '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),
85 def _real_extract(self, url):
86 sub_domain, video_id, display_id = re.match(self._VALID_URL, url).groups()
87 site_info = self._SITE_INFO.get(sub_domain, {})
88 brand = site_info.get('brand')
89 if not video_id or not site_info:
90 webpage = self._download_webpage(url, display_id or video_id)
91 video_id = self._search_regex(
92 # There may be inner quotes, e.g. data-video-id="'VDKA3609139'"
93 # from http://freeform.go.com/shows/shadowhunters/episodes/season-2/1-this-guilty-blood
94 r'data-video-id=["\']*(VDKA\w+)', webpage, 'video id',
97 brand = self._search_regex(
98 (r'data-brand=\s*["\']\s*(\d+)',
99 r'data-page-brand=\s*["\']\s*(\d+)'), webpage, 'brand',
102 si for _, si in self._SITE_INFO.items()
103 if si.get('brand') == brand)
105 # show extraction works for Disney, DisneyJunior and DisneyXD
106 # ABC and Freeform has different layout
107 show_id = self._search_regex(r'data-show-id=["\']*(SH\d+)', webpage, 'show id')
108 videos = self._extract_videos(brand, show_id=show_id)
109 show_title = self._search_regex(r'data-show-title="([^"]+)"', webpage, 'show title', fatal=False)
112 entries.append(self.url_result(
113 video['url'], 'Go', video.get('id'), video.get('title')))
115 return self.playlist_result(entries, show_id, show_title)
116 video_data = self._extract_videos(brand, video_id)[0]
117 video_id = video_data['id']
118 title = video_data['title']
121 for asset in video_data.get('assets', {}).get('asset', []):
122 asset_url = asset.get('value')
125 format_id = asset.get('format')
126 ext = determine_ext(asset_url)
128 video_type = video_data.get('type')
130 'video_id': video_data['id'],
131 'video_type': video_type,
135 if video_data.get('accesslevel') == '1':
136 requestor_id = site_info.get('requestor_id', 'DisneyChannels')
137 resource = site_info.get('resource_id') or self._get_mvpd_resource(
138 requestor_id, title, video_id, None)
139 auth = self._extract_mvpd_auth(
140 url, video_id, requestor_id, resource)
144 'adobe_requestor_id': requestor_id,
147 self._initialize_geo_bypass({'countries': ['US']})
148 entitlement = self._download_json(
149 'https://api.entitlement.watchabc.go.com/vp2/ws-secure/entitlement/2020/authorize.json',
150 video_id, data=urlencode_postdata(data))
151 errors = entitlement.get('errors', {}).get('errors', [])
154 if error.get('code') == 1002:
155 self.raise_geo_restricted(
156 error['message'], countries=['US'])
157 error_message = ', '.join([error['message'] for error in errors])
158 raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True)
159 asset_url += '?' + entitlement['uplynkData']['sessionKey']
160 formats.extend(self._extract_m3u8_formats(
161 asset_url, video_id, 'mp4', m3u8_id=format_id or 'hls', fatal=False))
164 'format_id': format_id,
168 if re.search(r'(?:/mp4/source/|_source\.mp4)', asset_url):
170 'format_id': ('%s-' % format_id if format_id else '') + 'SOURCE',
174 mobj = re.search(r'/(\d+)x(\d+)/', asset_url)
176 height = int(mobj.group(2))
178 'format_id': ('%s-' % format_id if format_id else '') + '%dP' % height,
179 'width': int(mobj.group(1)),
183 self._sort_formats(formats)
186 for cc in video_data.get('closedcaption', {}).get('src', []):
187 cc_url = cc.get('value')
190 ext = determine_ext(cc_url)
193 subtitles.setdefault(cc.get('lang'), []).append({
199 for thumbnail in video_data.get('thumbnails', {}).get('thumbnail', []):
200 thumbnail_url = thumbnail.get('value')
201 if not thumbnail_url:
204 'url': thumbnail_url,
205 'width': int_or_none(thumbnail.get('width')),
206 'height': int_or_none(thumbnail.get('height')),
212 'description': video_data.get('longdescription') or video_data.get('description'),
213 'duration': int_or_none(video_data.get('duration', {}).get('value'), 1000),
214 'age_limit': parse_age_limit(video_data.get('tvrating', {}).get('rating')),
215 'episode_number': int_or_none(video_data.get('episodenumber')),
216 'series': video_data.get('show', {}).get('title'),
217 'season_number': int_or_none(video_data.get('season', {}).get('num')),
218 'thumbnails': thumbnails,
220 'subtitles': subtitles,