]>
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+):
30 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
31 'md5': '16746bfc28c42049492385c989b26c4a',
35 'title': 'Stiftung Warentest',
36 'alt_title': 'Wie ein Test abläuft',
37 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
39 'creator': 'SPIEGEL TV',
40 'thumbnail': r
're:^https?://.*\.jpg$',
42 'timestamp': 1384264416,
43 'upload_date': '20131112',
46 'format': 'bestvideo',
50 'url': 'https://api.nexx.cloud/v3/741/videos/byid/247858',
54 'title': 'Return of the Golden Child (OV)',
55 'description': 'md5:5d969537509a92b733de21bae249dc63',
57 'thumbnail': r
're:^https?://.*\.jpg$',
59 'timestamp': 1495033267,
60 'upload_date': '20170517',
65 'format': 'bestvideo',
66 'skip_download': True,
69 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
70 'only_matching': True,
72 'url': 'nexx:748:128907',
73 'only_matching': True,
77 def _extract_domain_id(webpage
):
79 r
'<script\b[^>]+\bsrc=["\'](?
:https?
:)?
//require\
.nexx(?
:\
.cloud|cdn\
.com
)/(?P
<id>\d
+)',
81 return mobj.group('id') if mobj else None
84 def _extract_urls(webpage):
86 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
90 # JavaScript Integration
91 domain_id = NexxIE._extract_domain_id(webpage)
93 for video_id in re.findall(
94 r'(?
is)onPLAYReady
.+?_play\
.init\s
*\
(.+?\s
*,\s
*["\']?(\d+)',
97 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
98 % (domain_id, video_id))
100 # TODO: support more embed formats
105 def _extract_url(webpage):
106 return NexxIE._extract_urls(webpage)[0]
108 def _handle_error(self, response):
109 status = int_or_none(try_get(
110 response, lambda x: x['metadata']['status']) or 200)
111 if 200 <= status < 300:
113 raise ExtractorError(
114 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
117 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
118 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
119 result = self._download_json(
120 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
121 'Downloading %s JSON' % path, data=urlencode_postdata(data),
123 self._handle_error(result)
124 return result['result']
126 def _real_extract(self, url):
127 mobj = re.match(self._VALID_URL, url)
128 domain_id = mobj.group('domain_id') or mobj.group('domain_id_s')
129 video_id = mobj.group('id')
131 # Reverse engineered from JS code (see getDeviceID function)
132 device_id = '%d:%d:%d%d' % (
133 random.randint(1, 4), int(time.time()),
134 random.randint(1e4, 99999), random.randint(1, 9))
136 result = self._call_api(domain_id, 'session/init', video_id, data={
137 'nxp_devh': device_id,
143 'playerversion': '6.0.00',
146 'explicitlanguage': 'en-US',
147 'addTextTemplates': '1',
148 'addDomainData': '1',
151 'X-Request-Enable-Auth-Fallback': '1',
154 cid = result['general']['cid']
156 # As described in [1] X-Request-Token generation algorithm is
158 # md5( operation + domain_id + domain_secret )
159 # where domain_secret is a static value that will be given by nexx.tv
160 # as per [1]. Here is how this "secret
" is generated (reversed
161 # from _play.api.init function, search for clienttoken). So it's
162 # actually not static and not that much of a secret.
163 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
164 secret = result['device']['clienttoken'][int(device_id[0]):]
165 secret = secret[0:len(secret) - int(device_id[-1])]
169 # Reversed from JS code for _play.api.call function (search for
171 request_token = hashlib.md5(
172 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
174 video = self._call_api(
175 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
176 'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description',
177 'addInteractionOptions': '1',
178 'addStatusDetails': '1',
179 'addStreamDetails': '1',
184 'captionFormat': 'data',
186 'X-Request-CID': cid,
187 'X-Request-Token': request_token,
190 general = video['general']
191 title = general['title']
193 stream_data = video['streamdata']
194 language = general.get('language_raw') or ''
196 # TODO: reverse more cdns and formats
198 cdn = stream_data['cdnType']
199 assert cdn == 'azure'
201 azure_locator = stream_data['azureLocator']
203 AZURE_URL = 'http://nx-p%02d.akamaized.net/'
205 for secure in ('s', ''):
206 cdn_shield = stream_data.get('cdnShieldHTTP%s' % secure.upper())
208 azure_base = 'http%s://%s' % (secure, cdn_shield)
211 azure_base = AZURE_URL % int(stream_data['azureAccount'].replace('nexxplayplus', ''))
213 is_ml = ',' in language
214 azure_m3u8_url = '%s%s/%s_src%s.ism/Manifest(format=m3u8-aapl)' % (
215 azure_base, azure_locator, video_id, ('_manifest' if is_ml else ''))
217 protection_token = try_get(
218 video, lambda x: x['protectiondata']['token'], compat_str)
220 azure_m3u8_url += '?hdnts=%s' % protection_token
222 formats = self._extract_m3u8_formats(
223 azure_m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
224 m3u8_id='%s-hls' % cdn)
225 self._sort_formats(formats)
230 'alt_title': general.get('subtitle'),
231 'description': general.get('description'),
232 'release_year': int_or_none(general.get('year')),
233 'creator': general.get('studio') or general.get('studio_adref'),
234 'thumbnail': try_get(
235 video, lambda x: x['imagedata']['thumb'], compat_str),
236 'duration': parse_duration(general.get('runtime')),
237 'timestamp': int_or_none(general.get('uploaded')),
238 'episode_number': int_or_none(try_get(
239 video, lambda x: x['episodedata']['episode'])),
240 'season_number': int_or_none(try_get(
241 video, lambda x: x['episodedata']['season'])),
246 class NexxEmbedIE(InfoExtractor):
247 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?P<id>[^/?#&]+)'
249 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
250 'md5': '16746bfc28c42049492385c989b26c4a',
254 'title': 'Nervenkitzel Achterbahn',
255 'alt_title': 'Karussellbauer in Deutschland',
256 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
257 'release_year': 2005,
258 'creator': 'SPIEGEL TV',
259 'thumbnail': r're:^https?://.*\.jpg$',
261 'timestamp': 1394021479,
262 'upload_date': '20140305',
265 'format': 'bestvideo',
266 'skip_download': True,
271 def _extract_urls(webpage):
273 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
275 # iFrame Embed Integration
276 return [mobj.group('url') for mobj in re.finditer(
277 r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1',
280 def _real_extract(self, url):
281 embed_id = self._match_id(url)
283 webpage = self._download_webpage(url, embed_id)
285 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())