]>
Commit | Line | Data |
---|---|---|
940b606a | 1 | # coding: utf-8 |
4cd759f7 JMF |
2 | from __future__ import unicode_literals |
3 | ||
bc2ca1bb | 4 | import json |
940b606a | 5 | import re |
4cd759f7 JMF |
6 | |
7 | from .common import InfoExtractor | |
0b98f3a7 | 8 | from ..compat import compat_HTTPError |
5448b781 | 9 | from ..utils import ( |
864a4576 | 10 | determine_ext, |
0cf2352e | 11 | ExtractorError, |
864a4576 | 12 | float_or_none, |
5448b781 | 13 | int_or_none, |
bc2ca1bb | 14 | strip_or_none, |
864a4576 | 15 | unified_timestamp, |
5448b781 | 16 | ) |
940b606a | 17 | |
4cd759f7 JMF |
18 | |
19 | class DPlayIE(InfoExtractor): | |
bc2ca1bb | 20 | _PATH_REGEX = r'/(?P<id>[^/]+/[^/?#]+)' |
0b98f3a7 RA |
21 | _VALID_URL = r'''(?x)https?:// |
22 | (?P<domain> | |
00dd0cd5 | 23 | (?:www\.)?(?P<host>d |
24 | (?: | |
25 | play\.(?P<country>dk|fi|jp|se|no)| | |
26 | iscoveryplus\.(?P<plus_country>dk|es|fi|it|se|no) | |
27 | ) | |
28 | )| | |
0b98f3a7 | 29 | (?P<subdomain_country>es|it)\.dplay\.com |
bc2ca1bb | 30 | )/[^/]+''' + _PATH_REGEX |
95050537 | 31 | |
940b606a | 32 | _TESTS = [{ |
5448b781 | 33 | # non geo restricted, via secure api, unsigned download hls URL |
0b98f3a7 | 34 | 'url': 'https://www.dplay.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101', |
940b606a | 35 | 'info_dict': { |
0b98f3a7 RA |
36 | 'id': '13628', |
37 | 'display_id': 'nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101', | |
5448b781 | 38 | 'ext': 'mp4', |
940b606a S |
39 | 'title': 'Svensken lär sig njuta av livet', |
40 | 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8', | |
0b98f3a7 RA |
41 | 'duration': 2649.856, |
42 | 'timestamp': 1365453720, | |
940b606a | 43 | 'upload_date': '20130408', |
0b98f3a7 | 44 | 'creator': 'Kanal 5', |
940b606a S |
45 | 'series': 'Nugammalt - 77 händelser som format Sverige', |
46 | 'season_number': 1, | |
47 | 'episode_number': 1, | |
0b98f3a7 RA |
48 | }, |
49 | 'params': { | |
50 | 'format': 'bestvideo', | |
51 | 'skip_download': True, | |
95050537 | 52 | }, |
940b606a | 53 | }, { |
5448b781 | 54 | # geo restricted, via secure api, unsigned download hls URL |
0b98f3a7 | 55 | 'url': 'http://www.dplay.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster', |
940b606a | 56 | 'info_dict': { |
0b98f3a7 RA |
57 | 'id': '104465', |
58 | 'display_id': 'ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster', | |
5448b781 | 59 | 'ext': 'mp4', |
0b98f3a7 RA |
60 | 'title': 'Ted Bundy: Mind Of A Monster', |
61 | 'description': 'md5:8b780f6f18de4dae631668b8a9637995', | |
62 | 'duration': 5290.027, | |
63 | 'timestamp': 1570694400, | |
64 | 'upload_date': '20191010', | |
65 | 'creator': 'ID - Investigation Discovery', | |
66 | 'series': 'Ted Bundy: Mind Of A Monster', | |
67 | 'season_number': 1, | |
68 | 'episode_number': 1, | |
69 | }, | |
70 | 'params': { | |
71 | 'format': 'bestvideo', | |
72 | 'skip_download': True, | |
940b606a | 73 | }, |
864a4576 S |
74 | }, { |
75 | # disco-api | |
76 | 'url': 'https://www.dplay.no/videoer/i-kongens-klr/sesong-1-episode-7', | |
77 | 'info_dict': { | |
78 | 'id': '40206', | |
79 | 'display_id': 'i-kongens-klr/sesong-1-episode-7', | |
80 | 'ext': 'mp4', | |
81 | 'title': 'Episode 7', | |
82 | 'description': 'md5:e3e1411b2b9aebeea36a6ec5d50c60cf', | |
83 | 'duration': 2611.16, | |
84 | 'timestamp': 1516726800, | |
85 | 'upload_date': '20180123', | |
86 | 'series': 'I kongens klær', | |
87 | 'season_number': 1, | |
88 | 'episode_number': 7, | |
89 | }, | |
90 | 'params': { | |
91 | 'format': 'bestvideo', | |
92 | 'skip_download': True, | |
93 | }, | |
0b98f3a7 | 94 | 'skip': 'Available for Premium users', |
a0ee342b | 95 | }, { |
0b98f3a7 RA |
96 | 'url': 'http://it.dplay.com/nove/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij/', |
97 | 'md5': '2b808ffb00fc47b884a172ca5d13053c', | |
98 | 'info_dict': { | |
99 | 'id': '6918', | |
100 | 'display_id': 'biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij', | |
101 | 'ext': 'mp4', | |
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', | |
108 | 'season_number': 1, | |
109 | 'episode': 'Episode 1', | |
110 | 'episode_number': 1, | |
111 | }, | |
112 | }, { | |
113 | 'url': 'https://es.dplay.com/dmax/la-fiebre-del-oro/temporada-8-episodio-1/', | |
114 | 'info_dict': { | |
115 | 'id': '21652', | |
116 | 'display_id': 'la-fiebre-del-oro/temporada-8-episodio-1', | |
117 | 'ext': 'mp4', | |
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', | |
124 | 'season_number': 8, | |
125 | 'episode': 'Episode 1', | |
126 | 'episode_number': 1, | |
127 | }, | |
128 | 'params': { | |
129 | 'skip_download': True, | |
130 | }, | |
131 | }, { | |
132 | 'url': 'https://www.dplay.fi/videot/shifting-gears-with-aaron-kaufman/episode-16', | |
a0ee342b | 133 | 'only_matching': True, |
d6b15291 | 134 | }, { |
0b98f3a7 | 135 | 'url': 'https://www.dplay.jp/video/gold-rush/24086', |
d6b15291 | 136 | 'only_matching': True, |
00dd0cd5 | 137 | }, { |
138 | 'url': 'https://www.discoveryplus.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101', | |
139 | 'only_matching': True, | |
140 | }, { | |
141 | 'url': 'https://www.discoveryplus.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster', | |
142 | 'only_matching': True, | |
143 | }, { | |
144 | 'url': 'https://www.discoveryplus.no/videoer/i-kongens-klr/sesong-1-episode-7', | |
145 | 'only_matching': True, | |
146 | }, { | |
147 | 'url': 'https://www.discoveryplus.it/videos/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij', | |
148 | 'only_matching': True, | |
149 | }, { | |
150 | 'url': 'https://www.discoveryplus.es/videos/la-fiebre-del-oro/temporada-8-episodio-1', | |
151 | 'only_matching': True, | |
152 | }, { | |
153 | 'url': 'https://www.discoveryplus.fi/videot/shifting-gears-with-aaron-kaufman/episode-16', | |
154 | 'only_matching': True, | |
940b606a | 155 | }] |
4cd759f7 | 156 | |
bc2ca1bb | 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) | |
167 | ||
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', | |
171 | query={ | |
172 | 'realm': realm, | |
173 | })['data']['attributes']['token'] | |
174 | ||
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'] | |
179 | streaming_list = [] | |
180 | for format_id, format_dict in streaming.items(): | |
181 | streaming_list.append({ | |
182 | 'type': format_id, | |
183 | 'url': format_dict.get('url'), | |
184 | }) | |
185 | return streaming_list | |
186 | ||
0b98f3a7 RA |
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, | |
191 | }) | |
192 | disco_base = 'https://%s/' % disco_host | |
aa560616 RA |
193 | headers = { |
194 | 'Referer': url, | |
aa560616 | 195 | } |
bc2ca1bb | 196 | self._update_disco_api_headers(headers, disco_base, display_id, realm) |
197 | try: | |
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' | |
207 | }) | |
208 | except ExtractorError as e: | |
209 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400: | |
210 | self._process_errors(e, geo_countries) | |
211 | raise | |
aa560616 RA |
212 | video_id = video['data']['id'] |
213 | info = video['data']['attributes'] | |
0b98f3a7 | 214 | title = info['name'].strip() |
aa560616 | 215 | formats = [] |
0b98f3a7 | 216 | try: |
bc2ca1bb | 217 | streaming = self._download_video_playback_info( |
218 | disco_base, video_id, headers) | |
0b98f3a7 RA |
219 | except ExtractorError as e: |
220 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
bc2ca1bb | 221 | self._process_errors(e, geo_countries) |
0b98f3a7 | 222 | raise |
bc2ca1bb | 223 | for format_dict in streaming: |
aa560616 RA |
224 | if not isinstance(format_dict, dict): |
225 | continue | |
226 | format_url = format_dict.get('url') | |
227 | if not format_url: | |
228 | continue | |
bc2ca1bb | 229 | format_id = format_dict.get('type') |
aa560616 RA |
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_m3u8_formats( | |
236 | format_url, display_id, 'mp4', | |
237 | entry_protocol='m3u8_native', m3u8_id='hls', | |
238 | fatal=False)) | |
239 | else: | |
240 | formats.append({ | |
241 | 'url': format_url, | |
242 | 'format_id': format_id, | |
243 | }) | |
244 | self._sort_formats(formats) | |
245 | ||
0b98f3a7 RA |
246 | creator = series = None |
247 | tags = [] | |
248 | thumbnails = [] | |
249 | included = video.get('included') or [] | |
250 | if isinstance(included, list): | |
251 | for e in included: | |
252 | attributes = e.get('attributes') | |
253 | if not attributes: | |
254 | continue | |
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') | |
260 | if src: | |
261 | thumbnails.append({ | |
262 | 'url': src, | |
263 | 'width': int_or_none(attributes.get('width')), | |
264 | 'height': int_or_none(attributes.get('height')), | |
265 | }) | |
266 | if e_type == 'show': | |
267 | series = attributes.get('name') | |
268 | elif e_type == 'tag': | |
269 | name = attributes.get('name') | |
270 | if name: | |
271 | tags.append(name) | |
aa560616 RA |
272 | |
273 | return { | |
274 | 'id': video_id, | |
275 | 'display_id': display_id, | |
276 | 'title': title, | |
bc2ca1bb | 277 | 'description': strip_or_none(info.get('description')), |
0b98f3a7 | 278 | 'duration': float_or_none(info.get('videoDuration'), 1000), |
aa560616 RA |
279 | 'timestamp': unified_timestamp(info.get('publishStart')), |
280 | 'series': series, | |
281 | 'season_number': int_or_none(info.get('seasonNumber')), | |
282 | 'episode_number': int_or_none(info.get('episodeNumber')), | |
0b98f3a7 RA |
283 | 'creator': creator, |
284 | 'tags': tags, | |
285 | 'thumbnails': thumbnails, | |
aa560616 RA |
286 | 'formats': formats, |
287 | } | |
288 | ||
4cd759f7 | 289 | def _real_extract(self, url): |
940b606a S |
290 | mobj = re.match(self._VALID_URL, url) |
291 | display_id = mobj.group('id') | |
0b98f3a7 | 292 | domain = mobj.group('domain').lstrip('www.') |
00dd0cd5 | 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' | |
0b98f3a7 RA |
295 | return self._get_disco_api_info( |
296 | url, display_id, host, 'dplay' + country, country) | |
bc2ca1bb | 297 | |
298 | ||
45d1f157 S |
299 | class HGTVDeIE(DPlayIE): |
300 | _VALID_URL = r'https?://de\.hgtv\.com/sendungen' + DPlayIE._PATH_REGEX | |
301 | _TESTS = [{ | |
302 | 'url': 'https://de.hgtv.com/sendungen/tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette/', | |
303 | 'info_dict': { | |
304 | 'id': '151205', | |
305 | 'display_id': 'tiny-house-klein-aber-oho/wer-braucht-schon-eine-toilette', | |
306 | 'ext': 'mp4', | |
307 | 'title': 'Wer braucht schon eine Toilette', | |
308 | 'description': 'md5:05b40a27e7aed2c9172de34d459134e2', | |
309 | 'duration': 1177.024, | |
310 | 'timestamp': 1595705400, | |
311 | 'upload_date': '20200725', | |
312 | 'creator': 'HGTV', | |
313 | 'series': 'Tiny House - klein, aber oho', | |
314 | 'season_number': 3, | |
315 | 'episode_number': 3, | |
316 | }, | |
317 | 'params': { | |
318 | 'format': 'bestvideo', | |
319 | }, | |
320 | }] | |
321 | ||
322 | def _real_extract(self, url): | |
323 | display_id = self._match_id(url) | |
324 | return self._get_disco_api_info( | |
325 | url, display_id, 'eu1-prod.disco-api.com', 'hgtv', 'de') | |
326 | ||
327 | ||
bc2ca1bb | 328 | class DiscoveryPlusIE(DPlayIE): |
329 | _VALID_URL = r'https?://(?:www\.)?discoveryplus\.com/video' + DPlayIE._PATH_REGEX | |
330 | _TESTS = [{ | |
331 | 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family', | |
332 | 'info_dict': { | |
333 | 'id': '1140794', | |
334 | 'display_id': 'property-brothers-forever-home/food-and-family', | |
335 | 'ext': 'mp4', | |
336 | 'title': 'Food and Family', | |
337 | 'description': 'The brothers help a Richmond family expand their single-level home.', | |
338 | 'duration': 2583.113, | |
339 | 'timestamp': 1609304400, | |
340 | 'upload_date': '20201230', | |
341 | 'creator': 'HGTV', | |
342 | 'series': 'Property Brothers: Forever Home', | |
343 | 'season_number': 1, | |
344 | 'episode_number': 1, | |
345 | }, | |
346 | 'skip': 'Available for Premium users', | |
347 | }] | |
348 | ||
45d1f157 S |
349 | _PRODUCT = 'dplus_us' |
350 | _API_URL = 'us1-prod-direct.discoveryplus.com' | |
351 | ||
bc2ca1bb | 352 | def _update_disco_api_headers(self, headers, disco_base, display_id, realm): |
45d1f157 | 353 | headers['x-disco-client'] = f'WEB:UNKNOWN:{self._PRODUCT}:15.0.0' |
bc2ca1bb | 354 | |
355 | def _download_video_playback_info(self, disco_base, video_id, headers): | |
356 | return self._download_json( | |
357 | disco_base + 'playback/v3/videoPlaybackInfo', | |
358 | video_id, headers=headers, data=json.dumps({ | |
359 | 'deviceInfo': { | |
360 | 'adBlocker': False, | |
361 | }, | |
362 | 'videoId': video_id, | |
363 | 'wisteriaProperties': { | |
364 | 'platform': 'desktop', | |
45d1f157 | 365 | 'product': self._PRODUCT, |
bc2ca1bb | 366 | }, |
367 | }).encode('utf-8'))['data']['attributes']['streaming'] | |
368 | ||
369 | def _real_extract(self, url): | |
370 | display_id = self._match_id(url) | |
371 | return self._get_disco_api_info( | |
45d1f157 | 372 | url, display_id, self._API_URL, 'go', 'us') |
bc2ca1bb | 373 | |
374 | ||
45d1f157 S |
375 | class ScienceChannelIE(DiscoveryPlusIE): |
376 | _VALID_URL = r'https?://(?:www\.)?sciencechannel\.com/video' + DPlayIE._PATH_REGEX | |
bc2ca1bb | 377 | _TESTS = [{ |
45d1f157 | 378 | 'url': 'https://www.sciencechannel.com/video/strangest-things-science-atve-us/nazi-mystery-machine', |
bc2ca1bb | 379 | 'info_dict': { |
45d1f157 S |
380 | 'id': '2842849', |
381 | 'display_id': 'strangest-things-science-atve-us/nazi-mystery-machine', | |
bc2ca1bb | 382 | 'ext': 'mp4', |
45d1f157 S |
383 | 'title': 'Nazi Mystery Machine', |
384 | 'description': 'Experts investigate the secrets of a revolutionary encryption machine.', | |
385 | 'season_number': 1, | |
386 | 'episode_number': 1, | |
bc2ca1bb | 387 | }, |
45d1f157 | 388 | 'skip': 'Available for Premium users', |
bc2ca1bb | 389 | }] |
390 | ||
45d1f157 S |
391 | _PRODUCT = 'sci' |
392 | _API_URL = 'us1-prod-direct.sciencechannel.com' |