2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_HTTPError
17 class DPlayIE(InfoExtractor):
18 _VALID_URL = r'''(?x)https?://
20 (?:www\.)?(?P<host>dplay\.(?P<country>dk|fi|jp|se|no))|
21 (?P<subdomain_country>es|it)\.dplay\.com
22 )/[^/]+/(?P<id>[^/]+/[^/?#]+)'''
25 # non geo restricted, via secure api, unsigned download hls URL
26 'url': 'https://www.dplay.se/videos/nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
29 'display_id': 'nugammalt-77-handelser-som-format-sverige/nugammalt-77-handelser-som-format-sverige-101',
31 'title': 'Svensken lär sig njuta av livet',
32 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
34 'timestamp': 1365453720,
35 'upload_date': '20130408',
37 'series': 'Nugammalt - 77 händelser som format Sverige',
42 'format': 'bestvideo',
43 'skip_download': True,
46 # geo restricted, via secure api, unsigned download hls URL
47 'url': 'http://www.dplay.dk/videoer/ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
50 'display_id': 'ted-bundy-mind-of-a-monster/ted-bundy-mind-of-a-monster',
52 'title': 'Ted Bundy: Mind Of A Monster',
53 'description': 'md5:8b780f6f18de4dae631668b8a9637995',
55 'timestamp': 1570694400,
56 'upload_date': '20191010',
57 'creator': 'ID - Investigation Discovery',
58 'series': 'Ted Bundy: Mind Of A Monster',
63 'format': 'bestvideo',
64 'skip_download': True,
68 'url': 'https://www.dplay.no/videoer/i-kongens-klr/sesong-1-episode-7',
71 'display_id': 'i-kongens-klr/sesong-1-episode-7',
74 'description': 'md5:e3e1411b2b9aebeea36a6ec5d50c60cf',
76 'timestamp': 1516726800,
77 'upload_date': '20180123',
78 'series': 'I kongens klær',
83 'format': 'bestvideo',
84 'skip_download': True,
86 'skip': 'Available for Premium users',
88 'url': 'http://it.dplay.com/nove/biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij/',
89 'md5': '2b808ffb00fc47b884a172ca5d13053c',
92 'display_id': 'biografie-imbarazzanti/luigi-di-maio-la-psicosi-di-stanislawskij',
94 'title': 'Luigi Di Maio: la psicosi di Stanislawskij',
95 'description': 'md5:3c7a4303aef85868f867a26f5cc14813',
96 'thumbnail': r're:^https?://.*\.jpe?g',
97 'upload_date': '20160524',
98 'timestamp': 1464076800,
99 'series': 'Biografie imbarazzanti',
101 'episode': 'Episode 1',
105 'url': 'https://es.dplay.com/dmax/la-fiebre-del-oro/temporada-8-episodio-1/',
108 'display_id': 'la-fiebre-del-oro/temporada-8-episodio-1',
110 'title': 'Episodio 1',
111 'description': 'md5:b9dcff2071086e003737485210675f69',
112 'thumbnail': r're:^https?://.*\.png',
113 'upload_date': '20180709',
114 'timestamp': 1531173540,
115 'series': 'La fiebre del oro',
117 'episode': 'Episode 1',
121 'skip_download': True,
124 'url': 'https://www.dplay.fi/videot/shifting-gears-with-aaron-kaufman/episode-16',
125 'only_matching': True,
127 'url': 'https://www.dplay.jp/video/gold-rush/24086',
128 'only_matching': True,
131 def _get_disco_api_info(self, url, display_id, disco_host, realm, country):
132 geo_countries = [country.upper()]
133 self._initialize_geo_bypass({
134 'countries': geo_countries,
136 disco_base = 'https://%s/' % disco_host
137 token = self._download_json(
138 disco_base + 'token', display_id, 'Downloading token',
141 })['data']['attributes']['token']
144 'Authorization': 'Bearer ' + token,
146 video = self._download_json(
147 disco_base + 'content/videos/' + display_id, display_id,
148 headers=headers, query={
149 'include': 'images,primaryChannel,show,tags'
151 video_id = video['data']['id']
152 info = video['data']['attributes']
153 title = info['name'].strip()
156 streaming = self._download_json(
157 disco_base + 'playback/videoPlaybackInfo/' + video_id,
158 display_id, headers=headers)['data']['attributes']['streaming']
159 except ExtractorError as e:
160 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
161 info = self._parse_json(e.cause.read().decode('utf-8'), display_id)
162 error = info['errors'][0]
163 error_code = error.get('code')
164 if error_code == 'access.denied.geoblocked':
165 self.raise_geo_restricted(countries=geo_countries)
166 elif error_code == 'access.denied.missingpackage':
167 self.raise_login_required()
168 raise ExtractorError(info['errors'][0]['detail'], expected=True)
170 for format_id, format_dict in streaming.items():
171 if not isinstance(format_dict, dict):
173 format_url = format_dict.get('url')
176 ext = determine_ext(format_url)
177 if format_id == 'dash' or ext == 'mpd':
178 formats.extend(self._extract_mpd_formats(
179 format_url, display_id, mpd_id='dash', fatal=False))
180 elif format_id == 'hls' or ext == 'm3u8':
181 formats.extend(self._extract_m3u8_formats(
182 format_url, display_id, 'mp4',
183 entry_protocol='m3u8_native', m3u8_id='hls',
188 'format_id': format_id,
190 self._sort_formats(formats)
192 creator = series = None
195 included = video.get('included') or []
196 if isinstance(included, list):
198 attributes = e.get('attributes')
201 e_type = e.get('type')
202 if e_type == 'channel':
203 creator = attributes.get('name')
204 elif e_type == 'image':
205 src = attributes.get('src')
209 'width': int_or_none(attributes.get('width')),
210 'height': int_or_none(attributes.get('height')),
213 series = attributes.get('name')
214 elif e_type == 'tag':
215 name = attributes.get('name')
221 'display_id': display_id,
223 'description': info.get('description'),
224 'duration': float_or_none(info.get('videoDuration'), 1000),
225 'timestamp': unified_timestamp(info.get('publishStart')),
227 'season_number': int_or_none(info.get('seasonNumber')),
228 'episode_number': int_or_none(info.get('episodeNumber')),
229 'age_limit': int_or_none(info.get('minimum_age')),
232 'thumbnails': thumbnails,
236 def _real_extract(self, url):
237 mobj = re.match(self._VALID_URL, url)
238 display_id = mobj.group('id')
239 domain = mobj.group('domain').lstrip('www.')
240 country = mobj.group('country') or mobj.group('subdomain_country')
241 host = 'disco-api.' + domain if domain.startswith('dplay.') else 'eu2-prod.disco-api.com'
242 return self._get_disco_api_info(
243 url, display_id, host, 'dplay' + country, country)