2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
15 class NexxIE(InfoExtractor):
18 https?://api\.nexx(?:\.cloud|cdn\.com)/v3/\d+/videos/byid/|
25 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
26 'md5': '828cea195be04e66057b846288295ba1',
30 'title': 'Stiftung Warentest',
31 'alt_title': 'Wie ein Test abläuft',
32 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
34 'creator': 'SPIEGEL TV',
35 'thumbnail': r're:^https?://.*\.jpg$',
37 'timestamp': 1384264416,
38 'upload_date': '20131112',
42 'url': 'https://api.nexx.cloud/v3/741/videos/byid/247858',
46 'title': 'Return of the Golden Child (OV)',
47 'description': 'md5:5d969537509a92b733de21bae249dc63',
49 'thumbnail': r're:^https?://.*\.jpg$',
51 'timestamp': 1495033267,
52 'upload_date': '20170517',
57 'skip_download': True,
60 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
61 'only_matching': True,
63 'url': 'nexx:748:128907',
64 'only_matching': True,
67 'only_matching': True,
71 def _extract_domain_id(webpage):
73 r'<script\b[^>]+\bsrc=["\'](?:https?:)?//require\.nexx(?:\.cloud|cdn\.com)/(?P<id>\d+)',
75 return mobj.group('id') if mobj else None
78 def _extract_urls(webpage):
80 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
84 # JavaScript Integration
85 domain_id = NexxIE._extract_domain_id(webpage)
87 for video_id in re.findall(
88 r'(?is)onPLAYReady.+?_play\.init\s*\(.+?\s*,\s*["\']?(\d+)',
91 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
92 % (domain_id, video_id))
94 # TODO: support more embed formats
99 def _extract_url(webpage):
100 return NexxIE._extract_urls(webpage)[0]
102 def _real_extract(self, url):
103 video_id = self._match_id(url)
105 video = self._download_json(
106 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
109 general = video['general']
110 title = general['title']
112 stream_data = video['streamdata']
113 language = general.get('language_raw') or ''
115 # TODO: reverse more cdns
117 cdn = stream_data['cdnType']
118 assert cdn == 'azure'
120 azure_locator = stream_data['azureLocator']
122 AZURE_URL = 'http://nx%s%02d.akamaized.net/'
124 def get_cdn_shield_base(shield_type='', prefix='-p'):
125 for secure in ('', 's'):
126 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
128 return 'http%s://%s' % (secure, cdn_shield)
130 return AZURE_URL % (prefix, int(stream_data['azureAccount'].replace('nexxplayplus', '')))
132 azure_stream_base = get_cdn_shield_base()
133 is_ml = ',' in language
134 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
135 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
137 protection_token = try_get(
138 video, lambda x: x['protectiondata']['token'], compat_str)
140 azure_manifest_url += '?hdnts=%s' % protection_token
142 formats = self._extract_m3u8_formats(
143 azure_manifest_url % '(format=m3u8-aapl)',
144 video_id, 'mp4', 'm3u8_native',
145 m3u8_id='%s-hls' % cdn, fatal=False)
146 formats.extend(self._extract_mpd_formats(
147 azure_manifest_url % '(format=mpd-time-csf)',
148 video_id, mpd_id='%s-dash' % cdn, fatal=False))
149 formats.extend(self._extract_ism_formats(
150 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
152 azure_progressive_base = get_cdn_shield_base('Prog', '-d')
153 azure_file_distribution = stream_data.get('azureFileDistribution')
154 if azure_file_distribution:
155 fds = azure_file_distribution.split(',')
160 tbr = int_or_none(ss[0])
163 'url': '%s%s/%s_src_%s_%d.mp4' % (
164 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
165 'format_id': '%s-http-%d' % (cdn, tbr),
168 width_height = ss[1].split('x')
169 if len(width_height) == 2:
171 'width': int_or_none(width_height[0]),
172 'height': int_or_none(width_height[1]),
176 self._sort_formats(formats)
181 'alt_title': general.get('subtitle'),
182 'description': general.get('description'),
183 'release_year': int_or_none(general.get('year')),
184 'creator': general.get('studio') or general.get('studio_adref'),
185 'thumbnail': try_get(
186 video, lambda x: x['imagedata']['thumb'], compat_str),
187 'duration': parse_duration(general.get('runtime')),
188 'timestamp': int_or_none(general.get('uploaded')),
189 'episode_number': int_or_none(try_get(
190 video, lambda x: x['episodedata']['episode'])),
191 'season_number': int_or_none(try_get(
192 video, lambda x: x['episodedata']['season'])),
197 class NexxEmbedIE(InfoExtractor):
198 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?P<id>[^/?#&]+)'
200 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
201 'md5': '16746bfc28c42049492385c989b26c4a',
205 'title': 'Nervenkitzel Achterbahn',
206 'alt_title': 'Karussellbauer in Deutschland',
207 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
208 'release_year': 2005,
209 'creator': 'SPIEGEL TV',
210 'thumbnail': r're:^https?://.*\.jpg$',
212 'timestamp': 1394021479,
213 'upload_date': '20140305',
216 'format': 'bestvideo',
217 'skip_download': True,
222 def _extract_urls(webpage):
224 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
226 # iFrame Embed Integration
227 return [mobj.group('url') for mobj in re.finditer(
228 r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?:(?!\1).)+)\1',
231 def _real_extract(self, url):
232 embed_id = self._match_id(url)
234 webpage = self._download_webpage(url, embed_id)
236 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())