]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spiegel.py
340a38440d02ad28b5eb6ab19916eee870818c35
[youtubedl] / youtube_dl / extractor / spiegel.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class SpiegelIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
11 _TESTS = [{
12 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
13 'md5': '2c2754212136f35fb4b19767d242f66e',
14 'info_dict': {
15 'id': '1259285',
16 'ext': 'mp4',
17 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
18 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
19 'duration': 49,
20 },
21 }, {
22 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
23 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
24 'info_dict': {
25 'id': '1309159',
26 'ext': 'mp4',
27 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
28 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
29 'duration': 983,
30 },
31 }, {
32 'url': 'http://www.spiegel.de/video/johann-westhauser-videobotschaft-des-hoehlenforschers-video-1502367.html',
33 'md5': '54f58ba0e752e3c07bc2a26222dd0acf',
34 'info_dict': {
35 'id': '1502367',
36 'ext': 'mp4',
37 'title': 'Videobotschaft: Höhlenforscher Westhauser dankt seinen Rettern',
38 'description': 'md5:c6f1ec11413ebd1088b6813943e5fc91',
39 'duration': 42,
40 },
41 }]
42
43 def _real_extract(self, url):
44 m = re.match(self._VALID_URL, url)
45 video_id = m.group('videoID')
46
47 webpage = self._download_webpage(url, video_id)
48
49 title = self._html_search_regex(
50 r'<div class="module-title">(.*?)</div>', webpage, 'title')
51 description = self._html_search_meta('description', webpage, 'description')
52
53 base_url = self._search_regex(
54 r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
55
56 xml_url = base_url + video_id + '.xml'
57 idoc = self._download_xml(xml_url, video_id)
58
59 formats = [
60 {
61 'format_id': n.tag.rpartition('type')[2],
62 'url': base_url + n.find('./filename').text,
63 'width': int(n.find('./width').text),
64 'height': int(n.find('./height').text),
65 'abr': int(n.find('./audiobitrate').text),
66 'vbr': int(n.find('./videobitrate').text),
67 'vcodec': n.find('./codec').text,
68 'acodec': 'MP4A',
69 }
70 for n in list(idoc)
71 # Blacklist type 6, it's extremely LQ and not available on the same server
72 if n.tag.startswith('type') and n.tag != 'type6'
73 ]
74 duration = float(idoc[0].findall('./duration')[0].text)
75
76 self._sort_formats(formats)
77
78 return {
79 'id': video_id,
80 'title': title,
81 'description': description,
82 'duration': duration,
83 'formats': formats,
84 }