1 from __future__ import unicode_literals
7 from .discoverygo import DiscoveryGoBaseIE
12 from ..compat import compat_HTTPError
15 class DiscoveryIE(DiscoveryGoBaseIE):
16 _VALID_URL = r'''(?x)https?://(?:www\.)?(?:
18 investigationdiscovery|
26 )\.com(?P<path>/tv-shows/[^/]+/(?:video|full-episode)s/(?P<id>[^./?#]+))'''
28 'url': 'https://www.discovery.com/tv-shows/cash-cab/videos/dave-foley',
30 'id': '5a2d9b4d6b66d17a5026e1fd',
32 'title': 'Dave Foley',
33 'description': 'md5:4b39bcafccf9167ca42810eb5f28b01f',
37 'skip_download': True, # requires ffmpeg
40 'url': 'https://www.investigationdiscovery.com/tv-shows/final-vision/full-episodes/final-vision',
41 'only_matching': True,
43 _GEO_COUNTRIES = ['US']
46 def _real_extract(self, url):
47 path, display_id = re.match(self._VALID_URL, url).groups()
48 webpage = self._download_webpage(url, display_id)
50 react_data = self._parse_json(self._search_regex(
51 r'window\.__reactTransmitPacket\s*=\s*({.+?});',
52 webpage, 'react data'), display_id)
53 content_blocks = react_data['layout'][path]['contentBlocks']
54 video = next(cb for cb in content_blocks if cb.get('type') == 'video')['content']['items'][0]
55 video_id = video['id']
57 access_token = self._download_json(
58 'https://www.discovery.com/anonymous', display_id, query={
59 'authLink': update_url_query(
60 'https://login.discovery.com/v1/oauth2/authorize', {
61 'client_id': react_data['application']['apiClientId'],
62 'redirect_uri': 'https://fusion.ddmcdn.com/app/mercury-sdk/180/redirectHandler.html',
63 'response_type': 'anonymous',
64 'state': 'nonce,' + ''.join([random.choice(string.ascii_letters) for _ in range(32)]),
69 stream = self._download_json(
70 'https://api.discovery.com/v1/streaming/video/' + video_id,
72 'Authorization': 'Bearer ' + access_token,
74 except ExtractorError as e:
75 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
76 e_description = self._parse_json(
77 e.cause.read().decode(), display_id)['description']
78 if 'resource not available for country' in e_description:
79 self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
80 if 'Authorized Networks' in e_description:
82 'This video is only available via cable service provider subscription that'
83 ' is not currently supported. You may want to use --cookies.', expected=True)
84 raise ExtractorError(e_description)
87 return self._extract_video_info(video, stream, display_id)