4 from .common import InfoExtractor
11 class ZDFIE(InfoExtractor):
12 _VALID_URL = r'^http://www\.zdf\.de\/ZDFmediathek(?P<hash>#)?\/(.*beitrag\/video\/)(?P<video_id>[^/\?]+)(?:\?.*)?'
14 def _real_extract(self, url):
15 mobj = re.match(self._VALID_URL, url)
16 video_id = mobj.group('video_id')
18 xml_url = u'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
19 info_xml = self._download_webpage(
20 xml_url, video_id, note=u'Downloading video info')
21 doc = parse_xml_doc(info_xml)
23 title = doc.find('.//information/title').text
24 description = doc.find('.//information/detail').text
25 uploader_node = doc.find('.//details/originChannelTitle')
26 uploader = None if uploader_node is None else uploader_node.text
27 duration_str = doc.find('.//details/length').text
28 duration_m = re.match(r'''(?x)^
30 :(?P<minutes>[0-9]{2})
31 :(?P<seconds>[0-9]{2})
36 (int(duration_m.group('hours')) * 60 * 60) +
37 (int(duration_m.group('minutes')) * 60) +
38 int(duration_m.group('seconds'))
43 upload_date = unified_strdate(doc.find('.//details/airtime').text)
45 def xml_to_format(fnode):
46 video_url = fnode.find('url').text
47 is_available = u'http://www.metafilegenerator' not in video_url
49 format_id = fnode.attrib['basetype']
50 format_m = re.match(r'''(?x)
51 (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
52 (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
55 ext = format_m.group('container')
56 is_supported = ext != 'f4f'
58 PROTO_ORDER = ['http', 'rtmp', 'rtsp']
60 proto_pref = -PROTO_ORDER.index(format_m.group('proto'))
64 quality = fnode.find('./quality').text
65 QUALITY_ORDER = ['veryhigh', '300', 'high', 'med', 'low']
67 quality_pref = -QUALITY_ORDER.index(quality)
71 abr = int(fnode.find('./audioBitrate').text) // 1000
72 vbr = int(fnode.find('./videoBitrate').text) // 1000
73 pref = (is_available, is_supported,
74 proto_pref, quality_pref, vbr, abr)
78 format_note += u'(unsupported)'
83 'format_id': format_id + u'-' + quality,
86 'acodec': format_m.group('acodec'),
87 'vcodec': format_m.group('vcodec'),
90 'width': int(fnode.find('./width').text),
91 'height': int(fnode.find('./height').text),
92 'filesize': int(fnode.find('./filesize').text),
93 'format_note': format_note,
95 '_available': is_available,
98 format_nodes = doc.findall('.//formitaeten/formitaet')
99 formats = sorted(filter(lambda f: f['_available'],
100 map(xml_to_format, format_nodes)),
101 key=operator.itemgetter('_pref'))
107 'description': description,
108 'uploader': uploader,
109 'duration': duration,
110 'upload_date': upload_date,