]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/spiegel.py
[toutv] really skip test
[youtube-dl.git] / youtube_dl / extractor / spiegel.py
1 import re
2 import xml.etree.ElementTree
3
4 from .common import InfoExtractor
5
6
7 class SpiegelIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
9     _TESTS = [{
10         u'url': u'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
11         u'file': u'1259285.mp4',
12         u'md5': u'2c2754212136f35fb4b19767d242f66e',
13         u'info_dict': {
14             u"title": u"Vulkanausbruch in Ecuador: Der \"Feuerschlund\" ist wieder aktiv"
15         }
16     },
17     {
18         u'url': u'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
19         u'file': u'1309159.mp4',
20         u'md5': u'f2cdf638d7aa47654e251e1aee360af1',
21         u'info_dict': {
22             u'title': u'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers'
23         }
24     }]
25
26     def _real_extract(self, url):
27         m = re.match(self._VALID_URL, url)
28         video_id = m.group('videoID')
29
30         webpage = self._download_webpage(url, video_id)
31
32         video_title = self._html_search_regex(
33             r'<div class="module-title">(.*?)</div>', webpage, u'title')
34
35         xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
36         xml_code = self._download_webpage(
37             xml_url, video_id,
38             note=u'Downloading XML', errnote=u'Failed to download XML')
39
40         idoc = xml.etree.ElementTree.fromstring(xml_code)
41
42         formats = [
43             {
44                 'format_id': n.tag.rpartition('type')[2],
45                 'url': u'http://video2.spiegel.de/flash/' + n.find('./filename').text,
46                 'width': int(n.find('./width').text),
47                 'height': int(n.find('./height').text),
48                 'abr': int(n.find('./audiobitrate').text),
49                 'vbr': int(n.find('./videobitrate').text),
50                 'vcodec': n.find('./codec').text,
51                 'acodec': 'MP4A',
52             }
53             for n in list(idoc)
54             # Blacklist type 6, it's extremely LQ and not available on the same server
55             if n.tag.startswith('type') and n.tag != 'type6'
56         ]
57         formats.sort(key=lambda f: f['vbr'])
58         duration = float(idoc[0].findall('./duration')[0].text)
59
60         info = {
61             'id': video_id,
62             'title': video_title,
63             'duration': duration,
64             'formats': formats,
65         }
66         return info