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