]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spiegel.py
debian/watch: Update for version 4.
[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|-iframe)?(?:\.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 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-iframe.html',
44 'only_matching': True,
45 }]
46
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
49 webpage, handle = self._download_webpage_handle(url, video_id)
50
51 # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html
52 if SpiegeltvIE.suitable(handle.geturl()):
53 return self.url_result(handle.geturl(), 'Spiegeltv')
54
55 title = re.sub(r'\s+', ' ', self._html_search_regex(
56 r'(?s)<(?:h1|div) class="module-title"[^>]*>(.*?)</(?:h1|div)>',
57 webpage, 'title'))
58 description = self._html_search_meta('description', webpage, 'description')
59
60 base_url = self._search_regex(
61 [r'server\s*:\s*(["\'])(?P<url>.+?)\1', r'var\s+server\s*=\s*"(?P<url>[^"]+)\"'],
62 webpage, 'server URL', group='url')
63
64 xml_url = base_url + video_id + '.xml'
65 idoc = self._download_xml(xml_url, video_id)
66
67 formats = []
68 for n in list(idoc):
69 if n.tag.startswith('type') and n.tag != 'type6':
70 format_id = n.tag.rpartition('type')[2]
71 video_url = base_url + n.find('./filename').text
72 formats.append({
73 'format_id': format_id,
74 'url': video_url,
75 'width': int(n.find('./width').text),
76 'height': int(n.find('./height').text),
77 'abr': int(n.find('./audiobitrate').text),
78 'vbr': int(n.find('./videobitrate').text),
79 'vcodec': n.find('./codec').text,
80 'acodec': 'MP4A',
81 })
82 duration = float(idoc[0].findall('./duration')[0].text)
83
84 self._check_formats(formats, video_id)
85 self._sort_formats(formats)
86
87 return {
88 'id': video_id,
89 'title': title,
90 'description': description,
91 'duration': duration,
92 'formats': formats,
93 }
94
95
96 class SpiegelArticleIE(InfoExtractor):
97 _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
98 IE_NAME = 'Spiegel:Article'
99 IE_DESC = 'Articles on spiegel.de'
100 _TESTS = [{
101 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
102 'info_dict': {
103 'id': '1516455',
104 'ext': 'mp4',
105 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
106 'description': 're:^Patrick Kämnitz gehört.{100,}',
107 },
108 }, {
109 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
110 'info_dict': {
111
112 },
113 'playlist_count': 6,
114 }]
115
116 def _real_extract(self, url):
117 video_id = self._match_id(url)
118 webpage = self._download_webpage(url, video_id)
119
120 # Single video on top of the page
121 video_link = self._search_regex(
122 r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
123 'video page URL', default=None)
124 if video_link:
125 video_url = compat_urlparse.urljoin(
126 self.http_scheme() + '//spiegel.de/', video_link)
127 return self.url_result(video_url)
128
129 # Multiple embedded videos
130 embeds = re.findall(
131 r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
132 webpage)
133 entries = [
134 self.url_result(compat_urlparse.urljoin(
135 self.http_scheme() + '//spiegel.de/', embed_path))
136 for embed_path in embeds
137 ]
138 return self.playlist_result(entries)