]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nexx.py
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_urls(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
139 def _extract_url(webpage):
140 return NexxIE._extract_urls(webpage)[0]
142 def _handle_error(self, response):
143 if traverse_obj(response, ('metadata', 'notice'), expected_type=str):
144 self.report_warning('%s said: %s' % (self.IE_NAME, response['metadata']['notice']))
145 status = int_or_none(try_get(
146 response, lambda x: x['metadata']['status']) or 200)
147 if 200 <= status < 300:
149 raise ExtractorError(
150 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
153 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
154 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
155 result = self._download_json(
156 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
157 'Downloading %s JSON' % path, data=urlencode_postdata(data),
159 self._handle_error(result)
160 return result['result']
162 def _extract_free_formats(self, video, video_id):
163 stream_data = video['streamdata']
164 cdn = stream_data['cdnType']
167 hash = video['general']['hash']
169 ps = compat_str(stream_data['originalDomain'])
170 if stream_data['applyFolderHierarchy'] == 1:
171 s = ('%04d' % int(video_id))[::-1]
172 ps += '/%s/%s' % (s[0:2], s[2:4])
173 ps += '/%s/%s_' % (video_id, hash)
176 fd = stream_data['azureFileDistribution'].split(',')
177 cdn_provider = stream_data['cdnProvider']
180 return '_%s' % p if stream_data['applyAzureStructure'] == 1 else ''
183 if cdn_provider == 'ak':
187 t += p[1] + p0(int(p[0])) + ','
188 t += '.mp4.csmil/master.%s'
189 elif cdn_provider == 'ce':
192 http_base = t = '/'.join(k)
193 http_base = http_base % stream_data['cdnPathHTTP']
194 t += '/asset.ism/manifest.%s?dcp_ver=aos4&videostream='
198 filename = '%s%s%s.mp4' % (h, p[1], p0(tbr))
200 'url': http_base + '/' + filename,
201 'format_id': '%s-http-%d' % (cdn, tbr),
204 width_height = p[1].split('x')
205 if len(width_height) == 2:
207 'width': int_or_none(width_height[0]),
208 'height': int_or_none(width_height[1]),
211 a = filename + ':%s' % (tbr * 1000)
213 t = t[:-1] + '&audiostream=' + a.split(':')[0]
217 if cdn_provider == 'ce':
218 formats.extend(self._extract_mpd_formats(
219 t % (stream_data['cdnPathDASH'], 'mpd'), video_id,
220 mpd_id='%s-dash' % cdn, fatal=False))
221 formats.extend(self._extract_m3u8_formats(
222 t % (stream_data['cdnPathHLS'], 'm3u8'), video_id, 'mp4',
223 entry_protocol='m3u8_native', m3u8_id='%s-hls' % cdn, fatal=False))
227 def _extract_3q_formats(self, video, video_id):
228 stream_data = video['streamdata']
229 cdn = stream_data['cdnType']
232 q_acc, q_prefix, q_locator, q_hash = stream_data['qAccount'], stream_data['qPrefix'], stream_data['qLocator'], stream_data['qHash']
233 protection_key = traverse_obj(
234 video, ('protectiondata', 'key'), expected_type=str)
236 def get_cdn_shield_base(shield_type=''):
237 for secure in ('', 's'):
238 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
240 return 'http%s://%s' % (secure, cdn_shield)
241 return f'http://sdn-global-{"prog" if shield_type.lower() == "prog" else "streaming"}-cache.3qsdn.com/' + (f's/{protection_key}/' if protection_key else '')
243 stream_base = get_cdn_shield_base()
246 formats.extend(self._extract_m3u8_formats(
247 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{stream_data.get("qHEVCHash") or q_hash}.ism/manifest.m3u8',
248 video_id, 'mp4', m3u8_id=f'{cdn}-hls', fatal=False))
249 formats.extend(self._extract_mpd_formats(
250 f'{stream_base}{q_acc}/files/{q_prefix}/{q_locator}/{q_acc}-{q_hash}.ism/manifest.mpd',
251 video_id, mpd_id=f'{cdn}-dash', fatal=False))
253 progressive_base = get_cdn_shield_base('Prog')
254 q_references = stream_data.get('qReferences') or ''
255 fds = q_references.split(',')
260 tbr = int_or_none(ss[1], scale=1000)
262 'url': f'{progressive_base}{q_acc}/uploads/{q_acc}-{ss[2]}.webm',
263 'format_id': f'{cdn}-{ss[0]}{"-%s" % tbr if tbr else ""}',
267 azure_file_distribution = stream_data.get('azureFileDistribution') or ''
268 fds = azure_file_distribution.split(',')
273 tbr = int_or_none(ss[0])
274 width, height = ss[1].split('x') if len(ss[1].split('x')) == 2 else (None, None)
276 'url': f'{progressive_base}{q_acc}/files/{q_prefix}/{q_locator}/{ss[2]}.mp4',
277 'format_id': f'{cdn}-http-{"-%s" % tbr if tbr else ""}',
279 'width': int_or_none(width),
280 'height': int_or_none(height),
286 def _extract_azure_formats(self, video, video_id):
287 stream_data = video['streamdata']
288 cdn = stream_data['cdnType']
289 assert cdn == 'azure'
291 azure_locator = stream_data['azureLocator']
293 def get_cdn_shield_base(shield_type='', static=False):
294 for secure in ('', 's'):
295 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
297 return 'http%s://%s' % (secure, cdn_shield)
299 if 'fb' in stream_data['azureAccount']:
300 prefix = 'df' if static else 'f'
302 prefix = 'd' if static else 'p'
303 account = int(stream_data['azureAccount'].replace('nexxplayplus', '').replace('nexxplayfb', ''))
304 return 'http://nx-%s%02d.akamaized.net/' % (prefix, account)
306 language = video['general'].get('language_raw') or ''
308 azure_stream_base = get_cdn_shield_base()
309 is_ml = ',' in language
310 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
311 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
313 protection_token = try_get(
314 video, lambda x: x['protectiondata']['token'], compat_str)
316 azure_manifest_url += '?hdnts=%s' % protection_token
318 formats = self._extract_m3u8_formats(
319 azure_manifest_url % '(format=m3u8-aapl)',
320 video_id, 'mp4', 'm3u8_native',
321 m3u8_id='%s-hls' % cdn, fatal=False)
322 formats.extend(self._extract_mpd_formats(
323 azure_manifest_url % '(format=mpd-time-csf)',
324 video_id, mpd_id='%s-dash' % cdn, fatal=False))
325 formats.extend(self._extract_ism_formats(
326 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
328 azure_progressive_base = get_cdn_shield_base('Prog', True)
329 azure_file_distribution = stream_data.get('azureFileDistribution')
330 if azure_file_distribution:
331 fds = azure_file_distribution.split(',')
336 tbr = int_or_none(ss[0])
339 'url': '%s%s/%s_src_%s_%d.mp4' % (
340 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
341 'format_id': '%s-http-%d' % (cdn, tbr),
344 width_height = ss[1].split('x')
345 if len(width_height) == 2:
347 'width': int_or_none(width_height[0]),
348 'height': int_or_none(width_height[1]),
354 def _real_extract(self, url):
355 mobj = self._match_valid_url(url)
356 domain_id = mobj.group('domain_id') or mobj.group('domain_id_s')
357 video_id = mobj.group('id')
361 def find_video(result):
362 if isinstance(result, dict):
364 elif isinstance(result, list):
367 if try_get(v, lambda x: x['general']['ID'], int) == vid:
371 response = self._download_json(
372 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
373 video_id, fatal=False)
374 if response and isinstance(response, dict):
375 result = response.get('result')
377 video = find_video(result)
379 # not all videos work via arc, e.g. nexx:741:1269984
381 # Reverse engineered from JS code (see getDeviceID function)
382 device_id = '%d:%d:%d%d' % (
383 random.randint(1, 4), int(time.time()),
384 random.randint(1e4, 99999), random.randint(1, 9))
386 result = self._call_api(domain_id, 'session/init', video_id, data={
387 'nxp_devh': device_id,
393 'playerversion': '6.0.00',
396 'explicitlanguage': 'en-US',
397 'addTextTemplates': '1',
398 'addDomainData': '1',
401 'X-Request-Enable-Auth-Fallback': '1',
404 cid = result['general']['cid']
406 # As described in [1] X-Request-Token generation algorithm is
408 # md5( operation + domain_id + domain_secret )
409 # where domain_secret is a static value that will be given by nexx.tv
410 # as per [1]. Here is how this "secret
" is generated (reversed
411 # from _play._factory.data.getDomainData function, search for
412 # domaintoken or enableAPIAccess). So it's actually not static
413 # and not that much of a secret.
414 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
415 secret = result['device']['domaintoken'][int(device_id[0]):]
416 secret = secret[0:len(secret) - int(device_id[-1])]
420 # Reversed from JS code for _play.api.call function (search for
422 request_token = hashlib.md5(
423 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
425 result = self._call_api(
426 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
427 'additionalfields': 'language,channel,format,licenseby,slug,fileversion,episode,season',
428 'addInteractionOptions': '1',
429 'addStatusDetails': '1',
430 'addStreamDetails': '1',
432 # Caption format selection doesn't seem to be enforced?
433 'addCaptions': 'vtt',
437 'addConnectedMedia': 'persons',
440 'X-Request-CID': cid,
441 'X-Request-Token': request_token,
443 video = find_video(result)
445 general = video['general']
446 title = general['title']
448 cdn = video['streamdata']['cdnType']
451 formats = self._extract_azure_formats(video, video_id)
453 formats = self._extract_free_formats(video, video_id)
455 formats = self._extract_3q_formats(video, video_id)
457 self.raise_no_formats(f'{cdn} formats are currently not supported', video_id)
459 self._sort_formats(formats)
462 for sub in video.get('captiondata') or []:
464 subtitles.setdefault(sub.get('language', 'en'), []).append({
467 f'{i + 1}\n{srt_subtitles_timecode(line["fromms"] / 1000)} --> {srt_subtitles_timecode(line["toms"] / 1000)}\n{line["caption"]}'
468 for i, line in enumerate(sub['data'])),
469 'name': sub.get('language_long') or sub.get('title')
472 subtitles.setdefault(sub.get('language', 'en'), []).append({
474 'ext': sub.get('format'),
475 'name': sub.get('language_long') or sub.get('title')
481 'alt_title': general.get('subtitle'),
482 'description': general.get('description'),
483 'release_year': int_or_none(general.get('year')),
484 'creator': general.get('studio') or general.get('studio_adref') or None,
485 'thumbnail': try_get(
486 video, lambda x: x['imagedata']['thumb'], compat_str),
487 'duration': parse_duration(general.get('runtime')),
488 'timestamp': int_or_none(general.get('uploaded')),
489 'episode_number': traverse_obj(
490 video, (('episodedata', 'general'), 'episode'), expected_type=int, get_all=False),
491 'season_number': traverse_obj(
492 video, (('episodedata', 'general'), 'season'), expected_type=int, get_all=False),
493 'cast': traverse_obj(video, ('connectedmedia', ..., 'title'), expected_type=str),
495 'subtitles': subtitles,
499 class NexxEmbedIE(InfoExtractor):
500 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?:video/)?(?P<id>[^/?#&]+)'
502 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
503 'md5': '16746bfc28c42049492385c989b26c4a',
507 'title': 'Nervenkitzel Achterbahn',
508 'alt_title': 'Karussellbauer in Deutschland',
509 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
510 'creator': 'SPIEGEL TV',
511 'thumbnail': r're:^https?://.*\.jpg$',
513 'timestamp': 1394021479,
514 'upload_date': '20140305',
517 'skip_download': True,
520 'url': 'https://embed.nexx.cloud/11888/video/DSRTO7UVOX06S7',
521 'only_matching': True,
525 def _extract_urls(webpage):
527 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
529 # iFrame Embed Integration
530 return [mobj.group('url') for mobj in re.finditer(
531 r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1',
534 def _real_extract(self, url):
535 embed_id = self._match_id(url)
537 webpage = self._download_webpage(url, embed_id)
539 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())