]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nexx.py
2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import compat_str
15 srt_subtitles_timecode
,
22 class NexxIE(InfoExtractor
):
25 https?://api\.nexx(?:\.cloud|cdn\.com)/v3(?:\.\d)?/(?P<domain_id>\d+)/videos/byid/|
26 nexx:(?:(?P<domain_id_s>\d+):)?|
27 https?://arc\.nexx\.cloud/api/video/
33 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
34 'md5': '31899fd683de49ad46f4ee67e53e83fe',
38 'title': 'Stiftung Warentest',
39 'alt_title': 'Wie ein Test abläuft',
40 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
41 'creator': 'SPIEGEL TV',
42 'thumbnail': r
're:^https?://.*\.jpg$',
44 'timestamp': 1384264416,
45 'upload_date': '20131112',
47 'skip': 'Spiegel nexx CDNs are now disabled'
49 # episode with captions
50 'url': 'https://api.nexx.cloud/v3.1/741/videos/byid/1701834',
54 'title': 'Mein Leben mit \'nem TikTok E-Boy 😤',
55 'alt_title': 'Mein Leben mit \'nem TikTok E-Boy 😤',
56 'description': 'md5:f84f395a881fd143f952c892deab528d',
57 'thumbnail': r
're:^https?://.*\.jpg$',
59 'timestamp': 1595600027,
60 'upload_date': '20200724',
63 'episode': 'Episode 2',
67 'skip_download': True,
70 'url': 'nexx:741:1269984',
71 'md5': 'd5f14e14b592501e51addd5abef95a7f',
75 'title': '1 TAG ohne KLO... wortwörtlich! ?',
76 'alt_title': '1 TAG ohne KLO... wortwörtlich! ?',
77 'description': 'md5:2016393a31991a900946432ccdd09a6f',
78 'thumbnail': r
're:^https?://.*\.jpg$',
80 'timestamp': 1518614955,
81 'upload_date': '20180214',
84 # free cdn from http://www.spiegel.de/video/eifel-zoo-aufregung-um-ausgebrochene-raubtiere-video-99018031.html
85 'url': 'nexx:747:1533779',
86 'md5': '6bf6883912b82b7069fb86c2297e9893',
90 'title': 'Aufregung um ausgebrochene Raubtiere',
91 'alt_title': 'Eifel-Zoo',
92 'description': 'md5:f21375c91c74ad741dcb164c427999d2',
93 'thumbnail': r
're:^https?://.*\.jpg$',
95 'timestamp': 1527874460,
96 'upload_date': '20180601',
98 'skip': 'Spiegel nexx CDNs are now disabled'
100 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
101 'only_matching': True,
103 'url': 'nexx:748:128907',
104 'only_matching': True,
106 'url': 'nexx:128907',
107 'only_matching': True,
109 'url': 'https://arc.nexx.cloud/api/video/128907.json',
110 'only_matching': True,
114 def _extract_domain_id(webpage
):
116 r
'<script\b[^>]+\bsrc=["\'](?
:https?
:)?
//(?
:require|arc
)\
.nexx(?
:\
.cloud|cdn\
.com
)/(?
:sdk
/)?
(?P
<id>\d
+)',
118 return mobj.group('id') if mobj else None
121 def _extract_urls(webpage):
123 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
127 # JavaScript Integration
128 domain_id = NexxIE._extract_domain_id(webpage)
130 for video_id in re.findall(
131 r'(?
is)onPLAYReady
.+?_play\
.(?
:init|
(?
:control\
.)?addPlayer
)\s
*\
(.+?\s
*,\s
*["\']?(\d+)',
134 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
135 % (domain_id, video_id))
137 # TODO: support more embed formats
142 def _extract_url(webpage):
143 return NexxIE._extract_urls(webpage)[0]
145 def _handle_error(self, response):
146 if traverse_obj(response, ('metadata', 'notice'), expected_type=str):
147 self.report_warning('%s said: %s' % (self.IE_NAME, response['metadata']['notice']))
148 status = int_or_none(try_get(
149 response, lambda x: x['metadata']['status']) or 200)
150 if 200 <= status < 300:
152 raise ExtractorError(
153 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
156 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
157 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
158 result = self._download_json(
159 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
160 'Downloading %s JSON' % path, data=urlencode_postdata(data),
162 self._handle_error(result)
163 return result['result']
165 def _extract_free_formats(self, video, video_id):
166 stream_data = video['streamdata']
167 cdn = stream_data['cdnType']
170 hash = video['general']['hash']
172 ps = compat_str(stream_data['originalDomain'])
173 if stream_data['applyFolderHierarchy'] == 1:
174 s = ('%04d' % int(video_id))[::-1]
175 ps += '/%s/%s' % (s[0:2], s[2:4])
176 ps += '/%s/%s_' % (video_id, hash)
179 fd = stream_data['azureFileDistribution'].split(',')
180 cdn_provider = stream_data['cdnProvider']
183 return '_%s' % p if stream_data['applyAzureStructure'] == 1 else ''
186 if cdn_provider == 'ak':
190 t += p[1] + p0(int(p[0])) + ','
191 t += '.mp4.csmil/master.%s'
192 elif cdn_provider == 'ce':
195 http_base = t = '/'.join(k)
196 http_base = http_base % stream_data['cdnPathHTTP']
197 t += '/asset.ism/manifest.%s?dcp_ver=aos4&videostream='
201 filename = '%s%s%s.mp4' % (h, p[1], p0(tbr))
203 'url': http_base + '/' + filename,
204 'format_id': '%s-http-%d' % (cdn, tbr),
207 width_height = p[1].split('x')
208 if len(width_height) == 2:
210 'width': int_or_none(width_height[0]),
211 'height': int_or_none(width_height[1]),
214 a = filename + ':%s' % (tbr * 1000)
216 t = t[:-1] + '&audiostream=' + a.split(':')[0]
220 if cdn_provider == 'ce':
221 formats.extend(self._extract_mpd_formats(
222 t % (stream_data['cdnPathDASH'], 'mpd'), video_id,
223 mpd_id='%s-dash' % cdn, fatal=False))
224 formats.extend(self._extract_m3u8_formats(
225 t % (stream_data['cdnPathHLS'], 'm3u8'), video_id, 'mp4',
226 entry_protocol='m3u8_native', m3u8_id='%s-hls' % cdn, fatal=False))
230 def _extract_3q_formats(self, video, video_id):
231 stream_data = video['streamdata']
232 cdn = stream_data['cdnType']
235 q_acc, q_prefix, q_locator, q_hash = stream_data['qAccount'], stream_data['qPrefix'], stream_data['qLocator'], stream_data['qHash']
236 protection_key = traverse_obj(
237 video, ('protectiondata', 'key'), expected_type=str)
239 def get_cdn_shield_base(shield_type=''):
240 for secure in ('', 's'):
241 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
243 return 'http%s://%s' % (secure, cdn_shield)
244 return f'http://sdn-global-{"prog" if shield_type.lower() == "prog" else "streaming"}-cache.3qsdn.com/' + (f's/{protection_key}/' if protection_key else '')
246 stream_base = get_cdn_shield_base()
249 formats.extend(self._extract_m3u8_formats(
250 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{stream_data.get("qHEVCHash") or q_hash}.ism/manifest.m3u8',
251 video_id, 'mp4', m3u8_id=f'{cdn}-hls', fatal=False))
252 formats.extend(self._extract_mpd_formats(
253 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{q_hash}.ism/manifest.mpd',
254 video_id, mpd_id=f'{cdn}-dash', fatal=False))
256 progressive_base = get_cdn_shield_base('Prog')
257 q_references = stream_data.get('qReferences') or ''
258 fds = q_references.split(',')
263 tbr = int_or_none(ss[1], scale=1000)
265 'url': f'{progressive_base}{q_acc}/uploads/{q_acc}-{ss[2]}.webm',
266 'format_id': f'{cdn}-{ss[0]}{"-%s" % tbr if tbr else ""}',
270 azure_file_distribution = stream_data.get('azureFileDistribution') or ''
271 fds = azure_file_distribution.split(',')
276 tbr = int_or_none(ss[0])
277 width, height = ss[1].split('x') if len(ss[1].split('x')) == 2 else (None, None)
279 'url': f'{progressive_base}{q_acc}/files/{q_prefix}/{q_locator}/{ss[2]}.mp4',
280 'format_id': f'{cdn}-http-{"-%s" % tbr if tbr else ""}',
282 'width': int_or_none(width),
283 'height': int_or_none(height),
289 def _extract_azure_formats(self, video, video_id):
290 stream_data = video['streamdata']
291 cdn = stream_data['cdnType']
292 assert cdn == 'azure'
294 azure_locator = stream_data['azureLocator']
296 def get_cdn_shield_base(shield_type='', static=False):
297 for secure in ('', 's'):
298 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
300 return 'http%s://%s' % (secure, cdn_shield)
302 if 'fb' in stream_data['azureAccount']:
303 prefix = 'df' if static else 'f'
305 prefix = 'd' if static else 'p'
306 account = int(stream_data['azureAccount'].replace('nexxplayplus', '').replace('nexxplayfb', ''))
307 return 'http://nx-%s%02d.akamaized.net/' % (prefix, account)
309 language = video['general'].get('language_raw') or ''
311 azure_stream_base = get_cdn_shield_base()
312 is_ml = ',' in language
313 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
314 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
316 protection_token = try_get(
317 video, lambda x: x['protectiondata']['token'], compat_str)
319 azure_manifest_url += '?hdnts=%s' % protection_token
321 formats = self._extract_m3u8_formats(
322 azure_manifest_url % '(format=m3u8-aapl)',
323 video_id, 'mp4', 'm3u8_native',
324 m3u8_id='%s-hls' % cdn, fatal=False)
325 formats.extend(self._extract_mpd_formats(
326 azure_manifest_url % '(format=mpd-time-csf)',
327 video_id, mpd_id='%s-dash' % cdn, fatal=False))
328 formats.extend(self._extract_ism_formats(
329 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
331 azure_progressive_base = get_cdn_shield_base('Prog', True)
332 azure_file_distribution = stream_data.get('azureFileDistribution')
333 if azure_file_distribution:
334 fds = azure_file_distribution.split(',')
339 tbr = int_or_none(ss[0])
342 'url': '%s%s/%s_src_%s_%d.mp4' % (
343 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
344 'format_id': '%s-http-%d' % (cdn, tbr),
347 width_height = ss[1].split('x')
348 if len(width_height) == 2:
350 'width': int_or_none(width_height[0]),
351 'height': int_or_none(width_height[1]),
357 def _real_extract(self, url):
358 mobj = self._match_valid_url(url)
359 domain_id = mobj.group('domain_id') or mobj.group('domain_id_s')
360 video_id = mobj.group('id')
364 def find_video(result):
365 if isinstance(result, dict):
367 elif isinstance(result, list):
370 if try_get(v, lambda x: x['general']['ID'], int) == vid:
374 response = self._download_json(
375 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
376 video_id, fatal=False)
377 if response and isinstance(response, dict):
378 result = response.get('result')
380 video = find_video(result)
382 # not all videos work via arc, e.g. nexx:741:1269984
384 # Reverse engineered from JS code (see getDeviceID function)
385 device_id = '%d:%d:%d%d' % (
386 random.randint(1, 4), int(time.time()),
387 random.randint(1e4, 99999), random.randint(1, 9))
389 result = self._call_api(domain_id, 'session/init', video_id, data={
390 'nxp_devh': device_id,
396 'playerversion': '6.0.00',
399 'explicitlanguage': 'en-US',
400 'addTextTemplates': '1',
401 'addDomainData': '1',
404 'X-Request-Enable-Auth-Fallback': '1',
407 cid = result['general']['cid']
409 # As described in [1] X-Request-Token generation algorithm is
411 # md5( operation + domain_id + domain_secret )
412 # where domain_secret is a static value that will be given by nexx.tv
413 # as per [1]. Here is how this "secret
" is generated (reversed
414 # from _play._factory.data.getDomainData function, search for
415 # domaintoken or enableAPIAccess). So it's actually not static
416 # and not that much of a secret.
417 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
418 secret = result['device']['domaintoken'][int(device_id[0]):]
419 secret = secret[0:len(secret) - int(device_id[-1])]
423 # Reversed from JS code for _play.api.call function (search for
425 request_token = hashlib.md5(
426 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
428 result = self._call_api(
429 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
430 'additionalfields': 'language,channel,format,licenseby,slug,fileversion,episode,season',
431 'addInteractionOptions': '1',
432 'addStatusDetails': '1',
433 'addStreamDetails': '1',
435 # Caption format selection doesn't seem to be enforced?
436 'addCaptions': 'vtt',
440 'addConnectedMedia': 'persons',
443 'X-Request-CID': cid,
444 'X-Request-Token': request_token,
446 video = find_video(result)
448 general = video['general']
449 title = general['title']
451 cdn = video['streamdata']['cdnType']
454 formats = self._extract_azure_formats(video, video_id)
456 formats = self._extract_free_formats(video, video_id)
458 formats = self._extract_3q_formats(video, video_id)
460 self.raise_no_formats(f'{cdn} formats are currently not supported', video_id)
462 self._sort_formats(formats)
465 for sub in video.get('captiondata') or []:
467 subtitles.setdefault(sub.get('language', 'en'), []).append({
470 f'{i + 1}\n{srt_subtitles_timecode(line["fromms"] / 1000)} --> {srt_subtitles_timecode(line["toms"] / 1000)}\n{line["caption"]}'
471 for i, line in enumerate(sub['data'])),
472 'name': sub.get('language_long') or sub.get('title')
475 subtitles.setdefault(sub.get('language', 'en'), []).append({
477 'ext': sub.get('format'),
478 'name': sub.get('language_long') or sub.get('title')
484 'alt_title': general.get('subtitle'),
485 'description': general.get('description'),
486 'release_year': int_or_none(general.get('year')),
487 'creator': general.get('studio') or general.get('studio_adref') or None,
488 'thumbnail': try_get(
489 video, lambda x: x['imagedata']['thumb'], compat_str),
490 'duration': parse_duration(general.get('runtime')),
491 'timestamp': int_or_none(general.get('uploaded')),
492 'episode_number': traverse_obj(
493 video, (('episodedata', 'general'), 'episode'), expected_type=int, get_all=False),
494 'season_number': traverse_obj(
495 video, (('episodedata', 'general'), 'season'), expected_type=int, get_all=False),
496 'cast': traverse_obj(video, ('connectedmedia', ..., 'title'), expected_type=str),
498 'subtitles': subtitles,
502 class NexxEmbedIE(InfoExtractor):
503 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?:video/)?(?P<id>[^/?#&]+)'
505 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
506 'md5': '16746bfc28c42049492385c989b26c4a',
510 'title': 'Nervenkitzel Achterbahn',
511 'alt_title': 'Karussellbauer in Deutschland',
512 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
513 'creator': 'SPIEGEL TV',
514 'thumbnail': r're:^https?://.*\.jpg$',
516 'timestamp': 1394021479,
517 'upload_date': '20140305',
520 'skip_download': True,
523 'url': 'https://embed.nexx.cloud/11888/video/DSRTO7UVOX06S7',
524 'only_matching': True,
528 def _extract_urls(webpage):
530 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
532 # iFrame Embed Integration
533 return [mobj.group('url') for mobj in re.finditer(
534 r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1',
537 def _real_extract(self, url):
538 embed_id = self._match_id(url)
540 webpage = self._download_webpage(url, embed_id)
542 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())