]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ndr.py
Import Upstream version 2020.01.24
[youtubedl] / youtube_dl / extractor / ndr.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 determine_ext,
9 int_or_none,
10 parse_iso8601,
11 qualities,
12 try_get,
13 urljoin,
14 )
15
16
17 class NDRBaseIE(InfoExtractor):
18 def _real_extract(self, url):
19 mobj = re.match(self._VALID_URL, url)
20 display_id = next(group for group in mobj.groups() if group)
21 webpage = self._download_webpage(url, display_id)
22 return self._extract_embed(webpage, display_id)
23
24
25 class NDRIE(NDRBaseIE):
26 IE_NAME = 'ndr'
27 IE_DESC = 'NDR.de - Norddeutscher Rundfunk'
28 _VALID_URL = r'https?://(?:www\.)?ndr\.de/(?:[^/]+/)*(?P<id>[^/?#]+),[\da-z]+\.html'
29 _TESTS = [{
30 # httpVideo, same content id
31 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
32 'md5': '6515bc255dc5c5f8c85bbc38e035a659',
33 'info_dict': {
34 'id': 'hafengeburtstag988',
35 'display_id': 'Party-Poette-und-Parade',
36 'ext': 'mp4',
37 'title': 'Party, Pötte und Parade',
38 'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c',
39 'uploader': 'ndrtv',
40 'timestamp': 1431108900,
41 'upload_date': '20150510',
42 'duration': 3498,
43 },
44 'params': {
45 'skip_download': True,
46 },
47 }, {
48 # httpVideo, different content id
49 'url': 'http://www.ndr.de/sport/fussball/40-Osnabrueck-spielt-sich-in-einen-Rausch,osna270.html',
50 'md5': '1043ff203eab307f0c51702ec49e9a71',
51 'info_dict': {
52 'id': 'osna272',
53 'display_id': '40-Osnabrueck-spielt-sich-in-einen-Rausch',
54 'ext': 'mp4',
55 'title': 'Osnabrück - Wehen Wiesbaden: Die Highlights',
56 'description': 'md5:32e9b800b3d2d4008103752682d5dc01',
57 'uploader': 'ndrtv',
58 'timestamp': 1442059200,
59 'upload_date': '20150912',
60 'duration': 510,
61 },
62 'params': {
63 'skip_download': True,
64 },
65 }, {
66 # httpAudio, same content id
67 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
68 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
69 'info_dict': {
70 'id': 'audio51535',
71 'display_id': 'La-Valette-entgeht-der-Hinrichtung',
72 'ext': 'mp3',
73 'title': 'La Valette entgeht der Hinrichtung',
74 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
75 'uploader': 'ndrinfo',
76 'timestamp': 1290626100,
77 'upload_date': '20140729',
78 'duration': 884,
79 },
80 'params': {
81 'skip_download': True,
82 },
83 }, {
84 'url': 'https://www.ndr.de/Fettes-Brot-Ferris-MC-und-Thees-Uhlmann-live-on-stage,festivalsommer116.html',
85 'only_matching': True,
86 }]
87
88 def _extract_embed(self, webpage, display_id):
89 embed_url = self._html_search_meta(
90 'embedURL', webpage, 'embed URL', fatal=True)
91 description = self._search_regex(
92 r'<p[^>]+itemprop="description">([^<]+)</p>',
93 webpage, 'description', default=None) or self._og_search_description(webpage)
94 timestamp = parse_iso8601(
95 self._search_regex(
96 r'<span[^>]+itemprop="(?:datePublished|uploadDate)"[^>]+content="([^"]+)"',
97 webpage, 'upload date', fatal=False))
98 return {
99 '_type': 'url_transparent',
100 'url': embed_url,
101 'display_id': display_id,
102 'description': description,
103 'timestamp': timestamp,
104 }
105
106
107 class NJoyIE(NDRBaseIE):
108 IE_NAME = 'njoy'
109 IE_DESC = 'N-JOY'
110 _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?:(?P<display_id>[^/?#]+),)?(?P<id>[\da-z]+)\.html'
111 _TESTS = [{
112 # httpVideo, same content id
113 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
114 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
115 'info_dict': {
116 'id': 'comedycontest2480',
117 'display_id': 'Benaissa-beim-NDR-Comedy-Contest',
118 'ext': 'mp4',
119 'title': 'Benaissa beim NDR Comedy Contest',
120 'description': 'md5:f057a6c4e1c728b10d33b5ffd36ddc39',
121 'uploader': 'ndrtv',
122 'upload_date': '20141129',
123 'duration': 654,
124 },
125 'params': {
126 'skip_download': True,
127 },
128 }, {
129 # httpVideo, different content id
130 'url': 'http://www.n-joy.de/musik/Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-,felixjaehn168.html',
131 'md5': '417660fffa90e6df2fda19f1b40a64d8',
132 'info_dict': {
133 'id': 'dockville882',
134 'display_id': 'Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-',
135 'ext': 'mp4',
136 'title': '"Ich hab noch nie" mit Felix Jaehn',
137 'description': 'md5:85dd312d53be1b99e1f998a16452a2f3',
138 'uploader': 'njoy',
139 'upload_date': '20150822',
140 'duration': 211,
141 },
142 'params': {
143 'skip_download': True,
144 },
145 }, {
146 'url': 'http://www.n-joy.de/radio/webradio/morningshow209.html',
147 'only_matching': True,
148 }]
149
150 def _extract_embed(self, webpage, display_id):
151 video_id = self._search_regex(
152 r'<iframe[^>]+id="pp_([\da-z]+)"', webpage, 'embed id')
153 description = self._search_regex(
154 r'<div[^>]+class="subline"[^>]*>[^<]+</div>\s*<p>([^<]+)</p>',
155 webpage, 'description', fatal=False)
156 return {
157 '_type': 'url_transparent',
158 'ie_key': 'NDREmbedBase',
159 'url': 'ndr:%s' % video_id,
160 'display_id': display_id,
161 'description': description,
162 }
163
164
165 class NDREmbedBaseIE(InfoExtractor):
166 IE_NAME = 'ndr:embed:base'
167 _VALID_URL = r'(?:ndr:(?P<id_s>[\da-z]+)|https?://www\.ndr\.de/(?P<id>[\da-z]+)-ppjson\.json)'
168 _TESTS = [{
169 'url': 'ndr:soundcheck3366',
170 'only_matching': True,
171 }, {
172 'url': 'http://www.ndr.de/soundcheck3366-ppjson.json',
173 'only_matching': True,
174 }]
175
176 def _real_extract(self, url):
177 mobj = re.match(self._VALID_URL, url)
178 video_id = mobj.group('id') or mobj.group('id_s')
179
180 ppjson = self._download_json(
181 'http://www.ndr.de/%s-ppjson.json' % video_id, video_id)
182
183 playlist = ppjson['playlist']
184
185 formats = []
186 quality_key = qualities(('xs', 's', 'm', 'l', 'xl'))
187
188 for format_id, f in playlist.items():
189 src = f.get('src')
190 if not src:
191 continue
192 ext = determine_ext(src, None)
193 if ext == 'f4m':
194 formats.extend(self._extract_f4m_formats(
195 src + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
196 f4m_id='hds', fatal=False))
197 elif ext == 'm3u8':
198 formats.extend(self._extract_m3u8_formats(
199 src, video_id, 'mp4', m3u8_id='hls',
200 entry_protocol='m3u8_native', fatal=False))
201 else:
202 quality = f.get('quality')
203 ff = {
204 'url': src,
205 'format_id': quality or format_id,
206 'quality': quality_key(quality),
207 }
208 type_ = f.get('type')
209 if type_ and type_.split('/')[0] == 'audio':
210 ff['vcodec'] = 'none'
211 ff['ext'] = ext or 'mp3'
212 formats.append(ff)
213 self._sort_formats(formats)
214
215 config = playlist['config']
216
217 live = playlist.get('config', {}).get('streamType') in ['httpVideoLive', 'httpAudioLive']
218 title = config['title']
219 if live:
220 title = self._live_title(title)
221 uploader = ppjson.get('config', {}).get('branding')
222 upload_date = ppjson.get('config', {}).get('publicationDate')
223 duration = int_or_none(config.get('duration'))
224
225 thumbnails = []
226 poster = try_get(config, lambda x: x['poster'], dict) or {}
227 for thumbnail_id, thumbnail in poster.items():
228 thumbnail_url = urljoin(url, thumbnail.get('src'))
229 if not thumbnail_url:
230 continue
231 thumbnails.append({
232 'id': thumbnail.get('quality') or thumbnail_id,
233 'url': thumbnail_url,
234 'preference': quality_key(thumbnail.get('quality')),
235 })
236
237 return {
238 'id': video_id,
239 'title': title,
240 'is_live': live,
241 'uploader': uploader if uploader != '-' else None,
242 'upload_date': upload_date[0:8] if upload_date else None,
243 'duration': duration,
244 'thumbnails': thumbnails,
245 'formats': formats,
246 }
247
248
249 class NDREmbedIE(NDREmbedBaseIE):
250 IE_NAME = 'ndr:embed'
251 _VALID_URL = r'https?://(?:www\.)?ndr\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)\.html'
252 _TESTS = [{
253 'url': 'http://www.ndr.de/fernsehen/sendungen/ndr_aktuell/ndraktuell28488-player.html',
254 'md5': '8b9306142fe65bbdefb5ce24edb6b0a9',
255 'info_dict': {
256 'id': 'ndraktuell28488',
257 'ext': 'mp4',
258 'title': 'Norddeutschland begrüßt Flüchtlinge',
259 'is_live': False,
260 'uploader': 'ndrtv',
261 'upload_date': '20150907',
262 'duration': 132,
263 },
264 }, {
265 'url': 'http://www.ndr.de/ndr2/events/soundcheck/soundcheck3366-player.html',
266 'md5': '002085c44bae38802d94ae5802a36e78',
267 'info_dict': {
268 'id': 'soundcheck3366',
269 'ext': 'mp4',
270 'title': 'Ella Henderson braucht Vergleiche nicht zu scheuen',
271 'is_live': False,
272 'uploader': 'ndr2',
273 'upload_date': '20150912',
274 'duration': 3554,
275 },
276 'params': {
277 'skip_download': True,
278 },
279 }, {
280 'url': 'http://www.ndr.de/info/audio51535-player.html',
281 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
282 'info_dict': {
283 'id': 'audio51535',
284 'ext': 'mp3',
285 'title': 'La Valette entgeht der Hinrichtung',
286 'is_live': False,
287 'uploader': 'ndrinfo',
288 'upload_date': '20140729',
289 'duration': 884,
290 },
291 'params': {
292 'skip_download': True,
293 },
294 }, {
295 'url': 'http://www.ndr.de/fernsehen/sendungen/visite/visite11010-externalPlayer.html',
296 'md5': 'ae57f80511c1e1f2fd0d0d3d31aeae7c',
297 'info_dict': {
298 'id': 'visite11010',
299 'ext': 'mp4',
300 'title': 'Visite - die ganze Sendung',
301 'is_live': False,
302 'uploader': 'ndrtv',
303 'upload_date': '20150902',
304 'duration': 3525,
305 },
306 'params': {
307 'skip_download': True,
308 },
309 }, {
310 # httpVideoLive
311 'url': 'http://www.ndr.de/fernsehen/livestream/livestream217-externalPlayer.html',
312 'info_dict': {
313 'id': 'livestream217',
314 'ext': 'flv',
315 'title': r're:^NDR Fernsehen Niedersachsen \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
316 'is_live': True,
317 'upload_date': '20150910',
318 },
319 'params': {
320 'skip_download': True,
321 },
322 }, {
323 'url': 'http://www.ndr.de/ndrkultur/audio255020-player.html',
324 'only_matching': True,
325 }, {
326 'url': 'http://www.ndr.de/fernsehen/sendungen/nordtour/nordtour7124-player.html',
327 'only_matching': True,
328 }, {
329 'url': 'http://www.ndr.de/kultur/film/videos/videoimport10424-player.html',
330 'only_matching': True,
331 }, {
332 'url': 'http://www.ndr.de/fernsehen/sendungen/hamburg_journal/hamj43006-player.html',
333 'only_matching': True,
334 }, {
335 'url': 'http://www.ndr.de/fernsehen/sendungen/weltbilder/weltbilder4518-player.html',
336 'only_matching': True,
337 }, {
338 'url': 'http://www.ndr.de/fernsehen/doku952-player.html',
339 'only_matching': True,
340 }]
341
342
343 class NJoyEmbedIE(NDREmbedBaseIE):
344 IE_NAME = 'njoy:embed'
345 _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)_[^/]+\.html'
346 _TESTS = [{
347 # httpVideo
348 'url': 'http://www.n-joy.de/events/reeperbahnfestival/doku948-player_image-bc168e87-5263-4d6d-bd27-bb643005a6de_theme-n-joy.html',
349 'md5': '8483cbfe2320bd4d28a349d62d88bd74',
350 'info_dict': {
351 'id': 'doku948',
352 'ext': 'mp4',
353 'title': 'Zehn Jahre Reeperbahn Festival - die Doku',
354 'is_live': False,
355 'upload_date': '20150807',
356 'duration': 1011,
357 },
358 }, {
359 # httpAudio
360 'url': 'http://www.n-joy.de/news_wissen/stefanrichter100-player_image-d5e938b1-f21a-4b9a-86b8-aaba8bca3a13_theme-n-joy.html',
361 'md5': 'd989f80f28ac954430f7b8a48197188a',
362 'info_dict': {
363 'id': 'stefanrichter100',
364 'ext': 'mp3',
365 'title': 'Interview mit einem Augenzeugen',
366 'is_live': False,
367 'uploader': 'njoy',
368 'upload_date': '20150909',
369 'duration': 140,
370 },
371 'params': {
372 'skip_download': True,
373 },
374 }, {
375 # httpAudioLive, no explicit ext
376 'url': 'http://www.n-joy.de/news_wissen/webradioweltweit100-player_image-3fec0484-2244-4565-8fb8-ed25fd28b173_theme-n-joy.html',
377 'info_dict': {
378 'id': 'webradioweltweit100',
379 'ext': 'mp3',
380 'title': r're:^N-JOY Weltweit \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
381 'is_live': True,
382 'uploader': 'njoy',
383 'upload_date': '20150810',
384 },
385 'params': {
386 'skip_download': True,
387 },
388 }, {
389 'url': 'http://www.n-joy.de/musik/dockville882-player_image-3905259e-0803-4764-ac72-8b7de077d80a_theme-n-joy.html',
390 'only_matching': True,
391 }, {
392 'url': 'http://www.n-joy.de/radio/sendungen/morningshow/urlaubsfotos190-player_image-066a5df1-5c95-49ec-a323-941d848718db_theme-n-joy.html',
393 'only_matching': True,
394 }, {
395 'url': 'http://www.n-joy.de/entertainment/comedy/krudetv290-player_image-ab261bfe-51bf-4bf3-87ba-c5122ee35b3d_theme-n-joy.html',
396 'only_matching': True,
397 }]