]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dplay.py
7a00db7b0fe2c0c80e3fd9137ea8b045ec2abd5f
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_HTTPError
20 class DPlayBaseIE(InfoExtractor
):
21 _PATH_REGEX
= r
'/(?P<id>[^/]+/[^/?#]+)'
22 _auth_token_cache
= {}
24 def _get_auth(self
, disco_base
, display_id
, realm
, needs_device_id
=True):
25 key
= (disco_base
, realm
)
26 st
= self
._get
_cookies
(disco_base
).get('st')
27 token
= (st
and st
.value
) or self
._auth
_token
_cache
.get(key
)
30 query
= {'realm': realm}
32 query
['deviceId'] = uuid
.uuid4().hex
33 token
= self
._download
_json
(
34 disco_base
+ 'token', display_id
, 'Downloading token',
35 query
=query
)['data']['attributes']['token']
37 # Save cache only if cookies are not being set
38 if not self
._get
_cookies
(disco_base
).get('st'):
39 self
._auth
_token
_cache
[key
] = token
41 return f
'Bearer {token}'
43 def _process_errors(self
, e
, geo_countries
):
44 info
= self
._parse
_json
(e
.cause
.read().decode('utf-8'), None)
45 error
= info
['errors'][0]
46 error_code
= error
.get('code')
47 if error_code
== 'access.denied.geoblocked':
48 self
.raise_geo_restricted(countries
=geo_countries
)
49 elif error_code
in ('access.denied.missingpackage', 'invalid.token'):
51 'This video is only available for registered users. You may want to use --cookies.', expected
=True)
52 raise ExtractorError(info
['errors'][0]['detail'], expected
=True)
54 def _update_disco_api_headers(self
, headers
, disco_base
, display_id
, realm
):
55 headers
['Authorization'] = self
._get
_auth
(disco_base
, display_id
, realm
, False)
57 def _download_video_playback_info(self
, disco_base
, video_id
, headers
):
58 streaming
= self
._download
_json
(
59 disco_base
+ 'playback/videoPlaybackInfo/' + video_id
,
60 video_id
, headers
=headers
)['data']['attributes']['streaming']
62 for format_id
, format_dict
in streaming
.items():
63 streaming_list
.append({
65 'url': format_dict
.get('url'),
69 def _get_disco_api_info(self
, url
, display_id
, disco_host
, realm
, country
, domain
=''):
70 geo_countries
= [country
.upper()]
71 self
._initialize
_geo
_bypass
({
72 'countries': geo_countries
,
74 disco_base
= 'https://%s/' % disco_host
78 self
._update
_disco
_api
_headers
(headers
, disco_base
, display_id
, realm
)
80 video
= self
._download
_json
(
81 disco_base
+ 'content/videos/' + display_id
, display_id
,
82 headers
=headers
, query
={
83 'fields[channel]': 'name',
84 'fields[image]': 'height,src,width',
85 'fields[show]': 'name',
86 'fields[tag]': 'name',
87 'fields[video]': 'description,episodeNumber,name,publishStart,seasonNumber,videoDuration',
88 'include': 'images,primaryChannel,show,tags'
90 except ExtractorError
as e
:
91 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 400:
92 self
._process
_errors
(e
, geo_countries
)
94 video_id
= video
['data']['id']
95 info
= video
['data']['attributes']
96 title
= info
['name'].strip()
100 streaming
= self
._download
_video
_playback
_info
(
101 disco_base
, video_id
, headers
)
102 except ExtractorError
as e
:
103 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
104 self
._process
_errors
(e
, geo_countries
)
106 for format_dict
in streaming
:
107 if not isinstance(format_dict
, dict):
109 format_url
= format_dict
.get('url')
112 format_id
= format_dict
.get('type')
113 ext
= determine_ext(format_url
)
114 if format_id
== 'dash' or ext
== 'mpd':
115 dash_fmts
, dash_subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
116 format_url
, display_id
, mpd_id
='dash', fatal
=False)
117 formats
.extend(dash_fmts
)
118 subtitles
= self
._merge
_subtitles
(subtitles
, dash_subs
)
119 elif format_id
== 'hls' or ext
== 'm3u8':
120 m3u8_fmts
, m3u8_subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
121 format_url
, display_id
, 'mp4',
122 entry_protocol
='m3u8_native', m3u8_id
='hls',
124 formats
.extend(m3u8_fmts
)
125 subtitles
= self
._merge
_subtitles
(subtitles
, m3u8_subs
)
129 'format_id': format_id
,
131 self
._sort
_formats
(formats
)
133 creator
= series
= None
136 included
= video
.get('included') or []
137 if isinstance(included
, list):
139 attributes
= e
.get('attributes')
142 e_type
= e
.get('type')
143 if e_type
== 'channel':
144 creator
= attributes
.get('name')
145 elif e_type
== 'image':
146 src
= attributes
.get('src')
150 'width': int_or_none(attributes
.get('width')),
151 'height': int_or_none(attributes
.get('height')),
154 series
= attributes
.get('name')
155 elif e_type
== 'tag':
156 name
= attributes
.get('name')
161 'display_id': display_id
,
163 'description': strip_or_none(info
.get('description')),
164 'duration': float_or_none(info
.get('videoDuration'), 1000),
165 'timestamp': unified_timestamp(info
.get('publishStart')),
167 'season_number': int_or_none(info
.get('seasonNumber')),
168 'episode_number': int_or_none(info
.get('episodeNumber')),
171 'thumbnails': thumbnails
,
173 'subtitles': subtitles
,
180 class DPlayIE(DPlayBaseIE
):
181 _VALID_URL
= r
'''(?x)https?://
185 play\.(?P<country>dk|fi|jp|se|no)|
186 iscoveryplus\.(?P<plus_country>dk|es|fi|it|se|no)
189 (?P<subdomain_country>es|it)\.dplay\.com
190 )/[^/]+''' + DPlayBaseIE
._PATH
_REGEX
193 # non geo restricted, via secure api, unsigned download hls URL
194 'url': 'https://www.dplay.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
197 'display_id': 'nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
199 'title': 'Svensken lär sig njuta av livet',
200 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
201 'duration': 2649.856,
202 'timestamp': 1365453720,
203 'upload_date': '20130408',
204 'creator': 'Kanal 5',
205 'series': 'Nugammalt - 77 händelser som format Sverige',
210 'skip_download': True,
213 # geo restricted, via secure api, unsigned download hls URL
214 'url': 'http://www.dplay.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
217 'display_id': 'ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
219 'title': 'Ted Bundy: Mind Of A Monster',
220 'description': 'md5:8b780f6f18de4dae631668b8a9637995',
221 'duration': 5290.027,
222 'timestamp': 1570694400,
223 'upload_date': '20191010',
224 'creator': 'ID - Investigation Discovery',
225 'series': 'Ted Bundy: Mind Of A Monster',
230 'skip_download': True,
234 'url': 'https://www.dplay.no/videoer/i-kongens-klr/sesong-1-episode-7',
237 'display_id': 'i-kongens-klr/sesong-1-episode-7',
239 'title': 'Episode 7',
240 'description': 'md5:e3e1411b2b9aebeea36a6ec5d50c60cf',
242 'timestamp': 1516726800,
243 'upload_date': '20180123',
244 'series': 'I kongens klær',
249 'skip_download': True,
251 'skip': 'Available for Premium users',
253 'url': 'http://it.dplay.com/nove/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij/',
254 'md5': '2b808ffb00fc47b884a172ca5d13053c',
257 'display_id': 'biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
259 'title': 'Luigi Di Maio: la psicosi di Stanislawskij',
260 'description': 'md5:3c7a4303aef85868f867a26f5cc14813',
261 'thumbnail': r
're:^https?://.*\.jpe?g',
262 'upload_date': '20160524',
263 'timestamp': 1464076800,
264 'series': 'Biografie imbarazzanti',
266 'episode': 'Episode 1',
270 'url': 'https://es.dplay.com/dmax/la-fiebre-del-oro/temporada-8-episodio-1/',
273 'display_id': 'la-fiebre-del-oro/temporada-8-episodio-1',
275 'title': 'Episodio 1',
276 'description': 'md5:b9dcff2071086e003737485210675f69',
277 'thumbnail': r
're:^https?://.*\.png',
278 'upload_date': '20180709',
279 'timestamp': 1531173540,
280 'series': 'La fiebre del oro',
282 'episode': 'Episode 1',
286 'skip_download': True,
289 'url': 'https://www.dplay.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
290 'only_matching': True,
292 'url': 'https://www.dplay.jp/video/gold-rush/24086',
293 'only_matching': True,
295 'url': 'https://www.discoveryplus.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
296 'only_matching': True,
298 'url': 'https://www.discoveryplus.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
299 'only_matching': True,
301 'url': 'https://www.discoveryplus.no/videoer/i-kongens-klr/sesong-1-episode-7',
302 'only_matching': True,
304 'url': 'https://www.discoveryplus.it/videos/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
305 'only_matching': True,
307 'url': 'https://www.discoveryplus.es/videos/la-fiebre-del-oro/temporada-8-episodio-1',
308 'only_matching': True,
310 'url': 'https://www.discoveryplus.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
311 'only_matching': True,
314 def _real_extract(self
, url
):
315 mobj
= self
._match
_valid
_url
(url
)
316 display_id
= mobj
.group('id')
317 domain
= mobj
.group('domain').lstrip('www.')
318 country
= mobj
.group('country') or mobj
.group('subdomain_country') or mobj
.group('plus_country')
319 host
= 'disco-api.' + domain
if domain
[0] == 'd' else 'eu2-prod.disco-api.com'
320 return self
._get
_disco
_api
_info
(
321 url
, display_id
, host
, 'dplay' + country
, country
, domain
)
324 class HGTVDeIE(DPlayBaseIE
):
325 _VALID_URL
= r
'https?://de\.hgtv\.com/sendungen' + DPlayBaseIE
._PATH
_REGEX
327 'url': 'https://de.hgtv.com/sendungen/tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette/',
330 'display_id': 'tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette',
332 'title': 'Wer braucht schon eine Toilette',
333 'description': 'md5:05b40a27e7aed2c9172de34d459134e2',
334 'duration': 1177.024,
335 'timestamp': 1595705400,
336 'upload_date': '20200725',
338 'series': 'Tiny House - klein, aber oho',
344 def _real_extract(self
, url
):
345 display_id
= self
._match
_id
(url
)
346 return self
._get
_disco
_api
_info
(
347 url
, display_id
, 'eu1-prod.disco-api.com', 'hgtv', 'de')
350 class DiscoveryPlusBaseIE(DPlayBaseIE
):
351 def _update_disco_api_headers(self
, headers
, disco_base
, display_id
, realm
):
352 headers
['x-disco-client'] = f
'WEB:UNKNOWN:{self._PRODUCT}:25.2.6'
354 def _download_video_playback_info(self
, disco_base
, video_id
, headers
):
355 return self
._download
_json
(
356 disco_base
+ 'playback/v3/videoPlaybackInfo',
357 video_id
, headers
=headers
, data
=json
.dumps({
362 'wisteriaProperties': {
363 'platform': 'desktop',
364 'product': self
._PRODUCT
,
366 }).encode('utf-8'))['data']['attributes']['streaming']
368 def _real_extract(self
, url
):
369 return self
._get
_disco
_api
_info
(url
, self
._match
_id
(url
), **self
._DISCO
_API
_PARAMS
)
372 class ScienceChannelIE(DiscoveryPlusBaseIE
):
373 _VALID_URL
= r
'https?://(?:www\.)?sciencechannel\.com/video' + DPlayBaseIE
._PATH
_REGEX
375 'url': 'https://www.sciencechannel.com/video/strangest-things-science-atve-us/nazi-mystery-machine',
378 'display_id': 'strangest-things-science-atve-us/nazi-mystery-machine',
380 'title': 'Nazi Mystery Machine',
381 'description': 'Experts investigate the secrets of a revolutionary encryption machine.',
385 'skip': 'Available for Premium users',
389 _DISCO_API_PARAMS
= {
390 'disco_host': 'us1-prod-direct.sciencechannel.com',
396 class DIYNetworkIE(DiscoveryPlusBaseIE
):
397 _VALID_URL
= r
'https?://(?:watch\.)?diynetwork\.com/video' + DPlayBaseIE
._PATH
_REGEX
399 'url': 'https://watch.diynetwork.com/video/pool-kings-diy-network/bringing-beach-life-to-texas',
402 'display_id': 'pool-kings-diy-network/bringing-beach-life-to-texas',
404 'title': 'Bringing Beach Life to Texas',
405 'description': 'The Pool Kings give a family a day at the beach in their own backyard.',
409 'skip': 'Available for Premium users',
413 _DISCO_API_PARAMS
= {
414 'disco_host': 'us1-prod-direct.watch.diynetwork.com',
420 class AnimalPlanetIE(DiscoveryPlusBaseIE
):
421 _VALID_URL
= r
'https?://(?:www\.)?animalplanet\.com/video' + DPlayBaseIE
._PATH
_REGEX
423 'url': 'https://www.animalplanet.com/video/north-woods-law-animal-planet/squirrel-showdown',
426 'display_id': 'north-woods-law-animal-planet/squirrel-showdown',
428 'title': 'Squirrel Showdown',
429 'description': 'A woman is suspected of being in possession of flying squirrel kits.',
431 'episode_number': 11,
433 'skip': 'Available for Premium users',
437 _DISCO_API_PARAMS
= {
438 'disco_host': 'us1-prod-direct.animalplanet.com',
444 class DiscoveryPlusIE(DiscoveryPlusBaseIE
):
445 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.com/(?!it/)(?:\w{2}/)?video' + DPlayBaseIE
._PATH
_REGEX
447 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family',
450 'display_id': 'property-brothers-forever-home/food-and-family',
452 'title': 'Food and Family',
453 'description': 'The brothers help a Richmond family expand their single-level home.',
454 'duration': 2583.113,
455 'timestamp': 1609304400,
456 'upload_date': '20201230',
458 'series': 'Property Brothers: Forever Home',
462 'skip': 'Available for Premium users',
464 'url': 'https://discoveryplus.com/ca/video/bering-sea-gold-discovery-ca/goldslingers',
465 'only_matching': True,
468 _PRODUCT
= 'dplus_us'
469 _DISCO_API_PARAMS
= {
470 'disco_host': 'us1-prod-direct.discoveryplus.com',
476 class DiscoveryPlusIndiaIE(DiscoveryPlusBaseIE
):
477 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.in/videos?' + DPlayBaseIE
._PATH
_REGEX
479 'url': 'https://www.discoveryplus.in/videos/how-do-they-do-it/fugu-and-more?seasonId=8&type=EPISODE',
483 'display_id': 'how-do-they-do-it/fugu-and-more',
484 'title': 'Fugu and More',
485 'description': 'The Japanese catch, prepare and eat the deadliest fish on the planet.',
487 'timestamp': 1582309800,
488 'upload_date': '20200221',
489 'series': 'How Do They Do It?',
492 'creator': 'Discovery Channel',
493 'thumbnail': r
're:https://.+\.jpeg',
494 'episode': 'Episode 2',
495 'season': 'Season 8',
499 'skip_download': True,
503 _PRODUCT
= 'dplus-india'
504 _DISCO_API_PARAMS
= {
505 'disco_host': 'ap2-prod-direct.discoveryplus.in',
506 'realm': 'dplusindia',
508 'domain': 'https://www.discoveryplus.in/',
511 def _update_disco_api_headers(self
, headers
, disco_base
, display_id
, realm
):
513 'x-disco-params': 'realm=%s' % realm
,
514 'x-disco-client': f
'WEB:UNKNOWN:{self._PRODUCT}:17.0.0',
515 'Authorization': self
._get
_auth
(disco_base
, display_id
, realm
),
519 class DiscoveryNetworksDeIE(DPlayBaseIE
):
520 _VALID_URL
= r
'https?://(?:www\.)?(?P<domain>(?:tlc|dmax)\.de|dplay\.co\.uk)/(?:programme|show|sendungen)/(?P<programme>[^/]+)/(?:video/)?(?P<alternate_id>[^/]+)'
523 'url': 'https://www.tlc.de/programme/breaking-amish/video/die-welt-da-drauen/DCB331270001100',
527 'title': 'Die Welt da draußen',
528 'description': 'md5:61033c12b73286e409d99a41742ef608',
529 'timestamp': 1554069600,
530 'upload_date': '20190331',
532 'season': 'Season 1',
533 'series': 'Breaking Amish',
535 'tags': ['new york', 'großstadt', 'amische', 'landleben', 'modern', 'infos', 'tradition', 'herausforderung'],
536 'display_id': 'breaking-amish/die-welt-da-drauen',
537 'episode': 'Episode 1',
538 'duration': 2625.024,
540 'thumbnail': r
're:https://.+\.jpg',
543 'skip_download': True,
546 'url': 'https://www.dmax.de/programme/dmax-highlights/video/tuning-star-sidney-hoffmann-exklusiv-bei-dmax/191023082312316',
547 'only_matching': True,
549 'url': 'https://www.dplay.co.uk/show/ghost-adventures/video/hotel-leger-103620/EHD_280313B',
550 'only_matching': True,
552 'url': 'https://tlc.de/sendungen/breaking-amish/die-welt-da-drauen/',
553 'only_matching': True,
556 def _real_extract(self
, url
):
557 domain
, programme
, alternate_id
= self
._match
_valid
_url
(url
).groups()
558 country
= 'GB' if domain
== 'dplay.co.uk' else 'DE'
559 realm
= 'questuk' if country
== 'GB' else domain
.replace('.', '')
560 return self
._get
_disco
_api
_info
(
561 url
, '%s/%s' % (programme
, alternate_id
),
562 'sonic-eu1-prod.disco-api.com', realm
, country
)
565 class DiscoveryPlusShowBaseIE(DPlayBaseIE
):
567 def _entries(self
, show_name
):
569 'x-disco-client': self
._X
_CLIENT
,
570 'x-disco-params': f
'realm={self._REALM}',
571 'referer': self
._DOMAIN
,
572 'Authentication': self
._get
_auth
(self
._BASE
_API
, None, self
._REALM
),
574 show_json
= self
._download
_json
(
575 f
'{self._BASE_API}cms/routes/{self._SHOW_STR}/{show_name}?include=default',
576 video_id
=show_name
, headers
=headers
)['included'][self
._INDEX
]['attributes']['component']
577 show_id
= show_json
['mandatoryParams'].split('=')[-1]
578 season_url
= self
._BASE
_API
+ 'content/videos?sort=episodeNumber&filter[seasonNumber]={}&filter[show.id]={}&page[size]=100&page[number]={}'
579 for season
in show_json
['filters'][0]['options']:
580 season_id
= season
['id']
581 total_pages
, page_num
= 1, 0
582 while page_num
< total_pages
:
583 season_json
= self
._download
_json
(
584 season_url
.format(season_id
, show_id
, str(page_num
+ 1)), show_name
, headers
=headers
,
585 note
='Downloading season %s JSON metadata%s' % (season_id
, ' page %d' % page_num
if page_num
else ''))
587 total_pages
= try_get(season_json
, lambda x
: x
['meta']['totalPages'], int) or 1
588 episodes_json
= season_json
['data']
589 for episode
in episodes_json
:
590 video_path
= episode
['attributes']['path']
591 yield self
.url_result(
592 '%svideos/%s' % (self
._DOMAIN
, video_path
),
593 ie
=self
._VIDEO
_IE
.ie_key(), video_id
=episode
.get('id') or video_path
)
596 def _real_extract(self
, url
):
597 show_name
= self
._match
_valid
_url
(url
).group('show_name')
598 return self
.playlist_result(self
._entries
(show_name
), playlist_id
=show_name
)
601 class DiscoveryPlusItalyIE(DiscoveryPlusBaseIE
):
602 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.com/it/video' + DPlayBaseIE
._PATH
_REGEX
604 'url': 'https://www.discoveryplus.com/it/video/i-signori-della-neve/stagione-2-episodio-1-i-preparativi',
605 'only_matching': True,
608 _PRODUCT
= 'dplus_us'
609 _DISCO_API_PARAMS
= {
610 'disco_host': 'eu1-prod-direct.discoveryplus.com',
616 class DiscoveryPlusItalyShowIE(DiscoveryPlusShowBaseIE
):
617 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.it/programmi/(?P<show_name>[^/]+)/?(?:[?#]|$)'
619 'url': 'https://www.discoveryplus.it/programmi/deal-with-it-stai-al-gioco',
620 'playlist_mincount': 168,
622 'id': 'deal-with-it-stai-al-gioco',
626 _BASE_API
= 'https://disco-api.discoveryplus.it/'
627 _DOMAIN
= 'https://www.discoveryplus.it/'
628 _X_CLIENT
= 'WEB:UNKNOWN:dplay-client:2.6.0'
630 _SHOW_STR
= 'programmi'
635 class DiscoveryPlusIndiaShowIE(DiscoveryPlusShowBaseIE
):
636 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.in/show/(?P<show_name>[^/]+)/?(?:[?#]|$)'
638 'url': 'https://www.discoveryplus.in/show/how-do-they-do-it',
639 'playlist_mincount': 140,
641 'id': 'how-do-they-do-it',
645 _BASE_API
= 'https://ap2-prod-direct.discoveryplus.in/'
646 _DOMAIN
= 'https://www.discoveryplus.in/'
647 _X_CLIENT
= 'WEB:UNKNOWN:dplus-india:prod'
648 _REALM
= 'dplusindia'
651 _VIDEO_IE
= DiscoveryPlusIndiaIE