]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/dplay.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / dplay.py
CommitLineData
bc2ca1bb 1import json
5118d2ec 2import uuid
4cd759f7
JMF
3
4from .common import InfoExtractor
3d2623a8 5from ..networking.exceptions import HTTPError
5448b781 6from ..utils import (
0cf2352e 7 ExtractorError,
e897bd82 8 determine_ext,
864a4576 9 float_or_none,
5448b781 10 int_or_none,
0f06bcd7 11 remove_start,
bc2ca1bb 12 strip_or_none,
5118d2ec 13 try_get,
864a4576 14 unified_timestamp,
5448b781 15)
940b606a 16
4cd759f7 17
5118d2ec 18class DPlayBaseIE(InfoExtractor):
bc2ca1bb 19 _PATH_REGEX = r'/(?P<id>[^/]+/[^/?#]+)'
5118d2ec
AG
20 _auth_token_cache = {}
21
22 def _get_auth(self, disco_base, display_id, realm, needs_device_id=True):
23 key = (disco_base, realm)
24 st = self._get_cookies(disco_base).get('st')
25 token = (st and st.value) or self._auth_token_cache.get(key)
26
27 if not token:
28 query = {'realm': realm}
29 if needs_device_id:
30 query['deviceId'] = uuid.uuid4().hex
31 token = self._download_json(
32 disco_base + 'token', display_id, 'Downloading token',
33 query=query)['data']['attributes']['token']
34
35 # Save cache only if cookies are not being set
36 if not self._get_cookies(disco_base).get('st'):
37 self._auth_token_cache[key] = token
38
39 return f'Bearer {token}'
40
41 def _process_errors(self, e, geo_countries):
3d2623a8 42 info = self._parse_json(e.cause.response.read().decode('utf-8'), None)
5118d2ec
AG
43 error = info['errors'][0]
44 error_code = error.get('code')
45 if error_code == 'access.denied.geoblocked':
46 self.raise_geo_restricted(countries=geo_countries)
47 elif error_code in ('access.denied.missingpackage', 'invalid.token'):
48 raise ExtractorError(
49 'This video is only available for registered users. You may want to use --cookies.', expected=True)
50 raise ExtractorError(info['errors'][0]['detail'], expected=True)
51
52 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
53 headers['Authorization'] = self._get_auth(disco_base, display_id, realm, False)
54
55 def _download_video_playback_info(self, disco_base, video_id, headers):
56 streaming = self._download_json(
57 disco_base + 'playback/videoPlaybackInfo/' + video_id,
58 video_id, headers=headers)['data']['attributes']['streaming']
59 streaming_list = []
60 for format_id, format_dict in streaming.items():
61 streaming_list.append({
62 'type': format_id,
63 'url': format_dict.get('url'),
64 })
65 return streaming_list
66
67 def _get_disco_api_info(self, url, display_id, disco_host, realm, country, domain=''):
774aa09d 68 country = self.get_param('geo_bypass_country') or country
5118d2ec
AG
69 geo_countries = [country.upper()]
70 self._initialize_geo_bypass({
71 'countries': geo_countries,
72 })
73 disco_base = 'https://%s/' % disco_host
74 headers = {
75 'Referer': url,
76 }
77 self._update_disco_api_headers(headers, disco_base, display_id, realm)
78 try:
79 video = self._download_json(
80 disco_base + 'content/videos/' + display_id, display_id,
81 headers=headers, query={
82 'fields[channel]': 'name',
83 'fields[image]': 'height,src,width',
84 'fields[show]': 'name',
85 'fields[tag]': 'name',
86 'fields[video]': 'description,episodeNumber,name,publishStart,seasonNumber,videoDuration',
87 'include': 'images,primaryChannel,show,tags'
88 })
89 except ExtractorError as e:
3d2623a8 90 if isinstance(e.cause, HTTPError) and e.cause.status == 400:
5118d2ec
AG
91 self._process_errors(e, geo_countries)
92 raise
93 video_id = video['data']['id']
94 info = video['data']['attributes']
95 title = info['name'].strip()
96 formats = []
97 subtitles = {}
98 try:
99 streaming = self._download_video_playback_info(
100 disco_base, video_id, headers)
101 except ExtractorError as e:
3d2623a8 102 if isinstance(e.cause, HTTPError) and e.cause.status == 403:
5118d2ec
AG
103 self._process_errors(e, geo_countries)
104 raise
105 for format_dict in streaming:
106 if not isinstance(format_dict, dict):
107 continue
108 format_url = format_dict.get('url')
109 if not format_url:
110 continue
111 format_id = format_dict.get('type')
112 ext = determine_ext(format_url)
113 if format_id == 'dash' or ext == 'mpd':
114 dash_fmts, dash_subs = self._extract_mpd_formats_and_subtitles(
115 format_url, display_id, mpd_id='dash', fatal=False)
116 formats.extend(dash_fmts)
117 subtitles = self._merge_subtitles(subtitles, dash_subs)
118 elif format_id == 'hls' or ext == 'm3u8':
119 m3u8_fmts, m3u8_subs = self._extract_m3u8_formats_and_subtitles(
120 format_url, display_id, 'mp4',
121 entry_protocol='m3u8_native', m3u8_id='hls',
122 fatal=False)
123 formats.extend(m3u8_fmts)
124 subtitles = self._merge_subtitles(subtitles, m3u8_subs)
125 else:
126 formats.append({
127 'url': format_url,
128 'format_id': format_id,
129 })
5118d2ec
AG
130
131 creator = series = None
132 tags = []
133 thumbnails = []
134 included = video.get('included') or []
135 if isinstance(included, list):
136 for e in included:
137 attributes = e.get('attributes')
138 if not attributes:
139 continue
140 e_type = e.get('type')
141 if e_type == 'channel':
142 creator = attributes.get('name')
143 elif e_type == 'image':
144 src = attributes.get('src')
145 if src:
146 thumbnails.append({
147 'url': src,
148 'width': int_or_none(attributes.get('width')),
149 'height': int_or_none(attributes.get('height')),
150 })
151 if e_type == 'show':
152 series = attributes.get('name')
153 elif e_type == 'tag':
154 name = attributes.get('name')
155 if name:
156 tags.append(name)
157 return {
158 'id': video_id,
159 'display_id': display_id,
160 'title': title,
161 'description': strip_or_none(info.get('description')),
162 'duration': float_or_none(info.get('videoDuration'), 1000),
163 'timestamp': unified_timestamp(info.get('publishStart')),
164 'series': series,
165 'season_number': int_or_none(info.get('seasonNumber')),
166 'episode_number': int_or_none(info.get('episodeNumber')),
167 'creator': creator,
168 'tags': tags,
169 'thumbnails': thumbnails,
170 'formats': formats,
171 'subtitles': subtitles,
172 'http_headers': {
173 'referer': domain,
174 },
175 }
176
177
178class DPlayIE(DPlayBaseIE):
0b98f3a7
RA
179 _VALID_URL = r'''(?x)https?://
180 (?P<domain>
00dd0cd5 181 (?:www\.)?(?P<host>d
182 (?:
183 play\.(?P<country>dk|fi|jp|se|no)|
184 iscoveryplus\.(?P<plus_country>dk|es|fi|it|se|no)
185 )
186 )|
0b98f3a7 187 (?P<subdomain_country>es|it)\.dplay\.com
5118d2ec 188 )/[^/]+''' + DPlayBaseIE._PATH_REGEX
95050537 189
940b606a 190 _TESTS = [{
5448b781 191 # non geo restricted, via secure api, unsigned download hls URL
0b98f3a7 192 'url': 'https://www.dplay.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
940b606a 193 'info_dict': {
0b98f3a7
RA
194 'id': '13628',
195 'display_id': 'nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
5448b781 196 'ext': 'mp4',
940b606a
S
197 'title': 'Svensken lär sig njuta av livet',
198 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
0b98f3a7
RA
199 'duration': 2649.856,
200 'timestamp': 1365453720,
940b606a 201 'upload_date': '20130408',
0b98f3a7 202 'creator': 'Kanal 5',
940b606a
S
203 'series': 'Nugammalt - 77 händelser som format Sverige',
204 'season_number': 1,
205 'episode_number': 1,
0b98f3a7
RA
206 },
207 'params': {
0b98f3a7 208 'skip_download': True,
95050537 209 },
940b606a 210 }, {
5448b781 211 # geo restricted, via secure api, unsigned download hls URL
0b98f3a7 212 'url': 'http://www.dplay.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
940b606a 213 'info_dict': {
0b98f3a7
RA
214 'id': '104465',
215 'display_id': 'ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
5448b781 216 'ext': 'mp4',
0b98f3a7
RA
217 'title': 'Ted Bundy: Mind Of A Monster',
218 'description': 'md5:8b780f6f18de4dae631668b8a9637995',
219 'duration': 5290.027,
220 'timestamp': 1570694400,
221 'upload_date': '20191010',
222 'creator': 'ID - Investigation Discovery',
223 'series': 'Ted Bundy: Mind Of A Monster',
224 'season_number': 1,
225 'episode_number': 1,
226 },
227 'params': {
0b98f3a7 228 'skip_download': True,
940b606a 229 },
864a4576
S
230 }, {
231 # disco-api
232 'url': 'https://www.dplay.no/videoer/i-kongens-klr/sesong-1-episode-7',
233 'info_dict': {
234 'id': '40206',
235 'display_id': 'i-kongens-klr/sesong-1-episode-7',
236 'ext': 'mp4',
237 'title': 'Episode 7',
238 'description': 'md5:e3e1411b2b9aebeea36a6ec5d50c60cf',
239 'duration': 2611.16,
240 'timestamp': 1516726800,
241 'upload_date': '20180123',
242 'series': 'I kongens klær',
243 'season_number': 1,
244 'episode_number': 7,
245 },
246 'params': {
864a4576
S
247 'skip_download': True,
248 },
0b98f3a7 249 'skip': 'Available for Premium users',
a0ee342b 250 }, {
0b98f3a7
RA
251 'url': 'http://it.dplay.com/nove/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij/',
252 'md5': '2b808ffb00fc47b884a172ca5d13053c',
253 'info_dict': {
254 'id': '6918',
255 'display_id': 'biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
256 'ext': 'mp4',
257 'title': 'Luigi Di Maio: la psicosi di Stanislawskij',
258 'description': 'md5:3c7a4303aef85868f867a26f5cc14813',
259 'thumbnail': r're:^https?://.*\.jpe?g',
260 'upload_date': '20160524',
261 'timestamp': 1464076800,
262 'series': 'Biografie imbarazzanti',
263 'season_number': 1,
264 'episode': 'Episode 1',
265 'episode_number': 1,
266 },
267 }, {
268 'url': 'https://es.dplay.com/dmax/la-fiebre-del-oro/temporada-8-episodio-1/',
269 'info_dict': {
270 'id': '21652',
271 'display_id': 'la-fiebre-del-oro/temporada-8-episodio-1',
272 'ext': 'mp4',
273 'title': 'Episodio 1',
274 'description': 'md5:b9dcff2071086e003737485210675f69',
275 'thumbnail': r're:^https?://.*\.png',
276 'upload_date': '20180709',
277 'timestamp': 1531173540,
278 'series': 'La fiebre del oro',
279 'season_number': 8,
280 'episode': 'Episode 1',
281 'episode_number': 1,
282 },
283 'params': {
284 'skip_download': True,
285 },
286 }, {
287 'url': 'https://www.dplay.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
a0ee342b 288 'only_matching': True,
d6b15291 289 }, {
0b98f3a7 290 'url': 'https://www.dplay.jp/video/gold-rush/24086',
d6b15291 291 'only_matching': True,
00dd0cd5 292 }, {
293 'url': 'https://www.discoveryplus.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
294 'only_matching': True,
295 }, {
296 'url': 'https://www.discoveryplus.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
297 'only_matching': True,
298 }, {
299 'url': 'https://www.discoveryplus.no/videoer/i-kongens-klr/sesong-1-episode-7',
300 'only_matching': True,
301 }, {
302 'url': 'https://www.discoveryplus.it/videos/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
303 'only_matching': True,
304 }, {
305 'url': 'https://www.discoveryplus.es/videos/la-fiebre-del-oro/temporada-8-episodio-1',
306 'only_matching': True,
307 }, {
308 'url': 'https://www.discoveryplus.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
309 'only_matching': True,
940b606a 310 }]
4cd759f7
JMF
311
312 def _real_extract(self, url):
5ad28e7f 313 mobj = self._match_valid_url(url)
940b606a 314 display_id = mobj.group('id')
0f06bcd7 315 domain = remove_start(mobj.group('domain'), 'www.')
00dd0cd5 316 country = mobj.group('country') or mobj.group('subdomain_country') or mobj.group('plus_country')
317 host = 'disco-api.' + domain if domain[0] == 'd' else 'eu2-prod.disco-api.com'
0b98f3a7 318 return self._get_disco_api_info(
5118d2ec 319 url, display_id, host, 'dplay' + country, country, domain)
bc2ca1bb 320
321
5118d2ec
AG
322class HGTVDeIE(DPlayBaseIE):
323 _VALID_URL = r'https?://de\.hgtv\.com/sendungen' + DPlayBaseIE._PATH_REGEX
45d1f157
S
324 _TESTS = [{
325 'url': 'https://de.hgtv.com/sendungen/tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette/',
326 'info_dict': {
327 'id': '151205',
328 'display_id': 'tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette',
329 'ext': 'mp4',
330 'title': 'Wer braucht schon eine Toilette',
331 'description': 'md5:05b40a27e7aed2c9172de34d459134e2',
332 'duration': 1177.024,
333 'timestamp': 1595705400,
334 'upload_date': '20200725',
335 'creator': 'HGTV',
336 'series': 'Tiny House - klein, aber oho',
337 'season_number': 3,
338 'episode_number': 3,
339 },
45d1f157
S
340 }]
341
342 def _real_extract(self, url):
343 display_id = self._match_id(url)
344 return self._get_disco_api_info(
345 url, display_id, 'eu1-prod.disco-api.com', 'hgtv', 'de')
346
347
0bb5ac1a 348class DiscoveryPlusBaseIE(DPlayBaseIE):
bc2ca1bb 349 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
c12977bd 350 headers['x-disco-client'] = f'WEB:UNKNOWN:{self._PRODUCT}:25.2.6'
bc2ca1bb 351
352 def _download_video_playback_info(self, disco_base, video_id, headers):
353 return self._download_json(
354 disco_base + 'playback/v3/videoPlaybackInfo',
355 video_id, headers=headers, data=json.dumps({
356 'deviceInfo': {
357 'adBlocker': False,
90d2da31 358 'drmSupported': False,
bc2ca1bb 359 },
360 'videoId': video_id,
90d2da31 361 'wisteriaProperties': {},
bc2ca1bb 362 }).encode('utf-8'))['data']['attributes']['streaming']
363
364 def _real_extract(self, url):
0bb5ac1a 365 return self._get_disco_api_info(url, self._match_id(url), **self._DISCO_API_PARAMS)
bc2ca1bb 366
367
7df07a3b
S
368class GoDiscoveryIE(DiscoveryPlusBaseIE):
369 _VALID_URL = r'https?://(?:go\.)?discovery\.com/video' + DPlayBaseIE._PATH_REGEX
370 _TESTS = [{
371 'url': 'https://go.discovery.com/video/dirty-jobs-discovery-atve-us/rodbuster-galvanizer',
372 'info_dict': {
373 'id': '4164906',
374 'display_id': 'dirty-jobs-discovery-atve-us/rodbuster-galvanizer',
375 'ext': 'mp4',
376 'title': 'Rodbuster / Galvanizer',
377 'description': 'Mike installs rebar with a team of rodbusters, then he galvanizes steel.',
378 'season_number': 9,
379 'episode_number': 1,
380 },
381 'skip': 'Available for Premium users',
382 }, {
383 'url': 'https://discovery.com/video/dirty-jobs-discovery-atve-us/rodbuster-galvanizer',
384 'only_matching': True,
385 }]
386
387 _PRODUCT = 'dsc'
388 _DISCO_API_PARAMS = {
389 'disco_host': 'us1-prod-direct.go.discovery.com',
390 'realm': 'go',
391 'country': 'us',
392 }
393
394
395class TravelChannelIE(DiscoveryPlusBaseIE):
396 _VALID_URL = r'https?://(?:watch\.)?travelchannel\.com/video' + DPlayBaseIE._PATH_REGEX
397 _TESTS = [{
398 'url': 'https://watch.travelchannel.com/video/ghost-adventures-travel-channel/ghost-train-of-ely',
399 'info_dict': {
400 'id': '2220256',
401 'display_id': 'ghost-adventures-travel-channel/ghost-train-of-ely',
402 'ext': 'mp4',
403 'title': 'Ghost Train of Ely',
404 'description': 'The crew investigates the dark history of the Nevada Northern Railway.',
405 'season_number': 24,
406 'episode_number': 1,
407 },
408 'skip': 'Available for Premium users',
409 }, {
410 'url': 'https://watch.travelchannel.com/video/ghost-adventures-travel-channel/ghost-train-of-ely',
411 'only_matching': True,
412 }]
413
414 _PRODUCT = 'trav'
415 _DISCO_API_PARAMS = {
416 'disco_host': 'us1-prod-direct.watch.travelchannel.com',
417 'realm': 'go',
418 'country': 'us',
419 }
420
421
422class CookingChannelIE(DiscoveryPlusBaseIE):
423 _VALID_URL = r'https?://(?:watch\.)?cookingchanneltv\.com/video' + DPlayBaseIE._PATH_REGEX
424 _TESTS = [{
425 'url': 'https://watch.cookingchanneltv.com/video/carnival-eats-cooking-channel/the-postman-always-brings-rice-2348634',
426 'info_dict': {
427 'id': '2348634',
428 'display_id': 'carnival-eats-cooking-channel/the-postman-always-brings-rice-2348634',
429 'ext': 'mp4',
430 'title': 'The Postman Always Brings Rice',
431 'description': 'Noah visits the Maui Fair and the Aurora Winter Festival in Vancouver.',
432 'season_number': 9,
433 'episode_number': 1,
434 },
435 'skip': 'Available for Premium users',
436 }, {
437 'url': 'https://watch.cookingchanneltv.com/video/carnival-eats-cooking-channel/the-postman-always-brings-rice-2348634',
438 'only_matching': True,
439 }]
440
441 _PRODUCT = 'cook'
442 _DISCO_API_PARAMS = {
443 'disco_host': 'us1-prod-direct.watch.cookingchanneltv.com',
444 'realm': 'go',
445 'country': 'us',
446 }
447
448
449class HGTVUsaIE(DiscoveryPlusBaseIE):
450 _VALID_URL = r'https?://(?:watch\.)?hgtv\.com/video' + DPlayBaseIE._PATH_REGEX
451 _TESTS = [{
452 'url': 'https://watch.hgtv.com/video/home-inspector-joe-hgtv-atve-us/this-mold-house',
453 'info_dict': {
454 'id': '4289736',
455 'display_id': 'home-inspector-joe-hgtv-atve-us/this-mold-house',
456 'ext': 'mp4',
457 'title': 'This Mold House',
458 'description': 'Joe and Noel help take a familys dream home from hazardous to fabulous.',
459 'season_number': 1,
460 'episode_number': 1,
461 },
462 'skip': 'Available for Premium users',
463 }, {
464 'url': 'https://watch.hgtv.com/video/home-inspector-joe-hgtv-atve-us/this-mold-house',
465 'only_matching': True,
466 }]
467
468 _PRODUCT = 'hgtv'
469 _DISCO_API_PARAMS = {
470 'disco_host': 'us1-prod-direct.watch.hgtv.com',
471 'realm': 'go',
472 'country': 'us',
473 }
474
475
476class FoodNetworkIE(DiscoveryPlusBaseIE):
477 _VALID_URL = r'https?://(?:watch\.)?foodnetwork\.com/video' + DPlayBaseIE._PATH_REGEX
478 _TESTS = [{
479 'url': 'https://watch.foodnetwork.com/video/kids-baking-championship-food-network/float-like-a-butterfly',
480 'info_dict': {
481 'id': '4116449',
482 'display_id': 'kids-baking-championship-food-network/float-like-a-butterfly',
483 'ext': 'mp4',
484 'title': 'Float Like a Butterfly',
485 'description': 'The 12 kid bakers create colorful carved butterfly cakes.',
486 'season_number': 10,
487 'episode_number': 1,
488 },
489 'skip': 'Available for Premium users',
490 }, {
491 'url': 'https://watch.foodnetwork.com/video/kids-baking-championship-food-network/float-like-a-butterfly',
492 'only_matching': True,
493 }]
494
495 _PRODUCT = 'food'
496 _DISCO_API_PARAMS = {
497 'disco_host': 'us1-prod-direct.watch.foodnetwork.com',
498 'realm': 'go',
499 'country': 'us',
500 }
501
502
503class DestinationAmericaIE(DiscoveryPlusBaseIE):
504 _VALID_URL = r'https?://(?:www\.)?destinationamerica\.com/video' + DPlayBaseIE._PATH_REGEX
505 _TESTS = [{
506 'url': 'https://www.destinationamerica.com/video/alaska-monsters-destination-america-atve-us/central-alaskas-bigfoot',
507 'info_dict': {
508 'id': '4210904',
509 'display_id': 'alaska-monsters-destination-america-atve-us/central-alaskas-bigfoot',
510 'ext': 'mp4',
511 'title': 'Central Alaskas Bigfoot',
512 'description': 'A team heads to central Alaska to investigate an aggressive Bigfoot.',
513 'season_number': 1,
514 'episode_number': 1,
515 },
516 'skip': 'Available for Premium users',
517 }, {
518 'url': 'https://www.destinationamerica.com/video/alaska-monsters-destination-america-atve-us/central-alaskas-bigfoot',
519 'only_matching': True,
520 }]
521
522 _PRODUCT = 'dam'
523 _DISCO_API_PARAMS = {
524 'disco_host': 'us1-prod-direct.destinationamerica.com',
525 'realm': 'go',
526 'country': 'us',
527 }
528
529
530class InvestigationDiscoveryIE(DiscoveryPlusBaseIE):
531 _VALID_URL = r'https?://(?:www\.)?investigationdiscovery\.com/video' + DPlayBaseIE._PATH_REGEX
532 _TESTS = [{
533 'url': 'https://www.investigationdiscovery.com/video/unmasked-investigation-discovery/the-killer-clown',
534 'info_dict': {
535 'id': '2139409',
536 'display_id': 'unmasked-investigation-discovery/the-killer-clown',
537 'ext': 'mp4',
538 'title': 'The Killer Clown',
539 'description': 'A wealthy Florida woman is fatally shot in the face by a clown at her door.',
540 'season_number': 1,
541 'episode_number': 1,
542 },
543 'skip': 'Available for Premium users',
544 }, {
545 'url': 'https://www.investigationdiscovery.com/video/unmasked-investigation-discovery/the-killer-clown',
546 'only_matching': True,
547 }]
548
549 _PRODUCT = 'ids'
550 _DISCO_API_PARAMS = {
551 'disco_host': 'us1-prod-direct.investigationdiscovery.com',
552 'realm': 'go',
553 'country': 'us',
554 }
555
556
557class AmHistoryChannelIE(DiscoveryPlusBaseIE):
558 _VALID_URL = r'https?://(?:www\.)?ahctv\.com/video' + DPlayBaseIE._PATH_REGEX
559 _TESTS = [{
560 'url': 'https://www.ahctv.com/video/modern-sniper-ahc/army',
561 'info_dict': {
562 'id': '2309730',
563 'display_id': 'modern-sniper-ahc/army',
564 'ext': 'mp4',
565 'title': 'Army',
566 'description': 'Snipers today face challenges their predecessors couldve only dreamed of.',
567 'season_number': 1,
568 'episode_number': 1,
569 },
570 'skip': 'Available for Premium users',
571 }, {
572 'url': 'https://www.ahctv.com/video/modern-sniper-ahc/army',
573 'only_matching': True,
574 }]
575
576 _PRODUCT = 'ahc'
577 _DISCO_API_PARAMS = {
578 'disco_host': 'us1-prod-direct.ahctv.com',
579 'realm': 'go',
580 'country': 'us',
581 }
582
583
0bb5ac1a 584class ScienceChannelIE(DiscoveryPlusBaseIE):
5118d2ec 585 _VALID_URL = r'https?://(?:www\.)?sciencechannel\.com/video' + DPlayBaseIE._PATH_REGEX
bc2ca1bb 586 _TESTS = [{
45d1f157 587 'url': 'https://www.sciencechannel.com/video/strangest-things-science-atve-us/nazi-mystery-machine',
bc2ca1bb 588 'info_dict': {
45d1f157
S
589 'id': '2842849',
590 'display_id': 'strangest-things-science-atve-us/nazi-mystery-machine',
bc2ca1bb 591 'ext': 'mp4',
45d1f157
S
592 'title': 'Nazi Mystery Machine',
593 'description': 'Experts investigate the secrets of a revolutionary encryption machine.',
594 'season_number': 1,
595 'episode_number': 1,
bc2ca1bb 596 },
45d1f157 597 'skip': 'Available for Premium users',
7df07a3b
S
598 }, {
599 'url': 'https://www.sciencechannel.com/video/strangest-things-science-atve-us/nazi-mystery-machine',
600 'only_matching': True,
bc2ca1bb 601 }]
602
45d1f157 603 _PRODUCT = 'sci'
0bb5ac1a 604 _DISCO_API_PARAMS = {
605 'disco_host': 'us1-prod-direct.sciencechannel.com',
606 'realm': 'go',
607 'country': 'us',
608 }
b5a39ed4
S
609
610
0bb5ac1a 611class DIYNetworkIE(DiscoveryPlusBaseIE):
5118d2ec 612 _VALID_URL = r'https?://(?:watch\.)?diynetwork\.com/video' + DPlayBaseIE._PATH_REGEX
b5a39ed4
S
613 _TESTS = [{
614 'url': 'https://watch.diynetwork.com/video/pool-kings-diy-network/bringing-beach-life-to-texas',
615 'info_dict': {
616 'id': '2309730',
617 'display_id': 'pool-kings-diy-network/bringing-beach-life-to-texas',
618 'ext': 'mp4',
619 'title': 'Bringing Beach Life to Texas',
620 'description': 'The Pool Kings give a family a day at the beach in their own backyard.',
621 'season_number': 10,
622 'episode_number': 2,
623 },
624 'skip': 'Available for Premium users',
7df07a3b
S
625 }, {
626 'url': 'https://watch.diynetwork.com/video/pool-kings-diy-network/bringing-beach-life-to-texas',
627 'only_matching': True,
b5a39ed4
S
628 }]
629
630 _PRODUCT = 'diy'
0bb5ac1a 631 _DISCO_API_PARAMS = {
632 'disco_host': 'us1-prod-direct.watch.diynetwork.com',
633 'realm': 'go',
634 'country': 'us',
635 }
c12977bd
S
636
637
7df07a3b
S
638class DiscoveryLifeIE(DiscoveryPlusBaseIE):
639 _VALID_URL = r'https?://(?:www\.)?discoverylife\.com/video' + DPlayBaseIE._PATH_REGEX
640 _TESTS = [{
641 'url': 'https://www.discoverylife.com/video/surviving-death-discovery-life-atve-us/bodily-trauma',
642 'info_dict': {
643 'id': '2218238',
644 'display_id': 'surviving-death-discovery-life-atve-us/bodily-trauma',
645 'ext': 'mp4',
646 'title': 'Bodily Trauma',
647 'description': 'Meet three people who tested the limits of the human body.',
648 'season_number': 1,
649 'episode_number': 2,
650 },
651 'skip': 'Available for Premium users',
652 }, {
653 'url': 'https://www.discoverylife.com/video/surviving-death-discovery-life-atve-us/bodily-trauma',
654 'only_matching': True,
655 }]
656
657 _PRODUCT = 'dlf'
658 _DISCO_API_PARAMS = {
659 'disco_host': 'us1-prod-direct.discoverylife.com',
660 'realm': 'go',
661 'country': 'us',
662 }
663
664
0bb5ac1a 665class AnimalPlanetIE(DiscoveryPlusBaseIE):
5118d2ec 666 _VALID_URL = r'https?://(?:www\.)?animalplanet\.com/video' + DPlayBaseIE._PATH_REGEX
c12977bd
S
667 _TESTS = [{
668 'url': 'https://www.animalplanet.com/video/north-woods-law-animal-planet/squirrel-showdown',
669 'info_dict': {
670 'id': '3338923',
671 'display_id': 'north-woods-law-animal-planet/squirrel-showdown',
672 'ext': 'mp4',
673 'title': 'Squirrel Showdown',
674 'description': 'A woman is suspected of being in possession of flying squirrel kits.',
675 'season_number': 16,
676 'episode_number': 11,
677 },
678 'skip': 'Available for Premium users',
7df07a3b
S
679 }, {
680 'url': 'https://www.animalplanet.com/video/north-woods-law-animal-planet/squirrel-showdown',
681 'only_matching': True,
c12977bd
S
682 }]
683
684 _PRODUCT = 'apl'
0bb5ac1a 685 _DISCO_API_PARAMS = {
686 'disco_host': 'us1-prod-direct.animalplanet.com',
687 'realm': 'go',
688 'country': 'us',
689 }
690
691
7df07a3b
S
692class TLCIE(DiscoveryPlusBaseIE):
693 _VALID_URL = r'https?://(?:go\.)?tlc\.com/video' + DPlayBaseIE._PATH_REGEX
694 _TESTS = [{
695 'url': 'https://go.tlc.com/video/my-600-lb-life-tlc/melissas-story-part-1',
696 'info_dict': {
697 'id': '2206540',
698 'display_id': 'my-600-lb-life-tlc/melissas-story-part-1',
699 'ext': 'mp4',
700 'title': 'Melissas Story (Part 1)',
701 'description': 'At 650 lbs, Melissa is ready to begin her seven-year weight loss journey.',
702 'season_number': 1,
703 'episode_number': 1,
704 },
705 'skip': 'Available for Premium users',
706 }, {
707 'url': 'https://go.tlc.com/video/my-600-lb-life-tlc/melissas-story-part-1',
708 'only_matching': True,
709 }]
710
711 _PRODUCT = 'tlc'
712 _DISCO_API_PARAMS = {
713 'disco_host': 'us1-prod-direct.tlc.com',
714 'realm': 'go',
715 'country': 'us',
716 }
717
718
26bafe70
S
719class MotorTrendIE(DiscoveryPlusBaseIE):
720 _VALID_URL = r'https?://(?:watch\.)?motortrend\.com/video' + DPlayBaseIE._PATH_REGEX
721 _TESTS = [{
722 'url': 'https://watch.motortrend.com/video/car-issues-motortrend-atve-us/double-dakotas',
723 'info_dict': {
724 'id': '"4859182"',
725 'display_id': 'double-dakotas',
726 'ext': 'mp4',
727 'title': 'Double Dakotas',
728 'description': 'Tylers buy-one-get-one Dakota deal has the Wizard pulling double duty.',
729 'season_number': 2,
730 'episode_number': 3,
731 },
732 'skip': 'Available for Premium users',
733 }, {
734 'url': 'https://watch.motortrend.com/video/car-issues-motortrend-atve-us/double-dakotas',
735 'only_matching': True,
736 }]
737
738 _PRODUCT = 'vel'
739 _DISCO_API_PARAMS = {
740 'disco_host': 'us1-prod-direct.watch.motortrend.com',
741 'realm': 'go',
742 'country': 'us',
743 }
744
745
f0394096 746class MotorTrendOnDemandIE(DiscoveryPlusBaseIE):
c03a58ec 747 _VALID_URL = r'https?://(?:www\.)?motortrend(?:ondemand\.com|\.com/plus)/detail' + DPlayBaseIE._PATH_REGEX
f0394096 748 _TESTS = [{
749 'url': 'https://www.motortrendondemand.com/detail/wheelstanding-dump-truck-stubby-bobs-comeback/37699/784',
750 'info_dict': {
751 'id': '37699',
752 'display_id': 'wheelstanding-dump-truck-stubby-bobs-comeback/37699',
753 'ext': 'mp4',
754 'title': 'Wheelstanding Dump Truck! Stubby Bob’s Comeback',
755 'description': 'md5:996915abe52a1c3dfc83aecea3cce8e7',
756 'season_number': 5,
757 'episode_number': 52,
758 'episode': 'Episode 52',
759 'season': 'Season 5',
760 'thumbnail': r're:^https?://.+\.jpe?g$',
761 'timestamp': 1388534401,
762 'duration': 1887.345,
763 'creator': 'Originals',
764 'series': 'Roadkill',
765 'upload_date': '20140101',
766 'tags': [],
767 },
c03a58ec
AA
768 }, {
769 'url': 'https://www.motortrend.com/plus/detail/roadworthy-rescues-teaser-trailer/4922860/',
770 'info_dict': {
771 'id': '4922860',
772 'ext': 'mp4',
773 'title': 'Roadworthy Rescues | Teaser Trailer',
774 'description': 'Derek Bieri helps Freiburger and Finnegan with their \'68 big-block Dart.',
775 'display_id': 'roadworthy-rescues-teaser-trailer/4922860',
776 'creator': 'Originals',
777 'series': 'Roadworthy Rescues',
778 'thumbnail': r're:^https?://.+\.jpe?g$',
779 'upload_date': '20220907',
780 'timestamp': 1662523200,
781 'duration': 1066.356,
782 'tags': [],
783 },
784 }, {
785 'url': 'https://www.motortrend.com/plus/detail/ugly-duckling/2450033/12439',
786 'only_matching': True,
f0394096 787 }]
788
789 _PRODUCT = 'MTOD'
790 _DISCO_API_PARAMS = {
791 'disco_host': 'us1-prod-direct.motortrendondemand.com',
792 'realm': 'motortrend',
793 'country': 'us',
794 }
795
796 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
797 headers.update({
798 'x-disco-params': f'realm={realm}',
799 'x-disco-client': f'WEB:UNKNOWN:{self._PRODUCT}:4.39.1-gi1',
800 'Authorization': self._get_auth(disco_base, display_id, realm),
801 })
802
803
0bb5ac1a 804class DiscoveryPlusIE(DiscoveryPlusBaseIE):
805 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.com/(?!it/)(?:\w{2}/)?video' + DPlayBaseIE._PATH_REGEX
806 _TESTS = [{
807 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family',
808 'info_dict': {
809 'id': '1140794',
810 'display_id': 'property-brothers-forever-home/food-and-family',
811 'ext': 'mp4',
812 'title': 'Food and Family',
813 'description': 'The brothers help a Richmond family expand their single-level home.',
814 'duration': 2583.113,
815 'timestamp': 1609304400,
816 'upload_date': '20201230',
817 'creator': 'HGTV',
818 'series': 'Property Brothers: Forever Home',
819 'season_number': 1,
820 'episode_number': 1,
821 },
822 'skip': 'Available for Premium users',
823 }, {
824 'url': 'https://discoveryplus.com/ca/video/bering-sea-gold-discovery-ca/goldslingers',
825 'only_matching': True,
826 }]
827
828 _PRODUCT = 'dplus_us'
829 _DISCO_API_PARAMS = {
830 'disco_host': 'us1-prod-direct.discoveryplus.com',
831 'realm': 'go',
832 'country': 'us',
833 }
5118d2ec
AG
834
835
0bb5ac1a 836class DiscoveryPlusIndiaIE(DiscoveryPlusBaseIE):
5118d2ec
AG
837 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/videos?' + DPlayBaseIE._PATH_REGEX
838 _TESTS = [{
839 'url': 'https://www.discoveryplus.in/videos/how-do-they-do-it/fugu-and-more?seasonId=8&type=EPISODE',
840 'info_dict': {
841 'id': '27104',
842 'ext': 'mp4',
843 'display_id': 'how-do-they-do-it/fugu-and-more',
844 'title': 'Fugu and More',
845 'description': 'The Japanese catch, prepare and eat the deadliest fish on the planet.',
0bb5ac1a 846 'duration': 1319.32,
5118d2ec
AG
847 'timestamp': 1582309800,
848 'upload_date': '20200221',
849 'series': 'How Do They Do It?',
850 'season_number': 8,
851 'episode_number': 2,
852 'creator': 'Discovery Channel',
0bb5ac1a 853 'thumbnail': r're:https://.+\.jpeg',
854 'episode': 'Episode 2',
855 'season': 'Season 8',
856 'tags': [],
5118d2ec
AG
857 },
858 'params': {
859 'skip_download': True,
860 }
861 }]
862
0bb5ac1a 863 _PRODUCT = 'dplus-india'
864 _DISCO_API_PARAMS = {
865 'disco_host': 'ap2-prod-direct.discoveryplus.in',
866 'realm': 'dplusindia',
867 'country': 'in',
868 'domain': 'https://www.discoveryplus.in/',
869 }
870
5118d2ec
AG
871 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
872 headers.update({
873 'x-disco-params': 'realm=%s' % realm,
0bb5ac1a 874 'x-disco-client': f'WEB:UNKNOWN:{self._PRODUCT}:17.0.0',
5118d2ec
AG
875 'Authorization': self._get_auth(disco_base, display_id, realm),
876 })
877
5118d2ec 878
90d2da31 879class DiscoveryNetworksDeIE(DiscoveryPlusBaseIE):
5118d2ec
AG
880 _VALID_URL = r'https?://(?:www\.)?(?P<domain>(?:tlc|dmax)\.de|dplay\.co\.uk)/(?:programme|show|sendungen)/(?P<programme>[^/]+)/(?:video/)?(?P<alternate_id>[^/]+)'
881
882 _TESTS = [{
90d2da31 883 'url': 'https://dmax.de/sendungen/goldrausch-in-australien/german-gold',
884 'info_dict': {
885 'id': '4756322',
886 'ext': 'mp4',
887 'title': 'German Gold',
888 'description': 'md5:f3073306553a8d9b40e6ac4cdbf09fc6',
889 'display_id': 'goldrausch-in-australien/german-gold',
890 'episode': 'Episode 1',
891 'episode_number': 1,
892 'season': 'Season 5',
893 'season_number': 5,
894 'series': 'Goldrausch in Australien',
895 'duration': 2648.0,
896 'upload_date': '20230517',
897 'timestamp': 1684357500,
898 'creators': ['DMAX'],
899 'thumbnail': 'https://eu1-prod-images.disco-api.com/2023/05/09/f72fb510-7992-3b12-af7f-f16a2c22d1e3.jpeg',
900 'tags': ['schatzsucher', 'schatz', 'nugget', 'bodenschätze', 'down under', 'australien', 'goldrausch'],
901 },
902 'params': {'skip_download': 'm3u8'},
903 }, {
5118d2ec
AG
904 'url': 'https://www.tlc.de/programme/breaking-amish/video/die-welt-da-drauen/DCB331270001100',
905 'info_dict': {
906 'id': '78867',
907 'ext': 'mp4',
908 'title': 'Die Welt da draußen',
909 'description': 'md5:61033c12b73286e409d99a41742ef608',
910 'timestamp': 1554069600,
911 'upload_date': '20190331',
0bb5ac1a 912 'creator': 'TLC',
913 'season': 'Season 1',
914 'series': 'Breaking Amish',
915 'episode_number': 1,
916 'tags': ['new york', 'großstadt', 'amische', 'landleben', 'modern', 'infos', 'tradition', 'herausforderung'],
917 'display_id': 'breaking-amish/die-welt-da-drauen',
918 'episode': 'Episode 1',
919 'duration': 2625.024,
920 'season_number': 1,
921 'thumbnail': r're:https://.+\.jpg',
5118d2ec 922 },
90d2da31 923 'skip': '404 Not Found',
5118d2ec
AG
924 }, {
925 'url': 'https://www.dmax.de/programme/dmax-highlights/video/tuning-star-sidney-hoffmann-exklusiv-bei-dmax/191023082312316',
926 'only_matching': True,
927 }, {
928 'url': 'https://www.dplay.co.uk/show/ghost-adventures/video/hotel-leger-103620/EHD_280313B',
929 'only_matching': True,
930 }, {
931 'url': 'https://tlc.de/sendungen/breaking-amish/die-welt-da-drauen/',
932 'only_matching': True,
933 }]
934
935 def _real_extract(self, url):
936 domain, programme, alternate_id = self._match_valid_url(url).groups()
937 country = 'GB' if domain == 'dplay.co.uk' else 'DE'
938 realm = 'questuk' if country == 'GB' else domain.replace('.', '')
939 return self._get_disco_api_info(
90d2da31 940 url, f'{programme}/{alternate_id}', 'eu1-prod.disco-api.com', realm, country)
941
942 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
943 headers.update({
944 'x-disco-params': f'realm={realm}',
945 'x-disco-client': 'Alps:HyogaPlayer:0.0.0',
946 'Authorization': self._get_auth(disco_base, display_id, realm),
947 })
5118d2ec
AG
948
949
950class DiscoveryPlusShowBaseIE(DPlayBaseIE):
951
952 def _entries(self, show_name):
953 headers = {
954 'x-disco-client': self._X_CLIENT,
955 'x-disco-params': f'realm={self._REALM}',
956 'referer': self._DOMAIN,
957 'Authentication': self._get_auth(self._BASE_API, None, self._REALM),
958 }
959 show_json = self._download_json(
960 f'{self._BASE_API}cms/routes/{self._SHOW_STR}/{show_name}?include=default',
961 video_id=show_name, headers=headers)['included'][self._INDEX]['attributes']['component']
962 show_id = show_json['mandatoryParams'].split('=')[-1]
963 season_url = self._BASE_API + 'content/videos?sort=episodeNumber&filter[seasonNumber]={}&filter[show.id]={}&page[size]=100&page[number]={}'
964 for season in show_json['filters'][0]['options']:
965 season_id = season['id']
966 total_pages, page_num = 1, 0
967 while page_num < total_pages:
968 season_json = self._download_json(
969 season_url.format(season_id, show_id, str(page_num + 1)), show_name, headers=headers,
970 note='Downloading season %s JSON metadata%s' % (season_id, ' page %d' % page_num if page_num else ''))
971 if page_num == 0:
972 total_pages = try_get(season_json, lambda x: x['meta']['totalPages'], int) or 1
973 episodes_json = season_json['data']
974 for episode in episodes_json:
86f3d52f 975 video_path = episode['attributes']['path']
5118d2ec 976 yield self.url_result(
86f3d52f
AG
977 '%svideos/%s' % (self._DOMAIN, video_path),
978 ie=self._VIDEO_IE.ie_key(), video_id=episode.get('id') or video_path)
5118d2ec
AG
979 page_num += 1
980
981 def _real_extract(self, url):
982 show_name = self._match_valid_url(url).group('show_name')
983 return self.playlist_result(self._entries(show_name), playlist_id=show_name)
984
985
0bb5ac1a 986class DiscoveryPlusItalyIE(DiscoveryPlusBaseIE):
0f86a1cd 987 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.com/it/video' + DPlayBaseIE._PATH_REGEX
988 _TESTS = [{
989 'url': 'https://www.discoveryplus.com/it/video/i-signori-della-neve/stagione-2-episodio-1-i-preparativi',
990 'only_matching': True,
292fdad2
T
991 }, {
992 'url': 'https://www.discoveryplus.com/it/video/super-benny/trailer',
993 'only_matching': True,
0f86a1cd 994 }]
995
0bb5ac1a 996 _PRODUCT = 'dplus_us'
997 _DISCO_API_PARAMS = {
998 'disco_host': 'eu1-prod-direct.discoveryplus.com',
999 'realm': 'dplay',
1000 'country': 'it',
1001 }
0f86a1cd 1002
292fdad2
T
1003 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
1004 headers.update({
1005 'x-disco-params': 'realm=%s' % realm,
1006 'x-disco-client': f'WEB:UNKNOWN:{self._PRODUCT}:25.2.6',
1007 'Authorization': self._get_auth(disco_base, display_id, realm),
1008 })
1009
0f86a1cd 1010
5118d2ec
AG
1011class DiscoveryPlusItalyShowIE(DiscoveryPlusShowBaseIE):
1012 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.it/programmi/(?P<show_name>[^/]+)/?(?:[?#]|$)'
1013 _TESTS = [{
1014 'url': 'https://www.discoveryplus.it/programmi/deal-with-it-stai-al-gioco',
1015 'playlist_mincount': 168,
1016 'info_dict': {
1017 'id': 'deal-with-it-stai-al-gioco',
1018 },
1019 }]
1020
1021 _BASE_API = 'https://disco-api.discoveryplus.it/'
1022 _DOMAIN = 'https://www.discoveryplus.it/'
1023 _X_CLIENT = 'WEB:UNKNOWN:dplay-client:2.6.0'
1024 _REALM = 'dplayit'
1025 _SHOW_STR = 'programmi'
1026 _INDEX = 1
1027 _VIDEO_IE = DPlayIE
1028
1029
1030class DiscoveryPlusIndiaShowIE(DiscoveryPlusShowBaseIE):
1031 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/show/(?P<show_name>[^/]+)/?(?:[?#]|$)'
1032 _TESTS = [{
1033 'url': 'https://www.discoveryplus.in/show/how-do-they-do-it',
1034 'playlist_mincount': 140,
1035 'info_dict': {
1036 'id': 'how-do-they-do-it',
1037 },
1038 }]
1039
1040 _BASE_API = 'https://ap2-prod-direct.discoveryplus.in/'
1041 _DOMAIN = 'https://www.discoveryplus.in/'
1042 _X_CLIENT = 'WEB:UNKNOWN:dplus-india:prod'
1043 _REALM = 'dplusindia'
1044 _SHOW_STR = 'show'
1045 _INDEX = 4
1046 _VIDEO_IE = DiscoveryPlusIndiaIE
774aa09d 1047
1048
1049class GlobalCyclingNetworkPlusIE(DiscoveryPlusBaseIE):
1050 _VALID_URL = r'https?://plus\.globalcyclingnetwork\.com/watch/(?P<id>\d+)'
1051 _TESTS = [{
1052 'url': 'https://plus.globalcyclingnetwork.com/watch/1397691',
1053 'info_dict': {
1054 'id': '1397691',
1055 'ext': 'mp4',
1056 'title': 'The Athertons: Mountain Biking\'s Fastest Family',
1057 'description': 'md5:75a81937fcd8b989eec6083a709cd837',
1058 'thumbnail': 'https://us1-prod-images.disco-api.com/2021/03/04/eb9e3026-4849-3001-8281-9356466f0557.png',
1059 'series': 'gcn',
1060 'creator': 'Gcn',
1061 'upload_date': '20210309',
1062 'timestamp': 1615248000,
1063 'duration': 2531.0,
1064 'tags': [],
1065 },
1066 'skip': 'Subscription required',
1067 'params': {'skip_download': 'm3u8'},
1068 }]
1069
1070 _PRODUCT = 'web'
1071 _DISCO_API_PARAMS = {
1072 'disco_host': 'disco-api-prod.globalcyclingnetwork.com',
1073 'realm': 'gcn',
1074 'country': 'us',
1075 }
1076
1077 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
1078 headers.update({
1079 'x-disco-params': f'realm={realm}',
1080 'x-disco-client': f'WEB:UNKNOWN:{self._PRODUCT}:27.3.2',
1081 'Authorization': self._get_auth(disco_base, display_id, realm),
1082 })