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/|
20 https?://arc\.nexx\.cloud/api/video/
26 'url': 'https://api.nexx.cloud/v3/748/videos/byid/128907',
27 'md5': '828cea195be04e66057b846288295ba1',
31 'title': 'Stiftung Warentest',
32 'alt_title': 'Wie ein Test abläuft',
33 'description': 'md5:d1ddb1ef63de721132abd38639cc2fd2',
35 'creator': 'SPIEGEL TV',
36 'thumbnail': r're:^https?://.*\.jpg$',
38 'timestamp': 1384264416,
39 'upload_date': '20131112',
43 'url': 'https://api.nexx.cloud/v3/741/videos/byid/247858',
47 'title': 'Return of the Golden Child (OV)',
48 'description': 'md5:5d969537509a92b733de21bae249dc63',
50 'thumbnail': r're:^https?://.*\.jpg$',
52 'timestamp': 1495033267,
53 'upload_date': '20170517',
58 'skip_download': True,
61 'url': 'https://api.nexxcdn.com/v3/748/videos/byid/128907',
62 'only_matching': True,
64 'url': 'nexx:748:128907',
65 'only_matching': True,
68 'only_matching': True,
70 'url': 'https://arc.nexx.cloud/api/video/128907.json',
71 'only_matching': True,
75 def _extract_domain_id(webpage):
77 r'<script\b[^>]+\bsrc=["\'](?:https?:)?//require\.nexx(?:\.cloud|cdn\.com)/(?P<id>\d+)',
79 return mobj.group('id') if mobj else None
82 def _extract_urls(webpage):
84 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
88 # JavaScript Integration
89 domain_id = NexxIE._extract_domain_id(webpage)
91 for video_id in re.findall(
92 r'(?is)onPLAYReady.+?_play\.init\s*\(.+?\s*,\s*["\']?(\d+)',
95 'https://api.nexx.cloud/v3/%s/videos/byid/%s'
96 % (domain_id, video_id))
98 # TODO: support more embed formats
103 def _extract_url(webpage):
104 return NexxIE._extract_urls(webpage)[0]
106 def _real_extract(self, url):
107 video_id = self._match_id(url)
109 video = self._download_json(
110 'https://arc.nexx.cloud/api/video/%s.json' % video_id,
113 general = video['general']
114 title = general['title']
116 stream_data = video['streamdata']
117 language = general.get('language_raw') or ''
119 # TODO: reverse more cdns
121 cdn = stream_data['cdnType']
122 assert cdn == 'azure'
124 azure_locator = stream_data['azureLocator']
126 AZURE_URL = 'http://nx%s%02d.akamaized.net/'
128 def get_cdn_shield_base(shield_type='', prefix='-p'):
129 for secure in ('', 's'):
130 cdn_shield = stream_data.get('cdnShield%sHTTP%s' % (shield_type, secure.upper()))
132 return 'http%s://%s' % (secure, cdn_shield)
134 return AZURE_URL % (prefix, int(stream_data['azureAccount'].replace('nexxplayplus', '')))
136 azure_stream_base = get_cdn_shield_base()
137 is_ml = ',' in language
138 azure_manifest_url = '%s%s/%s_src%s.ism/Manifest' % (
139 azure_stream_base, azure_locator, video_id, ('_manifest' if is_ml else '')) + '%s'
141 protection_token = try_get(
142 video, lambda x: x['protectiondata']['token'], compat_str)
144 azure_manifest_url += '?hdnts=%s' % protection_token
146 formats = self._extract_m3u8_formats(
147 azure_manifest_url % '(format=m3u8-aapl)',
148 video_id, 'mp4', 'm3u8_native',
149 m3u8_id='%s-hls' % cdn, fatal=False)
150 formats.extend(self._extract_mpd_formats(
151 azure_manifest_url % '(format=mpd-time-csf)',
152 video_id, mpd_id='%s-dash' % cdn, fatal=False))
153 formats.extend(self._extract_ism_formats(
154 azure_manifest_url % '', video_id, ism_id='%s-mss' % cdn, fatal=False))
156 azure_progressive_base = get_cdn_shield_base('Prog', '-d')
157 azure_file_distribution = stream_data.get('azureFileDistribution')
158 if azure_file_distribution:
159 fds = azure_file_distribution.split(',')
164 tbr = int_or_none(ss[0])
167 'url': '%s%s/%s_src_%s_%d.mp4' % (
168 azure_progressive_base, azure_locator, video_id, ss[1], tbr),
169 'format_id': '%s-http-%d' % (cdn, tbr),
172 width_height = ss[1].split('x')
173 if len(width_height) == 2:
175 'width': int_or_none(width_height[0]),
176 'height': int_or_none(width_height[1]),
180 self._sort_formats(formats)
185 'alt_title': general.get('subtitle'),
186 'description': general.get('description'),
187 'release_year': int_or_none(general.get('year')),
188 'creator': general.get('studio') or general.get('studio_adref'),
189 'thumbnail': try_get(
190 video, lambda x: x['imagedata']['thumb'], compat_str),
191 'duration': parse_duration(general.get('runtime')),
192 'timestamp': int_or_none(general.get('uploaded')),
193 'episode_number': int_or_none(try_get(
194 video, lambda x: x['episodedata']['episode'])),
195 'season_number': int_or_none(try_get(
196 video, lambda x: x['episodedata']['season'])),
201 class NexxEmbedIE(InfoExtractor):
202 _VALID_URL = r'https?://embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?P<id>[^/?#&]+)'
204 'url': 'http://embed.nexx.cloud/748/KC1614647Z27Y7T?autoplay=1',
205 'md5': '16746bfc28c42049492385c989b26c4a',
209 'title': 'Nervenkitzel Achterbahn',
210 'alt_title': 'Karussellbauer in Deutschland',
211 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
212 'release_year': 2005,
213 'creator': 'SPIEGEL TV',
214 'thumbnail': r're:^https?://.*\.jpg$',
216 'timestamp': 1394021479,
217 'upload_date': '20140305',
220 'format': 'bestvideo',
221 'skip_download': True,
226 def _extract_urls(webpage):
228 # 1. https://nx-s.akamaized.net/files/201510/44.pdf
230 # iFrame Embed Integration
231 return [mobj.group('url') for mobj in re.finditer(
232 r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//embed\.nexx(?:\.cloud|cdn\.com)/\d+/(?:(?!\1).)+)\1',
235 def _real_extract(self, url):
236 embed_id = self._match_id(url)
238 webpage = self._download_webpage(url, embed_id)
240 return self.url_result(NexxIE._extract_url(webpage), ie=NexxIE.ie_key())