]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dplay.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_HTTPError
19 class DPlayIE(InfoExtractor
):
20 _PATH_REGEX
= r
'/(?P<id>[^/]+/[^/?#]+)'
21 _VALID_URL
= r
'''(?x)https?://
25 play\.(?P<country>dk|fi|jp|se|no)|
26 iscoveryplus\.(?P<plus_country>dk|es|fi|it|se|no)
29 (?P<subdomain_country>es|it)\.dplay\.com
30 )/[^/]+''' + _PATH_REGEX
33 # non geo restricted, via secure api, unsigned download hls URL
34 'url': 'https://www.dplay.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
37 'display_id': 'nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
39 'title': 'Svensken lär sig njuta av livet',
40 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
42 'timestamp': 1365453720,
43 'upload_date': '20130408',
45 'series': 'Nugammalt - 77 händelser som format Sverige',
50 'format': 'bestvideo',
51 'skip_download': True,
54 # geo restricted, via secure api, unsigned download hls URL
55 'url': 'http://www.dplay.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
58 'display_id': 'ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
60 'title': 'Ted Bundy: Mind Of A Monster',
61 'description': 'md5:8b780f6f18de4dae631668b8a9637995',
63 'timestamp': 1570694400,
64 'upload_date': '20191010',
65 'creator': 'ID - Investigation Discovery',
66 'series': 'Ted Bundy: Mind Of A Monster',
71 'format': 'bestvideo',
72 'skip_download': True,
76 'url': 'https://www.dplay.no/videoer/i-kongens-klr/sesong-1-episode-7',
79 'display_id': 'i-kongens-klr/sesong-1-episode-7',
82 'description': 'md5:e3e1411b2b9aebeea36a6ec5d50c60cf',
84 'timestamp': 1516726800,
85 'upload_date': '20180123',
86 'series': 'I kongens klær',
91 'format': 'bestvideo',
92 'skip_download': True,
94 'skip': 'Available for Premium users',
96 'url': 'http://it.dplay.com/nove/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij/',
97 'md5': '2b808ffb00fc47b884a172ca5d13053c',
100 'display_id': 'biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
102 'title': 'Luigi Di Maio: la psicosi di Stanislawskij',
103 'description': 'md5:3c7a4303aef85868f867a26f5cc14813',
104 'thumbnail': r
're:^https?://.*\.jpe?g',
105 'upload_date': '20160524',
106 'timestamp': 1464076800,
107 'series': 'Biografie imbarazzanti',
109 'episode': 'Episode 1',
113 'url': 'https://es.dplay.com/dmax/la-fiebre-del-oro/temporada-8-episodio-1/',
116 'display_id': 'la-fiebre-del-oro/temporada-8-episodio-1',
118 'title': 'Episodio 1',
119 'description': 'md5:b9dcff2071086e003737485210675f69',
120 'thumbnail': r
're:^https?://.*\.png',
121 'upload_date': '20180709',
122 'timestamp': 1531173540,
123 'series': 'La fiebre del oro',
125 'episode': 'Episode 1',
129 'skip_download': True,
132 'url': 'https://www.dplay.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
133 'only_matching': True,
135 'url': 'https://www.dplay.jp/video/gold-rush/24086',
136 'only_matching': True,
138 'url': 'https://www.discoveryplus.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
139 'only_matching': True,
141 'url': 'https://www.discoveryplus.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
142 'only_matching': True,
144 'url': 'https://www.discoveryplus.no/videoer/i-kongens-klr/sesong-1-episode-7',
145 'only_matching': True,
147 'url': 'https://www.discoveryplus.it/videos/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
148 'only_matching': True,
150 'url': 'https://www.discoveryplus.es/videos/la-fiebre-del-oro/temporada-8-episodio-1',
151 'only_matching': True,
153 'url': 'https://www.discoveryplus.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
154 'only_matching': True,
157 def _process_errors(self
, e
, geo_countries
):
158 info
= self
._parse
_json
(e
.cause
.read().decode('utf-8'), None)
159 error
= info
['errors'][0]
160 error_code
= error
.get('code')
161 if error_code
== 'access.denied.geoblocked':
162 self
.raise_geo_restricted(countries
=geo_countries
)
163 elif error_code
in ('access.denied.missingpackage', 'invalid.token'):
164 raise ExtractorError(
165 'This video is only available for registered users. You may want to use --cookies.', expected
=True)
166 raise ExtractorError(info
['errors'][0]['detail'], expected
=True)
168 def _update_disco_api_headers(self
, headers
, disco_base
, display_id
, realm
):
169 headers
['Authorization'] = 'Bearer ' + self
._download
_json
(
170 disco_base
+ 'token', display_id
, 'Downloading token',
173 })['data']['attributes']['token']
175 def _download_video_playback_info(self
, disco_base
, video_id
, headers
):
176 streaming
= self
._download
_json
(
177 disco_base
+ 'playback/videoPlaybackInfo/' + video_id
,
178 video_id
, headers
=headers
)['data']['attributes']['streaming']
180 for format_id
, format_dict
in streaming
.items():
181 streaming_list
.append({
183 'url': format_dict
.get('url'),
185 return streaming_list
187 def _get_disco_api_info(self
, url
, display_id
, disco_host
, realm
, country
):
188 geo_countries
= [country
.upper()]
189 self
._initialize
_geo
_bypass
({
190 'countries': geo_countries
,
192 disco_base
= 'https://%s/' % disco_host
196 self
._update
_disco
_api
_headers
(headers
, disco_base
, display_id
, realm
)
198 video
= self
._download
_json
(
199 disco_base
+ 'content/videos/' + display_id
, display_id
,
200 headers
=headers
, query
={
201 'fields[channel]': 'name',
202 'fields[image]': 'height,src,width',
203 'fields[show]': 'name',
204 'fields[tag]': 'name',
205 'fields[video]': 'description,episodeNumber,name,publishStart,seasonNumber,videoDuration',
206 'include': 'images,primaryChannel,show,tags'
208 except ExtractorError
as e
:
209 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 400:
210 self
._process
_errors
(e
, geo_countries
)
212 video_id
= video
['data']['id']
213 info
= video
['data']['attributes']
214 title
= info
['name'].strip()
217 streaming
= self
._download
_video
_playback
_info
(
218 disco_base
, video_id
, headers
)
219 except ExtractorError
as e
:
220 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
221 self
._process
_errors
(e
, geo_countries
)
223 for format_dict
in streaming
:
224 if not isinstance(format_dict
, dict):
226 format_url
= format_dict
.get('url')
229 format_id
= format_dict
.get('type')
230 ext
= determine_ext(format_url
)
231 if format_id
== 'dash' or ext
== 'mpd':
232 formats
.extend(self
._extract
_mpd
_formats
(
233 format_url
, display_id
, mpd_id
='dash', fatal
=False))
234 elif format_id
== 'hls' or ext
== 'm3u8':
235 formats
.extend(self
._extract
_m
3u8_formats
(
236 format_url
, display_id
, 'mp4',
237 entry_protocol
='m3u8_native', m3u8_id
='hls',
242 'format_id': format_id
,
244 self
._sort
_formats
(formats
)
246 creator
= series
= None
249 included
= video
.get('included') or []
250 if isinstance(included
, list):
252 attributes
= e
.get('attributes')
255 e_type
= e
.get('type')
256 if e_type
== 'channel':
257 creator
= attributes
.get('name')
258 elif e_type
== 'image':
259 src
= attributes
.get('src')
263 'width': int_or_none(attributes
.get('width')),
264 'height': int_or_none(attributes
.get('height')),
267 series
= attributes
.get('name')
268 elif e_type
== 'tag':
269 name
= attributes
.get('name')
275 'display_id': display_id
,
277 'description': strip_or_none(info
.get('description')),
278 'duration': float_or_none(info
.get('videoDuration'), 1000),
279 'timestamp': unified_timestamp(info
.get('publishStart')),
281 'season_number': int_or_none(info
.get('seasonNumber')),
282 'episode_number': int_or_none(info
.get('episodeNumber')),
285 'thumbnails': thumbnails
,
289 def _real_extract(self
, url
):
290 mobj
= re
.match(self
._VALID
_URL
, url
)
291 display_id
= mobj
.group('id')
292 domain
= mobj
.group('domain').lstrip('www.')
293 country
= mobj
.group('country') or mobj
.group('subdomain_country') or mobj
.group('plus_country')
294 host
= 'disco-api.' + domain
if domain
[0] == 'd' else 'eu2-prod.disco-api.com'
295 return self
._get
_disco
_api
_info
(
296 url
, display_id
, host
, 'dplay' + country
, country
)
299 class DiscoveryPlusIE(DPlayIE
):
300 _VALID_URL
= r
'https?://(?:www\.)?discoveryplus\.com/video' + DPlayIE
._PATH
_REGEX
302 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family',
305 'display_id': 'property-brothers-forever-home/food-and-family',
307 'title': 'Food and Family',
308 'description': 'The brothers help a Richmond family expand their single-level home.',
309 'duration': 2583.113,
310 'timestamp': 1609304400,
311 'upload_date': '20201230',
313 'series': 'Property Brothers: Forever Home',
317 'skip': 'Available for Premium users',
320 def _update_disco_api_headers(self
, headers
, disco_base
, display_id
, realm
):
321 headers
['x-disco-client'] = 'WEB:UNKNOWN:dplus_us:15.0.0'
323 def _download_video_playback_info(self
, disco_base
, video_id
, headers
):
324 return self
._download
_json
(
325 disco_base
+ 'playback/v3/videoPlaybackInfo',
326 video_id
, headers
=headers
, data
=json
.dumps({
331 'wisteriaProperties': {
332 'platform': 'desktop',
333 'product': 'dplus_us',
335 }).encode('utf-8'))['data']['attributes']['streaming']
337 def _real_extract(self
, url
):
338 display_id
= self
._match
_id
(url
)
339 return self
._get
_disco
_api
_info
(
340 url
, display_id
, 'us1-prod-direct.discoveryplus.com', 'go', 'us')
343 class HGTVDeIE(DPlayIE
):
344 _VALID_URL
= r
'https?://de\.hgtv\.com/sendungen' + DPlayIE
._PATH
_REGEX
346 'url': 'https://de.hgtv.com/sendungen/tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette/',
349 'display_id': 'tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette',
351 'title': 'Wer braucht schon eine Toilette',
352 'description': 'md5:05b40a27e7aed2c9172de34d459134e2',
353 'duration': 1177.024,
354 'timestamp': 1595705400,
355 'upload_date': '20200725',
357 'series': 'Tiny House - klein, aber oho',
362 'format': 'bestvideo',
366 def _real_extract(self
, url
):
367 display_id
= self
._match
_id
(url
)
368 return self
._get
_disco
_api
_info
(
369 url
, display_id
, 'eu1-prod.disco-api.com', 'hgtv', 'de')