]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/discovery.py
91449dcd8549e992afed748651ad0e3312812721
1 from __future__
import unicode_literals
7 from .discoverygo
import DiscoveryGoBaseIE
8 from ..compat
import compat_str
13 from ..compat
import compat_HTTPError
16 class DiscoveryIE(DiscoveryGoBaseIE
):
17 _VALID_URL
= r
'''(?x)https?://(?:www\.)?(?P<site>
19 investigationdiscovery|
27 )\.com(?P<path>/tv-shows/[^/]+/(?:video|full-episode)s/(?P<id>[^./?#]+))'''
29 'url': 'https://www.discovery.com/tv-shows/cash-cab/videos/dave-foley',
31 'id': '5a2d9b4d6b66d17a5026e1fd',
33 'title': 'Dave Foley',
34 'description': 'md5:4b39bcafccf9167ca42810eb5f28b01f',
38 'skip_download': True, # requires ffmpeg
41 'url': 'https://www.investigationdiscovery.com/tv-shows/final-vision/full-episodes/final-vision',
42 'only_matching': True,
44 _GEO_COUNTRIES
= ['US']
47 def _real_extract(self
, url
):
48 site
, path
, display_id
= re
.match(self
._VALID
_URL
, url
).groups()
49 webpage
= self
._download
_webpage
(url
, display_id
)
51 react_data
= self
._parse
_json
(self
._search
_regex
(
52 r
'window\.__reactTransmitPacket\s*=\s*({.+?});',
53 webpage
, 'react data'), display_id
)
54 content_blocks
= react_data
['layout'][path
]['contentBlocks']
55 video
= next(cb
for cb
in content_blocks
if cb
.get('type') == 'video')['content']['items'][0]
56 video_id
= video
['id']
58 access_token
= self
._download
_json
(
59 'https://www.%s.com/anonymous' % site
, display_id
, query
={
60 'authRel': 'authorization',
62 react_data
, lambda x
: x
['application']['apiClientId'],
63 compat_str
) or '3020a40c2356a645b4b4',
64 'nonce': ''.join([random
.choice(string
.ascii_letters
) for _
in range(32)]),
65 'redirectUri': 'https://fusion.ddmcdn.com/app/mercury-sdk/180/redirectHandler.html?https://www.%s.com' % site
,
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
)