]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ndr.py
[extractor] Use classmethod/property where possible
[yt-dlp.git] / yt_dlp / extractor / ndr.py
CommitLineData
e9ea0bf1 1from .common import InfoExtractor
c1ed1f70 2from ..utils import (
2ffe3bc1 3 determine_ext,
c1ed1f70 4 int_or_none,
23dd2d9a 5 parse_duration,
376e1ad0 6 qualities,
3fc56635 7 try_get,
23dd2d9a 8 unified_strdate,
3fc56635 9 urljoin,
c1ed1f70 10)
e9ea0bf1
S
11
12
1934f3a0 13class NDRBaseIE(InfoExtractor):
64997815 14 def _real_extract(self, url):
5ad28e7f 15 mobj = self._match_valid_url(url)
7e0dc613 16 display_id = next(group for group in mobj.groups() if group)
dc9d8f44 17 id = mobj.group('id')
2ffe3bc1 18 webpage = self._download_webpage(url, display_id)
dc9d8f44 19 return self._extract_embed(webpage, display_id, id)
64997815 20
1934f3a0
YCH
21
22class NDRIE(NDRBaseIE):
23 IE_NAME = 'ndr'
2ffe3bc1 24 IE_DESC = 'NDR.de - Norddeutscher Rundfunk'
dc9d8f44 25 _VALID_URL = r'https?://(?:www\.)?(?:daserste\.)?ndr\.de/(?:[^/]+/)*(?P<display_id>[^/?#]+),(?P<id>[\da-z]+)\.html'
2ffe3bc1 26 _TESTS = [{
2ffe3bc1 27 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
2ffe3bc1
S
28 'info_dict': {
29 'id': 'hafengeburtstag988',
2ffe3bc1
S
30 'ext': 'mp4',
31 'title': 'Party, Pötte und Parade',
23dd2d9a 32 'thumbnail': 'https://www.ndr.de/fernsehen/hafengeburtstag990_v-contentxl.jpg',
2ffe3bc1 33 'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c',
23dd2d9a
AG
34 'series': None,
35 'channel': 'NDR Fernsehen',
36 'upload_date': '20150508',
2ffe3bc1
S
37 'duration': 3498,
38 },
2ffe3bc1 39 }, {
23dd2d9a
AG
40 'url': 'https://www.ndr.de/sport/fussball/Rostocks-Matchwinner-Froede-Ein-Hansa-Debuet-wie-im-Maerchen,hansa10312.html',
41 'only_matching': True
42 }, {
43 'url': 'https://www.ndr.de/nachrichten/niedersachsen/kommunalwahl_niedersachsen_2021/Grosse-Parteien-zufrieden-mit-Ergebnissen-der-Kommunalwahl,kommunalwahl1296.html',
2ffe3bc1 44 'info_dict': {
23dd2d9a 45 'id': 'kommunalwahl1296',
2ffe3bc1 46 'ext': 'mp4',
23dd2d9a
AG
47 'title': 'Die Spitzenrunde: Die Wahl aus Sicht der Landespolitik',
48 'thumbnail': 'https://www.ndr.de/fernsehen/screenshot1194912_v-contentxl.jpg',
49 'description': 'md5:5c6e2ad744cef499135735a1036d7aa7',
50 'series': 'Hallo Niedersachsen',
51 'channel': 'NDR Fernsehen',
52 'upload_date': '20210913',
53 'duration': 438,
2ffe3bc1
S
54 },
55 }, {
23dd2d9a
AG
56 'url': 'https://www.ndr.de/fernsehen/sendungen/extra_3/extra-3-Satiremagazin-mit-Christian-Ehring,sendung1091858.html',
57 'info_dict': {
58 'id': 'sendung1091858',
59 'ext': 'mp4',
60 'title': 'Extra 3 vom 11.11.2020 mit Christian Ehring',
61 'thumbnail': 'https://www.ndr.de/fernsehen/screenshot983938_v-contentxl.jpg',
62 'description': 'md5:700f6de264010585012a72f97b0ac0c9',
63 'series': 'extra 3',
64 'channel': 'NDR Fernsehen',
65 'upload_date': '20201111',
66 'duration': 1749,
67 }
68 }, {
2ffe3bc1 69 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
2ffe3bc1
S
70 'info_dict': {
71 'id': 'audio51535',
2ffe3bc1
S
72 'ext': 'mp3',
73 'title': 'La Valette entgeht der Hinrichtung',
23dd2d9a 74 'thumbnail': 'https://www.ndr.de/mediathek/mediathekbild140_v-podcast.jpg',
2ffe3bc1 75 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
2ffe3bc1 76 'upload_date': '20140729',
23dd2d9a 77 'duration': 884.0,
2ffe3bc1 78 },
23dd2d9a 79 'expected_warnings': ['unable to extract json url'],
2ffe3bc1
S
80 }]
81
dc9d8f44 82 def _extract_embed(self, webpage, display_id, id):
23dd2d9a
AG
83 formats = []
84 base_url = 'https://www.ndr.de'
85 json_url = self._search_regex(r'<iframe[^>]+src=\"([^\"]+)_theme-ndrde[^\.]*\.html\"', webpage,
86 'json url', fatal=False)
87 if json_url:
88 data_json = self._download_json(base_url + json_url.replace('ardplayer_image', 'ardjson_image') + '.json',
89 id, fatal=False)
90 info_json = data_json.get('_info', {})
91 media_json = try_get(data_json, lambda x: x['_mediaArray'][0]['_mediaStreamArray'])
92 for media in media_json:
93 if media.get('_quality') == 'auto':
94 formats.extend(self._extract_m3u8_formats(media['_stream'], id))
95 subtitles = {}
96 sub_url = data_json.get('_subtitleUrl')
97 if sub_url:
98 subtitles.setdefault('de', []).append({
99 'url': base_url + sub_url,
100 })
101 self._sort_formats(formats)
102 return {
103 'id': id,
104 'title': info_json.get('clipTitle'),
105 'thumbnail': base_url + data_json.get('_previewImage'),
106 'description': info_json.get('clipDescription'),
107 'series': info_json.get('seriesTitle') or None,
108 'channel': info_json.get('channelTitle'),
109 'upload_date': unified_strdate(info_json.get('clipDate')),
110 'duration': data_json.get('_duration'),
111 'formats': formats,
112 'subtitles': subtitles,
113 }
114 else:
115 json_url = base_url + self._search_regex(r'apiUrl\s?=\s?\'([^\']+)\'', webpage, 'json url').replace(
116 '_belongsToPodcast-', '')
117 data_json = self._download_json(json_url, id, fatal=False)
118 return {
119 'id': id,
120 'title': data_json.get('title'),
121 'thumbnail': base_url + data_json.get('poster'),
122 'description': data_json.get('summary'),
123 'upload_date': unified_strdate(data_json.get('publicationDate')),
124 'duration': parse_duration(data_json.get('duration')),
125 'formats': [{
126 'url': try_get(data_json, (lambda x: x['audio'][0]['url'], lambda x: x['files'][0]['url'])),
127 'vcodec': 'none',
128 'ext': 'mp3',
129 }],
130 }
1934f3a0
YCH
131
132
133class NJoyIE(NDRBaseIE):
2ffe3bc1
S
134 IE_NAME = 'njoy'
135 IE_DESC = 'N-JOY'
92519402 136 _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?:(?P<display_id>[^/?#]+),)?(?P<id>[\da-z]+)\.html'
2ffe3bc1
S
137 _TESTS = [{
138 # httpVideo, same content id
1934f3a0
YCH
139 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
140 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
141 'info_dict': {
64997815 142 'id': 'comedycontest2480',
2ffe3bc1 143 'display_id': 'Benaissa-beim-NDR-Comedy-Contest',
1934f3a0
YCH
144 'ext': 'mp4',
145 'title': 'Benaissa beim NDR Comedy Contest',
2ffe3bc1
S
146 'description': 'md5:f057a6c4e1c728b10d33b5ffd36ddc39',
147 'uploader': 'ndrtv',
148 'upload_date': '20141129',
1934f3a0 149 'duration': 654,
2ffe3bc1
S
150 },
151 'params': {
152 'skip_download': True,
153 },
154 }, {
155 # httpVideo, different content id
156 'url': 'http://www.n-joy.de/musik/Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-,felixjaehn168.html',
157 'md5': '417660fffa90e6df2fda19f1b40a64d8',
158 'info_dict': {
159 'id': 'dockville882',
160 'display_id': 'Das-frueheste-DJ-Set-des-Nordens-live-mit-Felix-Jaehn-',
161 'ext': 'mp4',
162 'title': '"Ich hab noch nie" mit Felix Jaehn',
163 'description': 'md5:85dd312d53be1b99e1f998a16452a2f3',
164 'uploader': 'njoy',
165 'upload_date': '20150822',
166 'duration': 211,
167 },
168 'params': {
169 'skip_download': True,
170 },
7e0dc613
S
171 }, {
172 'url': 'http://www.n-joy.de/radio/webradio/morningshow209.html',
173 'only_matching': True,
2ffe3bc1
S
174 }]
175
dc9d8f44 176 def _extract_embed(self, webpage, display_id, id):
2ffe3bc1
S
177 video_id = self._search_regex(
178 r'<iframe[^>]+id="pp_([\da-z]+)"', webpage, 'embed id')
179 description = self._search_regex(
180 r'<div[^>]+class="subline"[^>]*>[^<]+</div>\s*<p>([^<]+)</p>',
181 webpage, 'description', fatal=False)
182 return {
183 '_type': 'url_transparent',
184 'ie_key': 'NDREmbedBase',
185 'url': 'ndr:%s' % video_id,
186 'display_id': display_id,
187 'description': description,
1934f3a0 188 }
64997815 189
190
2ffe3bc1
S
191class NDREmbedBaseIE(InfoExtractor):
192 IE_NAME = 'ndr:embed:base'
193 _VALID_URL = r'(?:ndr:(?P<id_s>[\da-z]+)|https?://www\.ndr\.de/(?P<id>[\da-z]+)-ppjson\.json)'
194 _TESTS = [{
195 'url': 'ndr:soundcheck3366',
196 'only_matching': True,
197 }, {
198 'url': 'http://www.ndr.de/soundcheck3366-ppjson.json',
199 'only_matching': True,
200 }]
64997815 201
202 def _real_extract(self, url):
5ad28e7f 203 mobj = self._match_valid_url(url)
2ffe3bc1
S
204 video_id = mobj.group('id') or mobj.group('id_s')
205
206 ppjson = self._download_json(
207 'http://www.ndr.de/%s-ppjson.json' % video_id, video_id)
208
209 playlist = ppjson['playlist']
210
211 formats = []
212 quality_key = qualities(('xs', 's', 'm', 'l', 'xl'))
213
214 for format_id, f in playlist.items():
215 src = f.get('src')
216 if not src:
217 continue
218 ext = determine_ext(src, None)
219 if ext == 'f4m':
220 formats.extend(self._extract_f4m_formats(
310ea466
S
221 src + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
222 f4m_id='hds', fatal=False))
2ffe3bc1
S
223 elif ext == 'm3u8':
224 formats.extend(self._extract_m3u8_formats(
310ea466
S
225 src, video_id, 'mp4', m3u8_id='hls',
226 entry_protocol='m3u8_native', fatal=False))
2ffe3bc1
S
227 else:
228 quality = f.get('quality')
229 ff = {
230 'url': src,
231 'format_id': quality or format_id,
232 'quality': quality_key(quality),
233 }
234 type_ = f.get('type')
235 if type_ and type_.split('/')[0] == 'audio':
236 ff['vcodec'] = 'none'
237 ff['ext'] = ext or 'mp3'
238 formats.append(ff)
239 self._sort_formats(formats)
240
241 config = playlist['config']
242
243 live = playlist.get('config', {}).get('streamType') in ['httpVideoLive', 'httpAudioLive']
244 title = config['title']
2ffe3bc1
S
245 uploader = ppjson.get('config', {}).get('branding')
246 upload_date = ppjson.get('config', {}).get('publicationDate')
247 duration = int_or_none(config.get('duration'))
248
3fc56635
S
249 thumbnails = []
250 poster = try_get(config, lambda x: x['poster'], dict) or {}
251 for thumbnail_id, thumbnail in poster.items():
252 thumbnail_url = urljoin(url, thumbnail.get('src'))
253 if not thumbnail_url:
254 continue
255 thumbnails.append({
256 'id': thumbnail.get('quality') or thumbnail_id,
257 'url': thumbnail_url,
258 'preference': quality_key(thumbnail.get('quality')),
259 })
2ffe3bc1 260
8bdd16b4 261 subtitles = {}
262 tracks = config.get('tracks')
263 if tracks and isinstance(tracks, list):
264 for track in tracks:
265 if not isinstance(track, dict):
266 continue
267 track_url = urljoin(url, track.get('src'))
268 if not track_url:
269 continue
270 subtitles.setdefault(track.get('srclang') or 'de', []).append({
271 'url': track_url,
272 'ext': 'ttml',
273 })
274
2ffe3bc1
S
275 return {
276 'id': video_id,
277 'title': title,
278 'is_live': live,
279 'uploader': uploader if uploader != '-' else None,
280 'upload_date': upload_date[0:8] if upload_date else None,
281 'duration': duration,
282 'thumbnails': thumbnails,
283 'formats': formats,
8bdd16b4 284 'subtitles': subtitles,
2ffe3bc1 285 }
64997815 286
287
288class NDREmbedIE(NDREmbedBaseIE):
289 IE_NAME = 'ndr:embed'
dc9d8f44 290 _VALID_URL = r'https?://(?:www\.)?(?:daserste\.)?ndr\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)\.html'
2ffe3bc1 291 _TESTS = [{
64997815 292 'url': 'http://www.ndr.de/fernsehen/sendungen/ndr_aktuell/ndraktuell28488-player.html',
2ffe3bc1 293 'md5': '8b9306142fe65bbdefb5ce24edb6b0a9',
64997815 294 'info_dict': {
295 'id': 'ndraktuell28488',
296 'ext': 'mp4',
297 'title': 'Norddeutschland begrüßt Flüchtlinge',
2ffe3bc1
S
298 'is_live': False,
299 'uploader': 'ndrtv',
300 'upload_date': '20150907',
64997815 301 'duration': 132,
2ffe3bc1
S
302 },
303 }, {
304 'url': 'http://www.ndr.de/ndr2/events/soundcheck/soundcheck3366-player.html',
305 'md5': '002085c44bae38802d94ae5802a36e78',
306 'info_dict': {
307 'id': 'soundcheck3366',
308 'ext': 'mp4',
309 'title': 'Ella Henderson braucht Vergleiche nicht zu scheuen',
310 'is_live': False,
311 'uploader': 'ndr2',
312 'upload_date': '20150912',
313 'duration': 3554,
314 },
315 'params': {
316 'skip_download': True,
317 },
318 }, {
319 'url': 'http://www.ndr.de/info/audio51535-player.html',
320 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
321 'info_dict': {
322 'id': 'audio51535',
323 'ext': 'mp3',
324 'title': 'La Valette entgeht der Hinrichtung',
325 'is_live': False,
326 'uploader': 'ndrinfo',
327 'upload_date': '20140729',
328 'duration': 884,
329 },
330 'params': {
331 'skip_download': True,
332 },
333 }, {
334 'url': 'http://www.ndr.de/fernsehen/sendungen/visite/visite11010-externalPlayer.html',
335 'md5': 'ae57f80511c1e1f2fd0d0d3d31aeae7c',
336 'info_dict': {
337 'id': 'visite11010',
338 'ext': 'mp4',
339 'title': 'Visite - die ganze Sendung',
340 'is_live': False,
341 'uploader': 'ndrtv',
342 'upload_date': '20150902',
343 'duration': 3525,
344 },
345 'params': {
346 'skip_download': True,
347 },
348 }, {
349 # httpVideoLive
350 'url': 'http://www.ndr.de/fernsehen/livestream/livestream217-externalPlayer.html',
351 'info_dict': {
352 'id': 'livestream217',
353 'ext': 'flv',
ec85ded8 354 'title': r're:^NDR Fernsehen Niedersachsen \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
2ffe3bc1
S
355 'is_live': True,
356 'upload_date': '20150910',
357 },
358 'params': {
359 'skip_download': True,
360 },
361 }, {
362 'url': 'http://www.ndr.de/ndrkultur/audio255020-player.html',
363 'only_matching': True,
364 }, {
365 'url': 'http://www.ndr.de/fernsehen/sendungen/nordtour/nordtour7124-player.html',
366 'only_matching': True,
367 }, {
368 'url': 'http://www.ndr.de/kultur/film/videos/videoimport10424-player.html',
369 'only_matching': True,
370 }, {
371 'url': 'http://www.ndr.de/fernsehen/sendungen/hamburg_journal/hamj43006-player.html',
372 'only_matching': True,
373 }, {
374 'url': 'http://www.ndr.de/fernsehen/sendungen/weltbilder/weltbilder4518-player.html',
375 'only_matching': True,
376 }, {
377 'url': 'http://www.ndr.de/fernsehen/doku952-player.html',
378 'only_matching': True,
379 }]
64997815 380
381
382class NJoyEmbedIE(NDREmbedBaseIE):
2ffe3bc1 383 IE_NAME = 'njoy:embed'
92519402 384 _VALID_URL = r'https?://(?:www\.)?n-joy\.de/(?:[^/]+/)*(?P<id>[\da-z]+)-(?:player|externalPlayer)_[^/]+\.html'
2ffe3bc1
S
385 _TESTS = [{
386 # httpVideo
387 'url': 'http://www.n-joy.de/events/reeperbahnfestival/doku948-player_image-bc168e87-5263-4d6d-bd27-bb643005a6de_theme-n-joy.html',
388 'md5': '8483cbfe2320bd4d28a349d62d88bd74',
64997815 389 'info_dict': {
2ffe3bc1 390 'id': 'doku948',
64997815 391 'ext': 'mp4',
2ffe3bc1
S
392 'title': 'Zehn Jahre Reeperbahn Festival - die Doku',
393 'is_live': False,
394 'upload_date': '20150807',
395 'duration': 1011,
396 },
397 }, {
398 # httpAudio
399 'url': 'http://www.n-joy.de/news_wissen/stefanrichter100-player_image-d5e938b1-f21a-4b9a-86b8-aaba8bca3a13_theme-n-joy.html',
400 'md5': 'd989f80f28ac954430f7b8a48197188a',
401 'info_dict': {
402 'id': 'stefanrichter100',
403 'ext': 'mp3',
404 'title': 'Interview mit einem Augenzeugen',
405 'is_live': False,
406 'uploader': 'njoy',
407 'upload_date': '20150909',
408 'duration': 140,
409 },
410 'params': {
411 'skip_download': True,
412 },
413 }, {
414 # httpAudioLive, no explicit ext
415 'url': 'http://www.n-joy.de/news_wissen/webradioweltweit100-player_image-3fec0484-2244-4565-8fb8-ed25fd28b173_theme-n-joy.html',
416 'info_dict': {
417 'id': 'webradioweltweit100',
418 'ext': 'mp3',
ec85ded8 419 'title': r're:^N-JOY Weltweit \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
2ffe3bc1
S
420 'is_live': True,
421 'uploader': 'njoy',
422 'upload_date': '20150810',
423 },
424 'params': {
425 'skip_download': True,
426 },
427 }, {
428 'url': 'http://www.n-joy.de/musik/dockville882-player_image-3905259e-0803-4764-ac72-8b7de077d80a_theme-n-joy.html',
429 'only_matching': True,
430 }, {
431 'url': 'http://www.n-joy.de/radio/sendungen/morningshow/urlaubsfotos190-player_image-066a5df1-5c95-49ec-a323-941d848718db_theme-n-joy.html',
432 'only_matching': True,
433 }, {
434 'url': 'http://www.n-joy.de/entertainment/comedy/krudetv290-player_image-ab261bfe-51bf-4bf3-87ba-c5122ee35b3d_theme-n-joy.html',
435 'only_matching': True,
436 }]