]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nexx.py
2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
10 from ..compat
import compat_str
20 class NexxIE(InfoExtractor
):
23 https?://api\.nexx(?:\.cloud|cdn\.com)/v3/(?P<domain_id>\d+)/videos/byid/|
24 nexx:(?:(?P<domain_id_s>\d+):)?|
25 https?://arc\.nexx\.cloud/api/video/
31 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
32 'md5': '828cea195be04e66057b846288295ba1',
36 'title': 'Stiftung Warentest',
37 'alt_title': 'Wie ein Test abläuft',
38 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
40 'creator': 'SPIEGEL TV',
41 'thumbnail': r
're:^https?://.*\.jpg$',
43 'timestamp': 1384264416,
44 'upload_date': '20131112',
48 'url': 'https://api.nexx.cloud/v3/741/videos/byid/247858',
52 'title': 'Return of the Golden Child (OV)',
53 'description': 'md5:5d969537509a92b733de21bae249dc63',
55 'thumbnail': r
're:^https?://.*\.jpg$',
57 'timestamp': 1495033267,
58 'upload_date': '20170517',
63 'skip_download': True,
66 # does not work via arc
67 'url': 'nexx:741:1269984',
68 'md5': 'c714b5b238b2958dc8d5642addba6886',
72 'title': '1 TAG ohne KLO... wortwörtlich! 😑',
73 'alt_title': '1 TAG ohne KLO... wortwörtlich! 😑',
74 'description': 'md5:4604539793c49eda9443ab5c5b1d612f',
75 'thumbnail': r
're:^https?://.*\.jpg$',
77 'timestamp': 1518614955,
78 'upload_date': '20180214',
81 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
82 'only_matching': True,
84 'url': 'nexx:748:128907',
85 'only_matching': True,
88 'only_matching': True,
90 'url': 'https://arc.nexx.cloud/api/video/128907.json',
91 'only_matching': True,
95 def _extract_domain_id(webpage
):
97 r
'<script\b[^>]+\bsrc=["\'](?
:https?
:)?
//require\
.nexx(?
:\
.cloud|cdn\
.com
)/(?P
<id>\d
+)',
99 return mobj.group('id') if mobj else None
102 def _extract_urls(webpage):
104 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
108 # JavaScript Integration
109 domain_id = NexxIE._extract_domain_id(webpage)
111 for video_id in re.findall(
112 r'(?
is)onPLAYReady
.+?_play\
.init\s
*\
(.+?\s
*,\s
*["\']?(\d+)',
115 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
116 % (domain_id, video_id))
118 # TODO: support more embed formats
123 def _extract_url(webpage):
124 return NexxIE._extract_urls(webpage)[0]
126 def _handle_error(self, response):
127 status = int_or_none(try_get(
128 response, lambda x: x['metadata']['status']) or 200)
129 if 200 <= status < 300:
131 raise ExtractorError(
132 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
135 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
136 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
137 result = self._download_json(
138 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
139 'Downloading %s JSON' % path, data=urlencode_postdata(data),
141 self._handle_error(result)
142 return result['result']
144 def _real_extract(self, url):
145 mobj = re.match(self._VALID_URL, url)
146 domain_id = mobj.group('domain_id') or mobj.group('domain_id_s')
147 video_id = mobj.group('id')
151 response = self._download_json(
152 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
153 video_id, fatal=False)
154 if response and isinstance(response, dict):
155 result = response.get('result')
156 if result and isinstance(result, dict):
159 # not all videos work via arc, e.g. nexx:741:1269984
161 # Reverse engineered from JS code (see getDeviceID function)
162 device_id = '%d:%d:%d%d' % (
163 random.randint(1, 4), int(time.time()),
164 random.randint(1e4, 99999), random.randint(1, 9))
166 result = self._call_api(domain_id, 'session/init', video_id, data={
167 'nxp_devh': device_id,
173 'playerversion': '6.0.00',
176 'explicitlanguage': 'en-US',
177 'addTextTemplates': '1',
178 'addDomainData': '1',
181 'X-Request-Enable-Auth-Fallback': '1',
184 cid = result['general']['cid']
186 # As described in [1] X-Request-Token generation algorithm is
188 # md5( operation + domain_id + domain_secret )
189 # where domain_secret is a static value that will be given by nexx.tv
190 # as per [1]. Here is how this "secret
" is generated (reversed
191 # from _play.api.init function, search for clienttoken). So it's
192 # actually not static and not that much of a secret.
193 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
194 secret = result['device']['clienttoken'][int(device_id[0]):]
195 secret = secret[0:len(secret) - int(device_id[-1])]
199 # Reversed from JS code for _play.api.call function (search for
201 request_token = hashlib.md5(
202 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
204 video = self._call_api(
205 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
206 'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description',
207 'addInteractionOptions': '1',
208 'addStatusDetails': '1',
209 'addStreamDetails': '1',
214 'captionFormat': 'data',
216 'X-Request-CID': cid,
217 'X-Request-Token': request_token,
220 general = video['general']
221 title = general['title']
223 stream_data = video['streamdata']
224 language = general.get('language_raw') or ''
226 # TODO: reverse more cdns
228 cdn = stream_data['cdnType']
229 assert cdn == 'azure'
231 azure_locator = stream_data['azureLocator']
233 def get_cdn_shield_base(shield_type='', static=False):
234 for secure in ('', 's'):
235 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
237 return 'http%s://%s' % (secure, cdn_shield)
239 if 'fb' in stream_data['azureAccount']:
240 prefix = 'df' if static else 'f'
242 prefix = 'd' if static else 'p'
243 account = int(stream_data['azureAccount'].replace('nexxplayplus', '').replace('nexxplayfb', ''))
244 return 'http://nx-%s%02d.akamaized.net/' % (prefix, account)
246 azure_stream_base = get_cdn_shield_base()
247 is_ml = ',' in language
248 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
249 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
251 protection_token = try_get(
252 video, lambda x: x['protectiondata']['token'], compat_str)
254 azure_manifest_url += '?hdnts=%s' % protection_token
256 formats = self._extract_m3u8_formats(
257 azure_manifest_url % '(format=m3u8-aapl)',
258 video_id, 'mp4', 'm3u8_native',
259 m3u8_id='%s-hls' % cdn, fatal=False)
260 formats.extend(self._extract_mpd_formats(
261 azure_manifest_url % '(format=mpd-time-csf)',
262 video_id, mpd_id='%s-dash' % cdn, fatal=False))
263 formats.extend(self._extract_ism_formats(
264 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
266 azure_progressive_base = get_cdn_shield_base('Prog', True)
267 azure_file_distribution = stream_data.get('azureFileDistribution')
268 if azure_file_distribution:
269 fds = azure_file_distribution.split(',')
274 tbr = int_or_none(ss[0])
277 'url': '%s%s/%s_src_%s_%d.mp4' % (
278 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
279 'format_id': '%s-http-%d' % (cdn, tbr),
282 width_height = ss[1].split('x')
283 if len(width_height) == 2:
285 'width': int_or_none(width_height[0]),
286 'height': int_or_none(width_height[1]),
290 self._sort_formats(formats)
295 'alt_title': general.get('subtitle'),
296 'description': general.get('description'),
297 'release_year': int_or_none(general.get('year')),
298 'creator': general.get('studio') or general.get('studio_adref'),
299 'thumbnail': try_get(
300 video, lambda x: x['imagedata']['thumb'], compat_str),
301 'duration': parse_duration(general.get('runtime')),
302 'timestamp': int_or_none(general.get('uploaded')),
303 'episode_number': int_or_none(try_get(
304 video, lambda x: x['episodedata']['episode'])),
305 'season_number': int_or_none(try_get(
306 video, lambda x: x['episodedata']['season'])),
311 class NexxEmbedIE(InfoExtractor):
312 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?P<id>[^/?#&]+)'
314 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
315 'md5': '16746bfc28c42049492385c989b26c4a',
319 'title': 'Nervenkitzel Achterbahn',
320 'alt_title': 'Karussellbauer in Deutschland',
321 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
322 'release_year': 2005,
323 'creator': 'SPIEGEL TV',
324 'thumbnail': r're:^https?://.*\.jpg$',
326 'timestamp': 1394021479,
327 'upload_date': '20140305',
330 'format': 'bestvideo',
331 'skip_download': True,
336 def _extract_urls(webpage):
338 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
340 # iFrame Embed Integration
341 return [mobj.group('url') for mobj in re.finditer(
342 r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1',
345 def _real_extract(self, url):
346 embed_id = self._match_id(url)
348 webpage = self._download_webpage(url, embed_id)
350 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())