]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/spiegel.py
Merge branch 'peugeot-tnaflix'
[yt-dlp.git] / youtube_dl / extractor / spiegel.py
CommitLineData
55c97a03 1# encoding: utf-8
4baff4a4
JMF
2from __future__ import unicode_literals
3
49f5f315 4import re
49f5f315
PH
5
6from .common import InfoExtractor
7
8
9class SpiegelIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?(?:#.*)?$'
7150858d 11 _TESTS = [{
4baff4a4 12 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
4baff4a4
JMF
13 'md5': '2c2754212136f35fb4b19767d242f66e',
14 'info_dict': {
55c97a03
S
15 'id': '1259285',
16 'ext': 'mp4',
4baff4a4 17 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
55c97a03
S
18 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
19 'duration': 49,
4baff4a4 20 },
55c97a03 21 }, {
4baff4a4 22 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
4baff4a4
JMF
23 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
24 'info_dict': {
55c97a03
S
25 'id': '1309159',
26 'ext': 'mp4',
4baff4a4 27 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
55c97a03
S
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,
4baff4a4 40 },
7150858d 41 }]
49f5f315
PH
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
55c97a03 49 title = self._html_search_regex(
4baff4a4 50 r'<div class="module-title">(.*?)</div>', webpage, 'title')
55c97a03 51 description = self._html_search_meta('description', webpage, 'description')
49f5f315 52
8bfb6723 53 base_url = self._search_regex(
55c97a03 54 r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
8bfb6723
EP
55
56 xml_url = base_url + video_id + '.xml'
55c97a03 57 idoc = self._download_xml(xml_url, video_id)
49f5f315 58
7150858d
PH
59 formats = [
60 {
61 'format_id': n.tag.rpartition('type')[2],
98aeac6e 62 'url': base_url + n.find('./filename').text,
7150858d
PH
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 ]
7150858d
PH
74 duration = float(idoc[0].findall('./duration')[0].text)
75
e6812ac9
PH
76 self._sort_formats(formats)
77
4baff4a4 78 return {
49f5f315 79 'id': video_id,
55c97a03
S
80 'title': title,
81 'description': description,
49f5f315 82 'duration': duration,
7150858d 83 'formats': formats,
49f5f315 84 }