2 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import compat_str
20 class NexxIE(InfoExtractor):
21 _VALID_URL = r'https?://api\.nexx(?:\.cloud|cdn\.com)/v3/(?P<domain_id>\d+)/videos/byid/(?P<id>\d+)'
24 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
25 'md5': '16746bfc28c42049492385c989b26c4a',
29 'title': 'Stiftung Warentest',
30 'alt_title': 'Wie ein Test abläuft',
31 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
33 'creator': 'SPIEGEL TV',
34 'thumbnail': r're:^https?://.*\.jpg$',
36 'timestamp': 1384264416,
37 'upload_date': '20131112',
40 'format': 'bestvideo',
44 'url': 'https://api.nexx.cloud/v3/741/videos/byid/247858',
48 'title': 'Return of the Golden Child (OV)',
49 'description': 'md5:5d969537509a92b733de21bae249dc63',
51 'thumbnail': r're:^https?://.*\.jpg$',
53 'timestamp': 1495033267,
54 'upload_date': '20170517',
59 'format': 'bestvideo',
60 'skip_download': True,
63 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
64 'only_matching': True,
68 def _extract_urls(webpage):
70 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
74 # JavaScript Integration
76 r'<script\b[^>]+\bsrc=["\']https?://require\.nexx(?:\.cloud|cdn\.com)/(?P<id>\d+)',
79 domain_id = mobj.group('id')
80 for video_id in re.findall(
81 r'(?is)onPLAYReady.+?_play\.init\s*\(.+?\s*,\s*["\']?(\d+)',
84 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
85 % (domain_id, video_id))
87 # TODO: support more embed formats
91 def _handle_error(self, response):
92 status = int_or_none(try_get(
93 response, lambda x: x['metadata']['status']) or 200)
94 if 200 <= status < 300:
97 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
100 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
101 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
102 result = self._download_json(
103 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
104 'Downloading %s JSON' % path, data=urlencode_postdata(data),
106 self._handle_error(result)
107 return result['result']
109 def _real_extract(self, url):
110 mobj = re.match(self._VALID_URL, url)
111 domain_id, video_id = mobj.group('domain_id', 'id')
113 # Reverse engineered from JS code (see getDeviceID function)
114 device_id = '%d:%d:%d%d' % (
115 random.randint(1, 4), int(time.time()),
116 random.randint(1e4, 99999), random.randint(1, 9))
118 result = self._call_api(domain_id, 'session/init', video_id, data={
119 'nxp_devh': device_id,
125 'playerversion': '6.0.00',
128 'explicitlanguage': 'en-US',
129 'addTextTemplates': '1',
130 'addDomainData': '1',
133 'X-Request-Enable-Auth-Fallback': '1',
136 cid = result['general']['cid']
138 # As described in [1] X-Request-Token generation algorithm is
140 # md5( operation + domain_id + domain_secret )
141 # where domain_secret is a static value that will be given by nexx.tv
142 # as per [1]. Here is how this "secret" is generated (reversed
143 # from _play.api.init function, search for clienttoken). So it's
144 # actually not static and not that much of a secret.
145 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
146 secret = result['device']['clienttoken'][int(device_id[0]):]
147 secret = secret[0:len(secret) - int(device_id[-1])]
151 # Reversed from JS code for _play.api.call function (search for
153 request_token = hashlib.md5(
154 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
156 video = self._call_api(
157 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
158 'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description',
159 'addInteractionOptions': '1',
160 'addStatusDetails': '1',
161 'addStreamDetails': '1',
166 'captionFormat': 'data',
168 'X-Request-CID': cid,
169 'X-Request-Token': request_token,
172 general = video['general']
173 title = general['title']
175 stream_data = video['streamdata']
176 language = general.get('language_raw') or ''
178 # TODO: reverse more cdns and formats
180 cdn = stream_data['cdnType']
181 assert cdn == 'azure'
183 azure_locator = stream_data['azureLocator']
185 AZURE_URL = 'http://nx-p%02d.akamaized.net/'
187 for secure in ('s', ''):
188 cdn_shield = stream_data.get('cdnShieldHTTP%s' % secure.upper())
190 azure_base = 'http%s://%s' % (secure, cdn_shield)
193 azure_base = AZURE_URL % int(stream_data['azureAccount'].replace('nexxplayplus', ''))
195 is_ml = ',' in language
196 azure_m3u8_url = '%s%s/%s_src%s.ism/Manifest(format=m3u8-aapl)' % (
197 azure_base, azure_locator, video_id, ('_manifest' if is_ml else ''))
199 protection_token = try_get(
200 video, lambda x: x['protectiondata']['token'], compat_str)
202 azure_m3u8_url += '?hdnts=%s' % protection_token
204 formats = self._extract_m3u8_formats(
205 azure_m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
206 m3u8_id='%s-hls' % cdn)
207 self._sort_formats(formats)
212 'alt_title': general.get('subtitle'),
213 'description': general.get('description'),
214 'release_year': int_or_none(general.get('year')),
215 'creator': general.get('studio') or general.get('studio_adref'),
216 'thumbnail': try_get(
217 video, lambda x: x['imagedata']['thumb'], compat_str),
218 'duration': parse_duration(general.get('runtime')),
219 'timestamp': int_or_none(general.get('uploaded')),
220 'episode_number': int_or_none(try_get(
221 video, lambda x: x['episodedata']['episode'])),
222 'season_number': int_or_none(try_get(
223 video, lambda x: x['episodedata']['season'])),