3 from .common
import InfoExtractor
16 class DiscoveryGoBaseIE(InfoExtractor
):
17 _VALID_URL_TEMPLATE
= r
'''(?x)https?://(?:www\.)?(?:
19 investigationdiscovery|
27 )go\.com/%s(?P<id>[^/?#&]+)'''
29 def _extract_video_info(self
, video
, stream
, display_id
):
33 if video
.get('authenticated') is True:
35 'This video is only available via cable service provider subscription that'
36 ' is not currently supported. You may want to use --cookies.', expected
=True)
38 raise ExtractorError('Unable to find stream')
39 STREAM_URL_SUFFIX
= 'streamUrl'
41 for stream_kind
in ('', 'hds'):
42 suffix
= STREAM_URL_SUFFIX
.capitalize() if stream_kind
else STREAM_URL_SUFFIX
43 stream_url
= stream
.get('%s%s' % (stream_kind
, suffix
))
47 formats
.extend(self
._extract
_m
3u8_formats
(
48 stream_url
, display_id
, 'mp4', entry_protocol
='m3u8_native',
49 m3u8_id
='hls', fatal
=False))
50 elif stream_kind
== 'hds':
51 formats
.extend(self
._extract
_f
4m
_formats
(
52 stream_url
, display_id
, f4m_id
=stream_kind
, fatal
=False))
54 video_id
= video
.get('id') or display_id
55 description
= video
.get('description', {}).get('detailed')
56 duration
= int_or_none(video
.get('duration'))
58 series
= video
.get('show', {}).get('name')
59 season_number
= int_or_none(video
.get('season', {}).get('number'))
60 episode_number
= int_or_none(video
.get('episodeNumber'))
62 tags
= video
.get('tags')
63 age_limit
= parse_age_limit(video
.get('parental', {}).get('rating'))
66 captions
= stream
.get('captions')
67 if isinstance(captions
, list):
68 for caption
in captions
:
69 subtitle_url
= url_or_none(caption
.get('fileUrl'))
70 if not subtitle_url
or not subtitle_url
.startswith('http'):
72 lang
= caption
.get('fileLang', 'en')
73 ext
= determine_ext(subtitle_url
)
74 subtitles
.setdefault(lang
, []).append({
76 'ext': 'ttml' if ext
== 'xml' else ext
,
81 'display_id': display_id
,
83 'description': description
,
86 'season_number': season_number
,
87 'episode_number': episode_number
,
89 'age_limit': age_limit
,
91 'subtitles': subtitles
,
95 class DiscoveryGoIE(DiscoveryGoBaseIE
):
96 _VALID_URL
= DiscoveryGoBaseIE
._VALID
_URL
_TEMPLATE
% r
'(?:[^/]+/)+'
97 _GEO_COUNTRIES
= ['US']
99 'url': 'https://www.discoverygo.com/bering-sea-gold/reaper-madness/',
101 'id': '58c167d86b66d12f2addeb01',
103 'title': 'Reaper Madness',
104 'description': 'md5:09f2c625c99afb8946ed4fb7865f6e78',
106 'series': 'Bering Sea Gold',
113 def _real_extract(self
, url
):
114 display_id
= self
._match
_id
(url
)
116 webpage
= self
._download
_webpage
(url
, display_id
)
118 container
= extract_attributes(
120 r
'(<div[^>]+class=["\']video
-player
-container
[^
>]+>)',
121 webpage, 'video container
'))
123 video = self._parse_json(
124 container.get('data
-video
') or container.get('data
-json
'),
127 stream = video.get('stream
')
129 return self._extract_video_info(video, stream, display_id)
132 class DiscoveryGoPlaylistIE(DiscoveryGoBaseIE):
133 _VALID_URL = DiscoveryGoBaseIE._VALID_URL_TEMPLATE % ''
135 'url
': 'https
://www
.discoverygo
.com
/bering
-sea
-gold
/',
137 'id': 'bering
-sea
-gold
',
138 'title
': 'Bering Sea Gold
',
139 'description
': 'md5
:cc5c6489835949043c0cc3ad66c2fa0e
',
141 'playlist_mincount
': 6,
145 def suitable(cls, url):
146 return False if DiscoveryGoIE.suitable(url) else super(
147 DiscoveryGoPlaylistIE, cls).suitable(url)
149 def _real_extract(self, url):
150 display_id = self._match_id(url)
152 webpage = self._download_webpage(url, display_id)
155 for mobj in re.finditer(r'data
-json
=(["\'])(?P<json>{.+?})\1', webpage):
156 data = self._parse_json(
157 mobj.group('json'), display_id,
158 transform_source=unescapeHTML, fatal=False)
159 if not isinstance(data, dict) or data.get('type') != 'episode':
161 episode_url = data.get('socialUrl')
164 entries.append(self.url_result(
165 episode_url, ie=DiscoveryGoIE.ie_key(),
166 video_id=data.get('id')))
168 return self.playlist_result(
170 remove_end(self._og_search_title(
171 webpage, fatal=False), ' | Discovery GO'),
172 self._og_search_description(webpage))