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