]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
4baff4a4 JMF |
2 | from __future__ import unicode_literals |
3 | ||
49f5f315 | 4 | import re |
49f5f315 PH |
5 | |
6 | from .common import InfoExtractor | |
00d06e3c | 7 | from .nexx import NexxEmbedIE |
2707b50f | 8 | from .spiegeltv import SpiegeltvIE |
252a1f75 RA |
9 | from ..compat import compat_urlparse |
10 | from ..utils import ( | |
11 | extract_attributes, | |
12 | unified_strdate, | |
13 | get_element_by_attribute, | |
14 | ) | |
49f5f315 PH |
15 | |
16 | ||
17 | class SpiegelIE(InfoExtractor): | |
aeb7b41d | 18 | _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed|-iframe)?(?:\.html)?(?:#.*)?$' |
7150858d | 19 | _TESTS = [{ |
4baff4a4 | 20 | 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html', |
4baff4a4 JMF |
21 | 'md5': '2c2754212136f35fb4b19767d242f66e', |
22 | 'info_dict': { | |
55c97a03 S |
23 | 'id': '1259285', |
24 | 'ext': 'mp4', | |
4baff4a4 | 25 | 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv', |
55c97a03 S |
26 | 'description': 'md5:8029d8310232196eb235d27575a8b9f4', |
27 | 'duration': 49, | |
252a1f75 | 28 | 'upload_date': '20130311', |
4baff4a4 | 29 | }, |
55c97a03 | 30 | }, { |
4baff4a4 | 31 | 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html', |
4baff4a4 JMF |
32 | 'md5': 'f2cdf638d7aa47654e251e1aee360af1', |
33 | 'info_dict': { | |
55c97a03 S |
34 | 'id': '1309159', |
35 | 'ext': 'mp4', | |
4baff4a4 | 36 | 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers', |
55c97a03 S |
37 | 'description': 'md5:c2322b65e58f385a820c10fa03b2d088', |
38 | 'duration': 983, | |
252a1f75 | 39 | 'upload_date': '20131115', |
55c97a03 | 40 | }, |
e4bdb37e PH |
41 | }, { |
42 | 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-embed.html', | |
43 | 'md5': 'd8eeca6bfc8f1cd6f490eb1f44695d51', | |
44 | 'info_dict': { | |
45 | 'id': '1519126', | |
46 | 'ext': 'mp4', | |
47 | '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.', | |
48 | 'title': 'Fragen an Astronaut Alexander Gerst: "Bekommen Sie die Tageszeiten mit?"', | |
252a1f75 | 49 | 'upload_date': '20140904', |
e4bdb37e | 50 | } |
aeb7b41d | 51 | }, { |
52 | 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-iframe.html', | |
53 | 'only_matching': True, | |
7150858d | 54 | }] |
49f5f315 PH |
55 | |
56 | def _real_extract(self, url): | |
0e15e725 | 57 | video_id = self._match_id(url) |
2707b50f PH |
58 | webpage, handle = self._download_webpage_handle(url, video_id) |
59 | ||
60 | # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html | |
61 | if SpiegeltvIE.suitable(handle.geturl()): | |
62 | return self.url_result(handle.geturl(), 'Spiegeltv') | |
49f5f315 | 63 | |
252a1f75 RA |
64 | video_data = extract_attributes(self._search_regex(r'(<div[^>]+id="spVideoElements"[^>]+>)', webpage, 'video element', default='')) |
65 | ||
66 | title = video_data.get('data-video-title') or get_element_by_attribute('class', 'module-title', webpage) | |
67 | description = video_data.get('data-video-teaser') or self._html_search_meta('description', webpage, 'description') | |
49f5f315 | 68 | |
8bfb6723 | 69 | base_url = self._search_regex( |
bf2c8c8f S |
70 | [r'server\s*:\s*(["\'])(?P<url>.+?)\1', r'var\s+server\s*=\s*"(?P<url>[^"]+)\"'], |
71 | webpage, 'server URL', group='url') | |
8bfb6723 EP |
72 | |
73 | xml_url = base_url + video_id + '.xml' | |
55c97a03 | 74 | idoc = self._download_xml(xml_url, video_id) |
49f5f315 | 75 | |
e92d4a11 S |
76 | formats = [] |
77 | for n in list(idoc): | |
78 | if n.tag.startswith('type') and n.tag != 'type6': | |
79 | format_id = n.tag.rpartition('type')[2] | |
80 | video_url = base_url + n.find('./filename').text | |
e92d4a11 S |
81 | formats.append({ |
82 | 'format_id': format_id, | |
83 | 'url': video_url, | |
84 | 'width': int(n.find('./width').text), | |
85 | 'height': int(n.find('./height').text), | |
86 | 'abr': int(n.find('./audiobitrate').text), | |
87 | 'vbr': int(n.find('./videobitrate').text), | |
88 | 'vcodec': n.find('./codec').text, | |
89 | 'acodec': 'MP4A', | |
90 | }) | |
7150858d PH |
91 | duration = float(idoc[0].findall('./duration')[0].text) |
92 | ||
d862a4f9 | 93 | self._check_formats(formats, video_id) |
e6812ac9 PH |
94 | self._sort_formats(formats) |
95 | ||
4baff4a4 | 96 | return { |
49f5f315 | 97 | 'id': video_id, |
55c97a03 | 98 | 'title': title, |
252a1f75 | 99 | 'description': description.strip() if description else None, |
49f5f315 | 100 | 'duration': duration, |
252a1f75 | 101 | 'upload_date': unified_strdate(video_data.get('data-video-date')), |
7150858d | 102 | 'formats': formats, |
49f5f315 | 103 | } |
89fb6a97 PH |
104 | |
105 | ||
106 | class SpiegelArticleIE(InfoExtractor): | |
92519402 | 107 | _VALID_URL = r'https?://(?:www\.)?spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html' |
89fb6a97 PH |
108 | IE_NAME = 'Spiegel:Article' |
109 | IE_DESC = 'Articles on spiegel.de' | |
e4bdb37e | 110 | _TESTS = [{ |
89fb6a97 PH |
111 | 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html', |
112 | 'info_dict': { | |
113 | 'id': '1516455', | |
114 | 'ext': 'mp4', | |
115 | 'title': 'Faszination Badminton: Nennt es bloß nicht Federball', | |
116 | 'description': 're:^Patrick Kämnitz gehört.{100,}', | |
001fffd0 | 117 | 'upload_date': '20140825', |
89fb6a97 | 118 | }, |
e4bdb37e PH |
119 | }, { |
120 | 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html', | |
121 | 'info_dict': { | |
122 | ||
123 | }, | |
124 | 'playlist_count': 6, | |
125 | }] | |
89fb6a97 PH |
126 | |
127 | def _real_extract(self, url): | |
0e15e725 | 128 | video_id = self._match_id(url) |
89fb6a97 | 129 | webpage = self._download_webpage(url, video_id) |
e4bdb37e PH |
130 | |
131 | # Single video on top of the page | |
89fb6a97 PH |
132 | video_link = self._search_regex( |
133 | r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage, | |
e4bdb37e PH |
134 | 'video page URL', default=None) |
135 | if video_link: | |
136 | video_url = compat_urlparse.urljoin( | |
137 | self.http_scheme() + '//spiegel.de/', video_link) | |
138 | return self.url_result(video_url) | |
139 | ||
140 | # Multiple embedded videos | |
141 | embeds = re.findall( | |
142 | r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"', | |
143 | webpage) | |
144 | entries = [ | |
145 | self.url_result(compat_urlparse.urljoin( | |
146 | self.http_scheme() + '//spiegel.de/', embed_path)) | |
00d06e3c S |
147 | for embed_path in embeds] |
148 | if embeds: | |
149 | return self.playlist_result(entries) | |
150 | ||
151 | return self.playlist_from_matches( | |
152 | NexxEmbedIE._extract_urls(webpage), ie=NexxEmbedIE.ie_key()) |