]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/spiegel.py
[ssa] Add extractor (Closes #5169)
[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
d862a4f9 7from ..compat import compat_urlparse
2707b50f 8from .spiegeltv import SpiegeltvIE
49f5f315
PH
9
10
11class SpiegelIE(InfoExtractor):
e4bdb37e 12 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed)?(?:\.html)?(?:#.*)?$'
7150858d 13 _TESTS = [{
4baff4a4 14 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
4baff4a4
JMF
15 'md5': '2c2754212136f35fb4b19767d242f66e',
16 'info_dict': {
55c97a03
S
17 'id': '1259285',
18 'ext': 'mp4',
4baff4a4 19 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
55c97a03
S
20 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
21 'duration': 49,
4baff4a4 22 },
55c97a03 23 }, {
4baff4a4 24 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
4baff4a4
JMF
25 'md5': 'f2cdf638d7aa47654e251e1aee360af1',
26 'info_dict': {
55c97a03
S
27 'id': '1309159',
28 'ext': 'mp4',
4baff4a4 29 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
55c97a03
S
30 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
31 'duration': 983,
32 },
e4bdb37e
PH
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 }
7150858d 42 }]
49f5f315
PH
43
44 def _real_extract(self, url):
0e15e725 45 video_id = self._match_id(url)
2707b50f
PH
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')
49f5f315 51
e4bdb37e
PH
52 title = re.sub(r'\s+', ' ', self._html_search_regex(
53 r'(?s)<(?:h1|div) class="module-title"[^>]*>(.*?)</(?:h1|div)>',
54 webpage, 'title'))
55c97a03 55 description = self._html_search_meta('description', webpage, 'description')
49f5f315 56
8bfb6723 57 base_url = self._search_regex(
55c97a03 58 r'var\s+server\s*=\s*"([^"]+)\"', webpage, 'server URL')
8bfb6723
EP
59
60 xml_url = base_url + video_id + '.xml'
55c97a03 61 idoc = self._download_xml(xml_url, video_id)
49f5f315 62
e92d4a11
S
63 formats = []
64 for n in list(idoc):
65 if n.tag.startswith('type') and n.tag != 'type6':
66 format_id = n.tag.rpartition('type')[2]
67 video_url = base_url + n.find('./filename').text
e92d4a11
S
68 formats.append({
69 'format_id': format_id,
70 'url': video_url,
71 'width': int(n.find('./width').text),
72 'height': int(n.find('./height').text),
73 'abr': int(n.find('./audiobitrate').text),
74 'vbr': int(n.find('./videobitrate').text),
75 'vcodec': n.find('./codec').text,
76 'acodec': 'MP4A',
77 })
7150858d
PH
78 duration = float(idoc[0].findall('./duration')[0].text)
79
d862a4f9 80 self._check_formats(formats, video_id)
e6812ac9
PH
81 self._sort_formats(formats)
82
4baff4a4 83 return {
49f5f315 84 'id': video_id,
55c97a03
S
85 'title': title,
86 'description': description,
49f5f315 87 'duration': duration,
7150858d 88 'formats': formats,
49f5f315 89 }
89fb6a97
PH
90
91
92class SpiegelArticleIE(InfoExtractor):
93 _VALID_URL = 'https?://www\.spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
94 IE_NAME = 'Spiegel:Article'
95 IE_DESC = 'Articles on spiegel.de'
e4bdb37e 96 _TESTS = [{
89fb6a97
PH
97 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
98 'info_dict': {
99 'id': '1516455',
100 'ext': 'mp4',
101 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
102 'description': 're:^Patrick Kämnitz gehört.{100,}',
103 },
e4bdb37e
PH
104 }, {
105 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
106 'info_dict': {
107
108 },
109 'playlist_count': 6,
110 }]
89fb6a97
PH
111
112 def _real_extract(self, url):
0e15e725 113 video_id = self._match_id(url)
89fb6a97 114 webpage = self._download_webpage(url, video_id)
e4bdb37e
PH
115
116 # Single video on top of the page
89fb6a97
PH
117 video_link = self._search_regex(
118 r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
e4bdb37e
PH
119 'video page URL', default=None)
120 if video_link:
121 video_url = compat_urlparse.urljoin(
122 self.http_scheme() + '//spiegel.de/', video_link)
123 return self.url_result(video_url)
124
125 # Multiple embedded videos
126 embeds = re.findall(
127 r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
128 webpage)
129 entries = [
130 self.url_result(compat_urlparse.urljoin(
131 self.http_scheme() + '//spiegel.de/', embed_path))
132 for embed_path in embeds
133 ]
134 return self.playlist_result(entries)