]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/ndr.py
[ndr] fix info extraction
[yt-dlp.git] / youtube_dl / extractor / ndr.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 int_or_none,
8 )
9
10
11 preferences = {'xl': 4, 'l': 3, 'm': 2, 's': 1, 'xs': 0,}
12
13
14 class NDRBaseIE(InfoExtractor):
15 def _real_extract(self, url):
16 video_id = self._match_id(url)
17
18 json_data = self._download_json('http://www.ndr.de/%s-ppjson.json' % video_id, video_id, 'Downloading page')
19
20 formats = []
21 objetType = json_data.get('config').get('objectType')
22 if objetType == 'video':
23 for key, f in json_data.get('playlist').items():
24 if key != 'config':
25 src = f['src']
26 if '.f4m' in src:
27 formats.extend(self._extract_f4m_formats(src, video_id))
28 elif '.m3u8' in src:
29 formats.extend(self._extract_m3u8_formats(src, video_id))
30 else:
31 quality = f.get('quality')
32 formats.append({
33 'url': src,
34 'format_id': quality,
35 'preference': preferences.get(quality),
36 })
37 elif objetType == 'audio':
38 for key, f in json_data.get('playlist').items():
39 if key != 'config':
40 formats.append({
41 'url': f['src'],
42 'format_id': 'mp3',
43
44 })
45 else:
46 raise ExtractorError('No media links available for %s' % video_id)
47
48 self._sort_formats(formats)
49
50 config = json_data.get('playlist').get('config')
51
52 title = config['title']
53 duration = int_or_none(config.get('duration'))
54 thumbnails = [{
55 'id': thumbnail.get('quality'),
56 'url': thumbnail.get('src'),
57 'preference': preferences.get(thumbnail.get('quality'))
58 } for thumbnail in config.get('poster').values()]
59
60 return {
61 'id': video_id,
62 'title': title,
63 'thumbnails': thumbnails,
64 'duration': duration,
65 'formats': formats,
66 }
67
68
69 class NDRIE(NDRBaseIE):
70 IE_NAME = 'ndr'
71 IE_DESC = 'NDR.de - Mediathek'
72 _VALID_URL = r'https?://www\.ndr\.de/.+?,(?P<id>\w+)\.html'
73
74 _TESTS = [
75 {
76 'url': 'http://www.ndr.de/fernsehen/sendungen/nordmagazin/Kartoffeltage-in-der-Lewitz,nordmagazin25866.html',
77 'md5': '5bc5f5b92c82c0f8b26cddca34f8bb2c',
78 'note': 'Video file',
79 'info_dict': {
80 'id': 'nordmagazin25866',
81 'ext': 'mp4',
82 'title': 'Kartoffeltage in der Lewitz',
83 'duration': 166,
84 },
85 'skip': '404 Not found',
86 },
87 {
88 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
89 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59',
90 'info_dict': {
91 'id': 'hafengeburtstag988',
92 'ext': 'mp4',
93 'title': 'Party, Pötte und Parade',
94 'duration': 3498,
95 },
96 },
97 {
98 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
99 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
100 'note': 'Audio file',
101 'info_dict': {
102 'id': 'audio51535',
103 'ext': 'mp3',
104 'title': 'La Valette entgeht der Hinrichtung',
105 'duration': 884,
106 }
107 }
108 ]
109
110
111 class NJoyIE(NDRBaseIE):
112 IE_NAME = 'N-JOY'
113 _VALID_URL = r'https?://www\.n-joy\.de/.+?,(?P<id>\w+)\.html'
114
115 _TEST = {
116 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
117 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
118 'info_dict': {
119 'id': '2480',
120 'ext': 'mp4',
121 'title': 'Benaissa beim NDR Comedy Contest',
122 'duration': 654,
123 }
124 }