6 from .common
import InfoExtractor
7 from ..compat
import compat_str
12 srt_subtitles_timecode
,
19 class NexxIE(InfoExtractor
):
22 https?://api\.nexx(?:\.cloud|cdn\.com)/v3(?:\.\d)?/(?P<domain_id>\d+)/videos/byid/|
23 nexx:(?:(?P<domain_id_s>\d+):)?|
24 https?://arc\.nexx\.cloud/api/video/
30 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
31 'md5': '31899fd683de49ad46f4ee67e53e83fe',
35 'title': 'Stiftung Warentest',
36 'alt_title': 'Wie ein Test abläuft',
37 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
38 'creator': 'SPIEGEL TV',
39 'thumbnail': r
're:^https?://.*\.jpg$',
41 'timestamp': 1384264416,
42 'upload_date': '20131112',
44 'skip': 'Spiegel nexx CDNs are now disabled'
46 # episode with captions
47 'url': 'https://api.nexx.cloud/v3.1/741/videos/byid/1701834',
51 'title': 'Mein Leben mit \'nem TikTok E-Boy 😤',
52 'alt_title': 'Mein Leben mit \'nem TikTok E-Boy 😤',
53 'description': 'md5:f84f395a881fd143f952c892deab528d',
54 'thumbnail': r
're:^https?://.*\.jpg$',
56 'timestamp': 1595600027,
57 'upload_date': '20200724',
60 'episode': 'Episode 2',
64 'skip_download': True,
67 'url': 'nexx:741:1269984',
68 'md5': 'd5f14e14b592501e51addd5abef95a7f',
72 'title': '1 TAG ohne KLO... wortwörtlich! ?',
73 'alt_title': '1 TAG ohne KLO... wortwörtlich! ?',
74 'description': 'md5:2016393a31991a900946432ccdd09a6f',
75 'thumbnail': r
're:^https?://.*\.jpg$',
77 'timestamp': 1518614955,
78 'upload_date': '20180214',
81 # free cdn from http://www.spiegel.de/video/eifel-zoo-aufregung-um-ausgebrochene-raubtiere-video-99018031.html
82 'url': 'nexx:747:1533779',
83 'md5': '6bf6883912b82b7069fb86c2297e9893',
87 'title': 'Aufregung um ausgebrochene Raubtiere',
88 'alt_title': 'Eifel-Zoo',
89 'description': 'md5:f21375c91c74ad741dcb164c427999d2',
90 'thumbnail': r
're:^https?://.*\.jpg$',
92 'timestamp': 1527874460,
93 'upload_date': '20180601',
95 'skip': 'Spiegel nexx CDNs are now disabled'
97 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
98 'only_matching': True,
100 'url': 'nexx:748:128907',
101 'only_matching': True,
103 'url': 'nexx:128907',
104 'only_matching': True,
106 'url': 'https://arc.nexx.cloud/api/video/128907.json',
107 'only_matching': True,
111 def _extract_domain_id(webpage
):
113 r
'<script\b[^>]+\bsrc=["\'](?
:https?
:)?
//(?
:require|arc
)\
.nexx(?
:\
.cloud|cdn\
.com
)/(?
:sdk
/)?
(?P
<id>\d
+)',
115 return mobj.group('id') if mobj else None
118 def _extract_embed_urls(cls, url, webpage):
120 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
124 # JavaScript Integration
125 domain_id = NexxIE._extract_domain_id(webpage)
127 for video_id in re.findall(
128 r'(?
is)onPLAYReady
.+?_play\
.(?
:init|
(?
:control\
.)?addPlayer
)\s
*\
(.+?\s
*,\s
*["\']?(\d+)',
131 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
132 % (domain_id, video_id))
134 # TODO: support more embed formats
138 def _handle_error(self, response):
139 if traverse_obj(response, ('metadata', 'notice'), expected_type=str):
140 self.report_warning('%s said: %s' % (self.IE_NAME, response['metadata']['notice']))
141 status = int_or_none(try_get(
142 response, lambda x: x['metadata']['status']) or 200)
143 if 200 <= status < 300:
145 raise ExtractorError(
146 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
149 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
150 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
151 result = self._download_json(
152 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
153 'Downloading %s JSON' % path, data=urlencode_postdata(data),
155 self._handle_error(result)
156 return result['result']
158 def _extract_free_formats(self, video, video_id):
159 stream_data = video['streamdata']
160 cdn = stream_data['cdnType']
163 hash = video['general']['hash']
165 ps = compat_str(stream_data['originalDomain'])
166 if stream_data['applyFolderHierarchy'] == 1:
167 s = ('%04d' % int(video_id))[::-1]
168 ps += '/%s/%s' % (s[0:2], s[2:4])
169 ps += '/%s/%s_' % (video_id, hash)
172 fd = stream_data['azureFileDistribution'].split(',')
173 cdn_provider = stream_data['cdnProvider']
176 return '_%s' % p if stream_data['applyAzureStructure'] == 1 else ''
179 if cdn_provider == 'ak':
183 t += p[1] + p0(int(p[0])) + ','
184 t += '.mp4.csmil/master.%s'
185 elif cdn_provider == 'ce':
188 http_base = t = '/'.join(k)
189 http_base = http_base % stream_data['cdnPathHTTP']
190 t += '/asset.ism/manifest.%s?dcp_ver=aos4&videostream='
194 filename = '%s%s%s.mp4' % (h, p[1], p0(tbr))
196 'url': http_base + '/' + filename,
197 'format_id': '%s-http-%d' % (cdn, tbr),
200 width_height = p[1].split('x')
201 if len(width_height) == 2:
203 'width': int_or_none(width_height[0]),
204 'height': int_or_none(width_height[1]),
207 a = filename + ':%s' % (tbr * 1000)
209 t = t[:-1] + '&audiostream=' + a.split(':')[0]
213 if cdn_provider == 'ce':
214 formats.extend(self._extract_mpd_formats(
215 t % (stream_data['cdnPathDASH'], 'mpd'), video_id,
216 mpd_id='%s-dash' % cdn, fatal=False))
217 formats.extend(self._extract_m3u8_formats(
218 t % (stream_data['cdnPathHLS'], 'm3u8'), video_id, 'mp4',
219 entry_protocol='m3u8_native', m3u8_id='%s-hls' % cdn, fatal=False))
223 def _extract_3q_formats(self, video, video_id):
224 stream_data = video['streamdata']
225 cdn = stream_data['cdnType']
228 q_acc, q_prefix, q_locator, q_hash = stream_data['qAccount'], stream_data['qPrefix'], stream_data['qLocator'], stream_data['qHash']
229 protection_key = traverse_obj(
230 video, ('protectiondata', 'key'), expected_type=str)
232 def get_cdn_shield_base(shield_type=''):
233 for secure in ('', 's'):
234 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
236 return 'http%s://%s' % (secure, cdn_shield)
237 return f'http://sdn-global-{"prog" if shield_type.lower() == "prog" else "streaming"}-cache.3qsdn.com/' + (f's/{protection_key}/' if protection_key else '')
239 stream_base = get_cdn_shield_base()
242 formats.extend(self._extract_m3u8_formats(
243 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{stream_data.get("qHEVCHash") or q_hash}.ism/manifest.m3u8',
244 video_id, 'mp4', m3u8_id=f'{cdn}-hls', fatal=False))
245 formats.extend(self._extract_mpd_formats(
246 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{q_hash}.ism/manifest.mpd',
247 video_id, mpd_id=f'{cdn}-dash', fatal=False))
249 progressive_base = get_cdn_shield_base('Prog')
250 q_references = stream_data.get('qReferences') or ''
251 fds = q_references.split(',')
256 tbr = int_or_none(ss[1], scale=1000)
258 'url': f'{progressive_base}{q_acc}/uploads/{q_acc}-{ss[2]}.webm',
259 'format_id': f'{cdn}-{ss[0]}{"-%s" % tbr if tbr else ""}',
263 azure_file_distribution = stream_data.get('azureFileDistribution') or ''
264 fds = azure_file_distribution.split(',')
269 tbr = int_or_none(ss[0])
270 width, height = ss[1].split('x') if len(ss[1].split('x')) == 2 else (None, None)
272 'url': f'{progressive_base}{q_acc}/files/{q_prefix}/{q_locator}/{ss[2]}.mp4',
273 'format_id': f'{cdn}-http-{"-%s" % tbr if tbr else ""}',
275 'width': int_or_none(width),
276 'height': int_or_none(height),
282 def _extract_azure_formats(self, video, video_id):
283 stream_data = video['streamdata']
284 cdn = stream_data['cdnType']
285 assert cdn == 'azure'
287 azure_locator = stream_data['azureLocator']
289 def get_cdn_shield_base(shield_type='', static=False):
290 for secure in ('', 's'):
291 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
293 return 'http%s://%s' % (secure, cdn_shield)
295 if 'fb' in stream_data['azureAccount']:
296 prefix = 'df' if static else 'f'
298 prefix = 'd' if static else 'p'
299 account = int(stream_data['azureAccount'].replace('nexxplayplus', '').replace('nexxplayfb', ''))
300 return 'http://nx-%s%02d.akamaized.net/' % (prefix, account)
302 language = video['general'].get('language_raw') or ''
304 azure_stream_base = get_cdn_shield_base()
305 is_ml = ',' in language
306 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
307 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
309 protection_token = try_get(
310 video, lambda x: x['protectiondata']['token'], compat_str)
312 azure_manifest_url += '?hdnts=%s' % protection_token
314 formats = self._extract_m3u8_formats(
315 azure_manifest_url % '(format=m3u8-aapl)',
316 video_id, 'mp4', 'm3u8_native',
317 m3u8_id='%s-hls' % cdn, fatal=False)
318 formats.extend(self._extract_mpd_formats(
319 azure_manifest_url % '(format=mpd-time-csf)',
320 video_id, mpd_id='%s-dash' % cdn, fatal=False))
321 formats.extend(self._extract_ism_formats(
322 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
324 azure_progressive_base = get_cdn_shield_base('Prog', True)
325 azure_file_distribution = stream_data.get('azureFileDistribution')
326 if azure_file_distribution:
327 fds = azure_file_distribution.split(',')
332 tbr = int_or_none(ss[0])
335 'url': '%s%s/%s_src_%s_%d.mp4' % (
336 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
337 'format_id': '%s-http-%d' % (cdn, tbr),
340 width_height = ss[1].split('x')
341 if len(width_height) == 2:
343 'width': int_or_none(width_height[0]),
344 'height': int_or_none(width_height[1]),
350 def _real_extract(self, url):
351 mobj = self._match_valid_url(url)
352 domain_id = mobj.group('domain_id') or mobj.group('domain_id_s')
353 video_id = mobj.group('id')
357 def find_video(result):
358 if isinstance(result, dict):
360 elif isinstance(result, list):
363 if try_get(v, lambda x: x['general']['ID'], int) == vid:
367 response = self._download_json(
368 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
369 video_id, fatal=False)
370 if response and isinstance(response, dict):
371 result = response.get('result')
373 video = find_video(result)
375 # not all videos work via arc, e.g. nexx:741:1269984
377 # Reverse engineered from JS code (see getDeviceID function)
378 device_id = '%d:%d:%d%d' % (
379 random.randint(1, 4), int(time.time()),
380 random.randint(1e4, 99999), random.randint(1, 9))
382 result = self._call_api(domain_id, 'session/init', video_id, data={
383 'nxp_devh': device_id,
389 'playerversion': '6.0.00',
392 'explicitlanguage': 'en-US',
393 'addTextTemplates': '1',
394 'addDomainData': '1',
397 'X-Request-Enable-Auth-Fallback': '1',
400 cid = result['general']['cid']
402 # As described in [1] X-Request-Token generation algorithm is
404 # md5( operation + domain_id + domain_secret )
405 # where domain_secret is a static value that will be given by nexx.tv
406 # as per [1]. Here is how this "secret
" is generated (reversed
407 # from _play._factory.data.getDomainData function, search for
408 # domaintoken or enableAPIAccess). So it's actually not static
409 # and not that much of a secret.
410 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
411 secret = result['device']['domaintoken'][int(device_id[0]):]
412 secret = secret[0:len(secret) - int(device_id[-1])]
416 # Reversed from JS code for _play.api.call function (search for
418 request_token = hashlib.md5(
419 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
421 result = self._call_api(
422 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
423 'additionalfields': 'language,channel,format,licenseby,slug,fileversion,episode,season',
424 'addInteractionOptions': '1',
425 'addStatusDetails': '1',
426 'addStreamDetails': '1',
428 # Caption format selection doesn't seem to be enforced?
429 'addCaptions': 'vtt',
433 'addConnectedMedia': 'persons',
436 'X-Request-CID': cid,
437 'X-Request-Token': request_token,
439 video = find_video(result)
441 general = video['general']
442 title = general['title']
444 cdn = video['streamdata']['cdnType']
447 formats = self._extract_azure_formats(video, video_id)
449 formats = self._extract_free_formats(video, video_id)
451 formats = self._extract_3q_formats(video, video_id)
453 self.raise_no_formats(f'{cdn} formats are currently not supported', video_id)
455 self._sort_formats(formats)
458 for sub in video.get('captiondata') or []:
460 subtitles.setdefault(sub.get('language', 'en'), []).append({
463 f'{i + 1}\n{srt_subtitles_timecode(line["fromms"] / 1000)} --> {srt_subtitles_timecode(line["toms"] / 1000)}\n{line["caption"]}'
464 for i, line in enumerate(sub['data'])),
465 'name': sub.get('language_long') or sub.get('title')
468 subtitles.setdefault(sub.get('language', 'en'), []).append({
470 'ext': sub.get('format'),
471 'name': sub.get('language_long') or sub.get('title')
477 'alt_title': general.get('subtitle'),
478 'description': general.get('description'),
479 'release_year': int_or_none(general.get('year')),
480 'creator': general.get('studio') or general.get('studio_adref') or None,
481 'thumbnail': try_get(
482 video, lambda x: x['imagedata']['thumb'], compat_str),
483 'duration': parse_duration(general.get('runtime')),
484 'timestamp': int_or_none(general.get('uploaded')),
485 'episode_number': traverse_obj(
486 video, (('episodedata', 'general'), 'episode'), expected_type=int, get_all=False),
487 'season_number': traverse_obj(
488 video, (('episodedata', 'general'), 'season'), expected_type=int, get_all=False),
489 'cast': traverse_obj(video, ('connectedmedia', ..., 'title'), expected_type=str),
491 'subtitles': subtitles,
495 class NexxEmbedIE(InfoExtractor):
496 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?:video/)?(?P<id>[^/?#&]+)'
497 # Reference. https://nx-s.akamaized.net/files/201510/44.pdf
498 _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1']
500 'url
': 'http
://embed
.nexx
.cloud
/748/KC1614647Z27Y7T?autoplay
=1',
501 'md5
': '16746bfc28c42049492385c989b26c4a
',
505 'title
': 'Nervenkitzel Achterbahn
',
506 'alt_title
': 'Karussellbauer
in Deutschland
',
507 'description
': 'md5
:ffe7b1cc59a01f585e0569949aef73cc
',
508 'creator
': 'SPIEGEL TV
',
509 'thumbnail
': r're
:^https?
://.*\
.jpg$
',
511 'timestamp
': 1394021479,
512 'upload_date
': '20140305',
515 'skip_download
': True,
518 'url
': 'https
://embed
.nexx
.cloud
/11888/video
/DSRTO7UVOX06S7
',
519 'only_matching
': True,
522 def _real_extract(self, url):
523 embed_id = self._match_id(url)
525 webpage = self._download_webpage(url, embed_id)
527 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())