2 from __future__ import unicode_literals
7 from .common import InfoExtractor
19 class ZDFIE(InfoExtractor):
20 _VALID_URL = r'(?:zdf:|zdf:video:|https?://www\.zdf\.de/ZDFmediathek(?:#)?/(.*beitrag/(?:video/)?))(?P<id>[0-9]+)(?:/[^/?]+)?(?:\?.*)?'
23 'url': 'http://www.zdf.de/ZDFmediathek/beitrag/video/2037704/ZDFspezial---Ende-des-Machtpokers--?bc=sts;stt',
27 'title': 'ZDFspezial - Ende des Machtpokers',
28 'description': 'Union und SPD haben sich auf einen Koalitionsvertrag geeinigt. Aber was bedeutet das für die Bürger? Sehen Sie hierzu das ZDFspezial "Ende des Machtpokers - Große Koalition für Deutschland".',
30 'uploader': 'spezial',
31 'uploader_id': '225948',
32 'upload_date': '20131127',
34 'skip': 'Videos on ZDF.de are depublicised in short order',
37 def _parse_smil_formats(self, smil, smil_url, video_id, namespace=None, f4m_params=None, transform_rtmp_url=None):
39 for param_group in smil.findall(self._xpath_ns('./head/paramGroup', namespace)):
40 group_id = param_group.attrib.get(self._xpath_ns('id', 'http://www.w3.org/XML/1998/namespace'))
42 for param in param_group:
43 params[param.get('name')] = param.get('value')
44 param_groups[group_id] = params
47 for video in smil.findall(self._xpath_ns('.//video', namespace)):
48 src = video.get('src')
51 bitrate = float_or_none(video.get('system-bitrate') or video.get('systemBitrate'), 1000)
52 group_id = video.get('paramGroup')
53 param_group = param_groups[group_id]
54 for proto in param_group['protocols'].split(','):
56 'url': '%s://%s' % (proto, param_group['host']),
57 'app': param_group['app'],
60 'format_id': '%s-%d' % (proto, bitrate),
64 self._sort_formats(formats)
67 def extract_from_xml_url(self, video_id, xml_url):
68 doc = self._download_xml(
70 note='Downloading video info',
71 errnote='Failed to download video info')
73 title = doc.find('.//information/title').text
74 description = xpath_text(doc, './/information/detail', 'description')
75 duration = int_or_none(xpath_text(doc, './/details/lengthSec', 'duration'))
76 uploader = xpath_text(doc, './/details/originChannelTitle', 'uploader')
77 uploader_id = xpath_text(doc, './/details/originChannelId', 'uploader id')
78 upload_date = unified_strdate(xpath_text(doc, './/details/airtime', 'upload date'))
80 def xml_to_thumbnails(fnode):
83 thumbnail_url = node.text
89 if 'key' in node.attrib:
90 m = re.match('^([0-9]+)x([0-9]+)$', node.attrib['key'])
92 thumbnail['width'] = int(m.group(1))
93 thumbnail['height'] = int(m.group(2))
94 thumbnails.append(thumbnail)
97 thumbnails = xml_to_thumbnails(doc.findall('.//teaserimages/teaserimage'))
99 format_nodes = doc.findall('.//formitaeten/formitaet')
100 quality = qualities(['veryhigh', 'high', 'med', 'low'])
102 def get_quality(elem):
103 return quality(xpath_text(elem, 'quality'))
104 format_nodes.sort(key=get_quality)
107 for fnode in format_nodes:
108 video_url = fnode.find('url').text
109 is_available = 'http://www.metafilegenerator' not in video_url
112 format_id = fnode.attrib['basetype']
113 quality = xpath_text(fnode, './quality', 'quality')
114 format_m = re.match(r'''(?x)
115 (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
116 (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
119 ext = determine_ext(video_url, None) or format_m.group('container')
120 if ext not in ('smil', 'f4m', 'm3u8'):
121 format_id = format_id + '-' + quality
122 if format_id in format_ids:
128 smil_formats = self._extract_smil_formats(
129 video_url, video_id, fatal=False)
131 formats.extend(smil_formats)
133 m3u8_formats = self._extract_m3u8_formats(
134 video_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
136 formats.extend(m3u8_formats)
138 f4m_formats = self._extract_f4m_formats(
139 video_url, video_id, f4m_id='hds', fatal=False)
141 formats.extend(f4m_formats)
143 proto = format_m.group('proto').lower()
145 abr = int_or_none(xpath_text(fnode, './audioBitrate', 'abr'), 1000)
146 vbr = int_or_none(xpath_text(fnode, './videoBitrate', 'vbr'), 1000)
148 width = int_or_none(xpath_text(fnode, './width', 'width'))
149 height = int_or_none(xpath_text(fnode, './height', 'height'))
151 filesize = int_or_none(xpath_text(fnode, './filesize', 'filesize'))
158 'format_id': format_id,
161 'acodec': format_m.group('acodec'),
162 'vcodec': format_m.group('vcodec'),
167 'filesize': filesize,
168 'format_note': format_note,
170 '_available': is_available,
172 format_ids.append(format_id)
174 self._sort_formats(formats)
179 'description': description,
180 'duration': duration,
181 'thumbnails': thumbnails,
182 'uploader': uploader,
183 'uploader_id': uploader_id,
184 'upload_date': upload_date,
188 def _real_extract(self, url):
189 video_id = self._match_id(url)
190 xml_url = 'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
191 return self.extract_from_xml_url(video_id, xml_url)
194 class ZDFChannelIE(InfoExtractor):
195 _VALID_URL = r'(?:zdf:topic:|https?://www\.zdf\.de/ZDFmediathek(?:#)?/.*kanaluebersicht/(?:[^/]+/)?)(?P<id>[0-9]+)'
197 'url': 'http://www.zdf.de/ZDFmediathek#/kanaluebersicht/1586442/sendung/Titanic',
203 'url': 'http://www.zdf.de/ZDFmediathek/kanaluebersicht/aktuellste/332',
204 'only_matching': True,
206 'url': 'http://www.zdf.de/ZDFmediathek/kanaluebersicht/meist-gesehen/332',
207 'only_matching': True,
209 'url': 'http://www.zdf.de/ZDFmediathek/kanaluebersicht/_/1798716?bc=nrt;nrm?flash=off',
210 'only_matching': True,
214 def _fetch_page(self, channel_id, page):
215 offset = page * self._PAGE_SIZE
217 'http://www.zdf.de/ZDFmediathek/xmlservice/web/aktuellste?ak=web&offset=%d&maxLength=%d&id=%s'
218 % (offset, self._PAGE_SIZE, channel_id))
219 doc = self._download_xml(
221 note='Downloading channel info',
222 errnote='Failed to download channel info')
224 title = doc.find('.//information/title').text
225 description = doc.find('.//information/detail').text
226 for asset in doc.findall('.//teasers/teaser'):
227 a_type = asset.find('./type').text
228 a_id = asset.find('./details/assetId').text
229 if a_type not in ('video', 'topic'):
233 'playlist_title': title,
234 'playlist_description': description,
235 'url': 'zdf:%s:%s' % (a_type, a_id),
238 def _real_extract(self, url):
239 channel_id = self._match_id(url)
240 entries = OnDemandPagedList(
241 functools.partial(self._fetch_page, channel_id), self._PAGE_SIZE)