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