]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spiegel.py
debian/README.source: Change 'markup'.
[youtubedl] / youtube_dl / extractor / spiegel.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .nexx import (
8 NexxIE,
9 NexxEmbedIE,
10 )
11 from .spiegeltv import SpiegeltvIE
12 from ..compat import compat_urlparse
13 from ..utils import (
14 parse_duration,
15 strip_or_none,
16 unified_timestamp,
17 )
18
19
20 class SpiegelIE(InfoExtractor):
21 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<id>[0-9]+)(?:-embed|-iframe)?(?:\.html)?(?:#.*)?$'
22 _TESTS = [{
23 'url': 'http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html',
24 'md5': 'b57399839d055fccfeb9a0455c439868',
25 'info_dict': {
26 'id': '563747',
27 'ext': 'mp4',
28 'title': 'Vulkanausbruch in Ecuador: Der "Feuerschlund" ist wieder aktiv',
29 'description': 'md5:8029d8310232196eb235d27575a8b9f4',
30 'duration': 49,
31 'upload_date': '20130311',
32 'timestamp': 1362994320,
33 },
34 }, {
35 'url': 'http://www.spiegel.de/video/schach-wm-videoanalyse-des-fuenften-spiels-video-1309159.html',
36 'md5': '5b6c2f4add9d62912ed5fc78a1faed80',
37 'info_dict': {
38 'id': '580988',
39 'ext': 'mp4',
40 'title': 'Schach-WM in der Videoanalyse: Carlsen nutzt die Fehlgriffe des Titelverteidigers',
41 'description': 'md5:c2322b65e58f385a820c10fa03b2d088',
42 'duration': 983,
43 'upload_date': '20131115',
44 'timestamp': 1384546642,
45 },
46 }, {
47 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-embed.html',
48 'md5': '97b91083a672d72976faa8433430afb9',
49 'info_dict': {
50 'id': '601883',
51 'ext': 'mp4',
52 '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.',
53 'title': 'Fragen an Astronaut Alexander Gerst: "Bekommen Sie die Tageszeiten mit?"',
54 'upload_date': '20140904',
55 'timestamp': 1409834160,
56 }
57 }, {
58 'url': 'http://www.spiegel.de/video/astronaut-alexander-gerst-von-der-iss-station-beantwortet-fragen-video-1519126-iframe.html',
59 'only_matching': True,
60 }, {
61 # nexx video
62 'url': 'http://www.spiegel.de/video/spiegel-tv-magazin-ueber-guellekrise-in-schleswig-holstein-video-99012776.html',
63 'only_matching': True,
64 }]
65
66 def _real_extract(self, url):
67 video_id = self._match_id(url)
68 metadata_url = 'http://www.spiegel.de/video/metadata/video-%s.json' % video_id
69 handle = self._request_webpage(metadata_url, video_id)
70
71 # 302 to spiegel.tv, like http://www.spiegel.de/video/der-film-zum-wochenende-die-wahrheit-ueber-maenner-video-99003272.html
72 if SpiegeltvIE.suitable(handle.geturl()):
73 return self.url_result(handle.geturl(), 'Spiegeltv')
74
75 video_data = self._parse_json(self._webpage_read_content(
76 handle, metadata_url, video_id), video_id)
77 title = video_data['title']
78 nexx_id = video_data['nexxOmniaId']
79 domain_id = video_data.get('nexxOmniaDomain') or '748'
80
81 return {
82 '_type': 'url_transparent',
83 'id': video_id,
84 'url': 'nexx:%s:%s' % (domain_id, nexx_id),
85 'title': title,
86 'description': strip_or_none(video_data.get('teaser')),
87 'duration': parse_duration(video_data.get('duration')),
88 'timestamp': unified_timestamp(video_data.get('datum')),
89 'ie_key': NexxIE.ie_key(),
90 }
91
92
93 class SpiegelArticleIE(InfoExtractor):
94 _VALID_URL = r'https?://(?:www\.)?spiegel\.de/(?!video/)[^?#]*?-(?P<id>[0-9]+)\.html'
95 IE_NAME = 'Spiegel:Article'
96 IE_DESC = 'Articles on spiegel.de'
97 _TESTS = [{
98 'url': 'http://www.spiegel.de/sport/sonst/badminton-wm-die-randsportart-soll-populaerer-werden-a-987092.html',
99 'info_dict': {
100 'id': '1516455',
101 'ext': 'mp4',
102 'title': 'Faszination Badminton: Nennt es bloß nicht Federball',
103 'description': 're:^Patrick Kämnitz gehört.{100,}',
104 'upload_date': '20140825',
105 },
106 }, {
107 'url': 'http://www.spiegel.de/wissenschaft/weltall/astronaut-alexander-gerst-antwortet-spiegel-online-lesern-a-989876.html',
108 'info_dict': {
109
110 },
111 'playlist_count': 6,
112 }, {
113 # Nexx iFrame embed
114 'url': 'http://www.spiegel.de/sptv/spiegeltv/spiegel-tv-ueber-schnellste-katapult-achterbahn-der-welt-taron-a-1137884.html',
115 'info_dict': {
116 'id': '161464',
117 'ext': 'mp4',
118 'title': 'Nervenkitzel Achterbahn',
119 'alt_title': 'Karussellbauer in Deutschland',
120 'description': 'md5:ffe7b1cc59a01f585e0569949aef73cc',
121 'release_year': 2005,
122 'creator': 'SPIEGEL TV',
123 'thumbnail': r're:^https?://.*\.jpg$',
124 'duration': 2761,
125 'timestamp': 1394021479,
126 'upload_date': '20140305',
127 },
128 'params': {
129 'format': 'bestvideo',
130 'skip_download': True,
131 },
132 }]
133
134 def _real_extract(self, url):
135 video_id = self._match_id(url)
136 webpage = self._download_webpage(url, video_id)
137
138 # Single video on top of the page
139 video_link = self._search_regex(
140 r'<a href="([^"]+)" onclick="return spOpenVideo\(this,', webpage,
141 'video page URL', default=None)
142 if video_link:
143 video_url = compat_urlparse.urljoin(
144 self.http_scheme() + '//spiegel.de/', video_link)
145 return self.url_result(video_url)
146
147 # Multiple embedded videos
148 embeds = re.findall(
149 r'<div class="vid_holder[0-9]+.*?</div>\s*.*?url\s*=\s*"([^"]+)"',
150 webpage)
151 entries = [
152 self.url_result(compat_urlparse.urljoin(
153 self.http_scheme() + '//spiegel.de/', embed_path))
154 for embed_path in embeds]
155 if embeds:
156 return self.playlist_result(entries)
157
158 return self.playlist_from_matches(
159 NexxEmbedIE._extract_urls(webpage), ie=NexxEmbedIE.ie_key())