]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spiegel.py
1e55a9ffb5748b70969de11886c13720ff936be7
[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 from ..compat import compat_urlparse
8 from .spiegeltv import SpiegeltvIE
9
10
11 class SpiegelIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed)?(?:\.html)?(?:#.*)?$'
13 _TESTS = [{
14 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
15 'md5': '2c2754212136f35fb4b19767d242f66e',
16 'info_dict': {
17 'id': '1259285',
18 'ext': 'mp4',
19 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
20 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
21 'duration': 49,
22 },
23 }, {
24 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
25 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
26 'info_dict': {
27 'id': '1309159',
28 'ext': 'mp4',
29 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
30 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
31 'duration': 983,
32 },
33 }, {
34 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-embed.html',
35 'md5': 'd8eeca6bfc8f1cd6f490eb1f44695d51',
36 'info_dict': {
37 'id': '1519126',
38 'ext': 'mp4',
39 'description': 'SPIEGEL ONLINE-Nutzer durften den deutschen Astronauten Alexander Gerst über sein Leben auf der ISS-Station befragen. Hier kommen seine Antworten auf die besten sechs Fragen.',
40 'title': 'Fragen an Astronaut Alexander Gerst: "Bekommen Sie die Tageszeiten mit?"',
41 }
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46 webpage, handle = self._download_webpage_handle(url, video_id)
47
48 # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html
49 if SpiegeltvIE.suitable(handle.geturl()):
50 return self.url_result(handle.geturl(), 'Spiegeltv')
51
52 title = re.sub(r'\s+', ' ', self._html_search_regex(
53 r'(?s)<(?:h1|div) class="module-title"[^>]*>(.*?)</(?:h1|div)>',
54 webpage, 'title'))
55 description = self._html_search_meta('description', webpage, 'description')
56
57 base_url = self._search_regex(
58 r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
59
60 xml_url = base_url + video_id + '.xml'
61 idoc = self._download_xml(xml_url, video_id)
62
63 formats = [
64 {
65 'format_id': n.tag.rpartition('type')[2],
66 'url': base_url + n.find('./filename').text,
67 'width': int(n.find('./width').text),
68 'height': int(n.find('./height').text),
69 'abr': int(n.find('./audiobitrate').text),
70 'vbr': int(n.find('./videobitrate').text),
71 'vcodec': n.find('./codec').text,
72 'acodec': 'MP4A',
73 }
74 for n in list(idoc)
75 # Blacklist type 6, it's extremely LQ and not available on the same server
76 if n.tag.startswith('type') and n.tag != 'type6'
77 ]
78 duration = float(idoc[0].findall('./duration')[0].text)
79
80 self._sort_formats(formats)
81
82 return {
83 'id': video_id,
84 'title': title,
85 'description': description,
86 'duration': duration,
87 'formats': formats,
88 }
89
90
91 class SpiegelArticleIE(InfoExtractor):
92 _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
93 IE_NAME = 'Spiegel:Article'
94 IE_DESC = 'Articles on spiegel.de'
95 _TESTS = [{
96 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
97 'info_dict': {
98 'id': '1516455',
99 'ext': 'mp4',
100 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
101 'description': 're:^Patrick Kämnitz gehört.{100,}',
102 },
103 }, {
104 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
105 'info_dict': {
106
107 },
108 'playlist_count': 6,
109 }]
110
111 def _real_extract(self, url):
112 video_id = self._match_id(url)
113 webpage = self._download_webpage(url, video_id)
114
115 # Single video on top of the page
116 video_link = self._search_regex(
117 r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
118 'video page URL', default=None)
119 if video_link:
120 video_url = compat_urlparse.urljoin(
121 self.http_scheme() + '//spiegel.de/', video_link)
122 return self.url_result(video_url)
123
124 # Multiple embedded videos
125 embeds = re.findall(
126 r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
127 webpage)
128 entries = [
129 self.url_result(compat_urlparse.urljoin(
130 self.http_scheme() + '//spiegel.de/', embed_path))
131 for embed_path in embeds
132 ]
133 return self.playlist_result(entries)