4 from .discoverygo
import DiscoveryGoBaseIE
5 from ..compat
import compat_urllib_parse_unquote
6 from ..utils
import ExtractorError
7 from ..compat
import compat_HTTPError
10 class DiscoveryIE(DiscoveryGoBaseIE
):
11 _VALID_URL
= r
'''(?x)https?://
16 investigationdiscovery|
33 )\.com/tv-shows/(?P<show_slug>[^/]+)/(?:video|full-episode)s/(?P<id>[^./?#]+)'''
35 'url': 'https://go.discovery.com/tv-shows/cash-cab/videos/riding-with-matthew-perry',
37 'id': '5a2f35ce6b66d17a5026e29e',
39 'title': 'Riding with Matthew Perry',
40 'description': 'md5:a34333153e79bc4526019a5129e7f878',
44 'skip_download': True, # requires ffmpeg
47 'url': 'https://www.investigationdiscovery.com/tv-shows/final-vision/full-episodes/final-vision',
48 'only_matching': True,
50 'url': 'https://go.discovery.com/tv-shows/alaskan-bush-people/videos/follow-your-own-road',
51 'only_matching': True,
53 # using `show_slug` is important to get the correct video data
54 'url': 'https://www.sciencechannel.com/tv-shows/mythbusters-on-science/full-episodes/christmas-special',
55 'only_matching': True,
57 _GEO_COUNTRIES
= ['US']
59 _API_BASE_URL
= 'https://api.discovery.com/v1/'
61 def _real_extract(self
, url
):
62 site
, show_slug
, display_id
= self
._match
_valid
_url
(url
).groups()
65 cookies
= self
._get
_cookies
(url
)
67 # prefer Affiliate Auth Token over Anonymous Auth Token
68 auth_storage_cookie
= cookies
.get('eosAf') or cookies
.get('eosAn')
69 if auth_storage_cookie
and auth_storage_cookie
.value
:
70 auth_storage
= self
._parse
_json
(compat_urllib_parse_unquote(
71 compat_urllib_parse_unquote(auth_storage_cookie
.value
)),
72 display_id
, fatal
=False) or {}
73 access_token
= auth_storage
.get('a') or auth_storage
.get('access_token')
76 access_token
= self
._download
_json
(
77 'https://%s.com/anonymous' % site
, display_id
,
78 'Downloading token JSON metadata', query
={
79 'authRel': 'authorization',
80 'client_id': '3020a40c2356a645b4b4',
81 'nonce': ''.join([random
.choice(string
.ascii_letters
) for _
in range(32)]),
82 'redirectUri': 'https://www.discovery.com/',
85 headers
= self
.geo_verification_headers()
86 headers
['Authorization'] = 'Bearer ' + access_token
89 video
= self
._download
_json
(
90 self
._API
_BASE
_URL
+ 'content/videos',
91 display_id
, 'Downloading content JSON metadata',
92 headers
=headers
, query
={
94 'fields': 'authenticated,description.detailed,duration,episodeNumber,id,name,parental.rating,season.number,show,tags',
96 'show_slug': show_slug
,
98 video_id
= video
['id']
99 stream
= self
._download
_json
(
100 self
._API
_BASE
_URL
+ 'streaming/video/' + video_id
,
101 display_id
, 'Downloading streaming JSON metadata', headers
=headers
)
102 except ExtractorError
as e
:
103 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
in (401, 403):
104 e_description
= self
._parse
_json
(
105 e
.cause
.read().decode(), display_id
)['description']
106 if 'resource not available for country' in e_description
:
107 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
108 if 'Authorized Networks' in e_description
:
109 raise ExtractorError(
110 'This video is only available via cable service provider subscription that'
111 ' is not currently supported. You may want to use --cookies.', expected
=True)
112 raise ExtractorError(e_description
)
115 return self
._extract
_video
_info
(video
, stream
, display_id
)