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