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