]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nexx.py
d0235fdfe97cba28049ee3e9f6ba8415ff450989
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
92 def _extract_url(webpage):
93 return NexxIE._extract_urls(webpage)[0]
95 def _handle_error(self, response):
96 status = int_or_none(try_get(
97 response, lambda x: x['metadata']['status']) or 200)
98 if 200 <= status < 300:
100 raise ExtractorError(
101 '%s said: %s' % (self.IE_NAME, response['metadata']['errorhint']),
104 def _call_api(self, domain_id, path, video_id, data=None, headers={}):
105 headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
106 result = self._download_json(
107 'https://api.nexx.cloud/v3/%s/%s' % (domain_id, path), video_id,
108 'Downloading %s JSON' % path, data=urlencode_postdata(data),
110 self._handle_error(result)
111 return result['result']
113 def _real_extract(self, url):
114 mobj = re.match(self._VALID_URL, url)
115 domain_id, video_id = mobj.group('domain_id', 'id')
117 # Reverse engineered from JS code (see getDeviceID function)
118 device_id = '%d:%d:%d%d' % (
119 random.randint(1, 4), int(time.time()),
120 random.randint(1e4, 99999), random.randint(1, 9))
122 result = self._call_api(domain_id, 'session/init', video_id, data={
123 'nxp_devh': device_id,
129 'playerversion': '6.0.00',
132 'explicitlanguage': 'en-US',
133 'addTextTemplates': '1',
134 'addDomainData': '1',
137 'X-Request-Enable-Auth-Fallback': '1',
140 cid = result['general']['cid']
142 # As described in [1] X-Request-Token generation algorithm is
144 # md5( operation + domain_id + domain_secret )
145 # where domain_secret is a static value that will be given by nexx.tv
146 # as per [1]. Here is how this "secret
" is generated (reversed
147 # from _play.api.init function, search for clienttoken). So it's
148 # actually not static and not that much of a secret.
149 # 1. https://nexxtvstorage.blob.core.windows.net/files/201610/27.pdf
150 secret = result['device']['clienttoken'][int(device_id[0]):]
151 secret = secret[0:len(secret) - int(device_id[-1])]
155 # Reversed from JS code for _play.api.call function (search for
157 request_token = hashlib.md5(
158 ''.join((op, domain_id, secret)).encode('utf-8')).hexdigest()
160 video = self._call_api(
161 domain_id, 'videos/%s/%s' % (op, video_id), video_id, data={
162 'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description',
163 'addInteractionOptions': '1',
164 'addStatusDetails': '1',
165 'addStreamDetails': '1',
170 'captionFormat': 'data',
172 'X-Request-CID': cid,
173 'X-Request-Token': request_token,
176 general = video['general']
177 title = general['title']
179 stream_data = video['streamdata']
180 language = general.get('language_raw') or ''
182 # TODO: reverse more cdns and formats
184 cdn = stream_data['cdnType']
185 assert cdn == 'azure'
187 azure_locator = stream_data['azureLocator']
189 AZURE_URL = 'http://nx-p%02d.akamaized.net/'
191 for secure in ('s', ''):
192 cdn_shield = stream_data.get('cdnShieldHTTP%s' % secure.upper())
194 azure_base = 'http%s://%s' % (secure, cdn_shield)
197 azure_base = AZURE_URL % int(stream_data['azureAccount'].replace('nexxplayplus', ''))
199 is_ml = ',' in language
200 azure_m3u8_url = '%s%s/%s_src%s.ism/Manifest(format=m3u8-aapl)' % (
201 azure_base, azure_locator, video_id, ('_manifest' if is_ml else ''))
203 protection_token = try_get(
204 video, lambda x: x['protectiondata']['token'], compat_str)
206 azure_m3u8_url += '?hdnts=%s' % protection_token
208 formats = self._extract_m3u8_formats(
209 azure_m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
210 m3u8_id='%s-hls' % cdn)
211 self._sort_formats(formats)
216 'alt_title': general.get('subtitle'),
217 'description': general.get('description'),
218 'release_year': int_or_none(general.get('year')),
219 'creator': general.get('studio') or general.get('studio_adref'),
220 'thumbnail': try_get(
221 video, lambda x: x['imagedata']['thumb'], compat_str),
222 'duration': parse_duration(general.get('runtime')),
223 'timestamp': int_or_none(general.get('uploaded')),
224 'episode_number': int_or_none(try_get(
225 video, lambda x: x['episodedata']['episode'])),
226 'season_number': int_or_none(try_get(
227 video, lambda x: x['episodedata']['season'])),
232 class NexxEmbedIE(InfoExtractor):
233 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?P<id>[^/?#&]+)'
235 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
236 'md5': '16746bfc28c42049492385c989b26c4a',
240 'title': 'Nervenkitzel Achterbahn',
241 'alt_title': 'Karussellbauer in Deutschland',
242 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
243 'release_year': 2005,
244 'creator': 'SPIEGEL TV',
245 'thumbnail': r're:^https?://.*\.jpg$',
247 'timestamp': 1394021479,
248 'upload_date': '20140305',
251 'format': 'bestvideo',
252 'skip_download': True,
257 def _extract_urls(webpage):
259 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
261 # iFrame Embed Integration
262 return [mobj.group('url') for mobj in re.finditer(
263 r'<iframe[^>]+\bsrc=(["\'])(?P
<url
>(?
:https?
:)?
//embed\
.nexx(?
:\
.cloud|cdn\
.com
)/\d
+/(?
:(?
!\
1).)+)\
1',
266 def _real_extract(self, url):
267 embed_id = self._match_id(url)
269 webpage = self._download_webpage(url, embed_id)
271 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())