1 # -*- coding: utf-8 -*-
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class TagesschauPlayerIE(InfoExtractor
):
16 IE_NAME
= 'tagesschau:player'
17 _VALID_URL
= r
'https?://(?:www\.)?tagesschau\.de/multimedia/(?P<kind>audio|video)/(?P=kind)-(?P<id>\d+)~player(?:_[^/?#&]+)?\.html'
20 'url': 'http://www.tagesschau.de/multimedia/video/video-179517~player.html',
21 'md5': '8d09548d5c15debad38bee3a4d15ca21',
25 'title': 'Marie Kristin Boese, ARD Berlin, über den zukünftigen Kurs der AfD',
26 'thumbnail': 're:^https?:.*\.jpg$',
27 'formats': 'mincount:6',
30 'url': 'https://www.tagesschau.de/multimedia/audio/audio-29417~player.html',
31 'md5': '76e6eec6ebd40740671cf0a2c88617e5',
35 'title': 'Trabi - Bye, bye Rennpappe',
36 'thumbnail': 're:^https?:.*\.jpg$',
37 'formats': 'mincount:2',
40 'url': 'http://www.tagesschau.de/multimedia/audio/audio-29417~player_autoplay-true.html',
41 'only_matching': True,
46 's': {'width': 320, 'height': 180, 'quality': 1}
,
47 'm': {'width': 512, 'height': 288, 'quality': 2}
,
48 'l': {'width': 960, 'height': 540, 'quality': 3}
,
49 'xl': {'width': 1280, 'height': 720, 'quality': 4}
,
50 'xxl': {'quality': 5}
,
53 def _extract_via_api(self
, kind
, video_id
):
54 info
= self
._download
_json
(
55 'https://www.tagesschau.de/api/multimedia/{0}/{0}-{1}.json'.format(kind
, video_id
),
57 title
= info
['headline']
59 for media
in info
['mediadata']:
60 for format_id
, format_url
in media
.items():
61 if determine_ext(format_url
) == 'm3u8':
62 formats
.extend(self
._extract
_m
3u8_formats
(
63 format_url
, video_id
, 'mp4',
64 entry_protocol
='m3u8_native', m3u8_id
='hls'))
68 'format_id': format_id
,
69 'vcodec': 'none' if kind
== 'audio' else None,
71 self
._sort
_formats
(formats
)
72 timestamp
= parse_iso8601(info
.get('date'))
76 'timestamp': timestamp
,
80 def _real_extract(self
, url
):
81 mobj
= re
.match(self
._VALID
_URL
, url
)
82 video_id
= mobj
.group('id')
84 # kind = mobj.group('kind').lower()
86 # return self._extract_via_api(kind, video_id)
88 # JSON api does not provide some audio formats (e.g. ogg) thus
89 # extractiong audio via webpage
91 webpage
= self
._download
_webpage
(url
, video_id
)
93 title
= self
._og
_search
_title
(webpage
).strip()
96 for media_json
in re
.findall(r
'({src\s*:\s*["\']http[^}]+type\s*:[^}]+})', webpage
):
97 media
= self
._parse
_json
(js_to_json(media_json
), video_id
, fatal
=False)
100 src
= media
.get('src')
103 quality
= media
.get('quality')
104 kind
= media
.get('type', '').split('/')[0]
105 ext
= determine_ext(src
)
108 'format_id': '%s_%s' % (quality
, ext
) if quality
else ext
,
110 'vcodec': 'none' if kind
== 'audio' else None,
112 f
.update(self
._FORMATS
.get(quality
, {}))
115 self
._sort
_formats
(formats
)
117 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
122 'thumbnail': thumbnail
,
127 class TagesschauIE(InfoExtractor
):
128 _VALID_URL
= r
'https?://(?:www\.)?tagesschau\.de/(?P<path>[^/]+/(?:[^/]+/)*?(?P<id>[^/#?]+?(?:-?[0-9]+)?))(?:~_?[^/#?]+?)?\.html'
131 'url': 'http://www.tagesschau.de/multimedia/video/video-102143.html',
132 'md5': 'f7c27a0eff3bfe8c7727e65f8fe1b1e6',
134 'id': 'video-102143',
136 'title': 'Regierungsumbildung in Athen: Neue Minister in Griechenland vereidigt',
137 'description': '18.07.2015 20:10 Uhr',
138 'thumbnail': 're:^https?:.*\.jpg$',
141 'url': 'http://www.tagesschau.de/multimedia/sendung/ts-5727.html',
142 'md5': '3c54c1f6243d279b706bde660ceec633',
146 'title': 'Sendung: tagesschau \t04.12.2014 20:00 Uhr',
147 'description': 'md5:695c01bfd98b7e313c501386327aea59',
148 'thumbnail': 're:^https?:.*\.jpg$',
152 'url': 'http://www.tagesschau.de/multimedia/audio/audio-29417.html',
153 'md5': '76e6eec6ebd40740671cf0a2c88617e5',
157 'title': 'Trabi - Bye, bye Rennpappe',
158 'description': 'md5:8687dda862cbbe2cfb2df09b56341317',
159 'thumbnail': 're:^https?:.*\.jpg$',
163 'url': 'http://www.tagesschau.de/inland/bnd-303.html',
164 'md5': 'e0916c623e85fc1d2b26b78f299d3958',
168 'title': 'Viele Baustellen für neuen BND-Chef',
169 'description': 'md5:1e69a54be3e1255b2b07cdbce5bcd8b4',
170 'thumbnail': 're:^https?:.*\.jpg$',
173 'url': 'http://www.tagesschau.de/inland/afd-parteitag-135.html',
175 'id': 'afd-parteitag-135',
176 'title': 'Möchtegern-Underdog mit Machtanspruch',
180 'url': 'http://www.tagesschau.de/multimedia/sendung/tsg-3771.html',
181 'only_matching': True,
183 'url': 'http://www.tagesschau.de/multimedia/sendung/tt-3827.html',
184 'only_matching': True,
186 'url': 'http://www.tagesschau.de/multimedia/sendung/nm-3475.html',
187 'only_matching': True,
189 'url': 'http://www.tagesschau.de/multimedia/sendung/weltspiegel-3167.html',
190 'only_matching': True,
192 'url': 'http://www.tagesschau.de/multimedia/tsvorzwanzig-959.html',
193 'only_matching': True,
195 'url': 'http://www.tagesschau.de/multimedia/sendung/bab/bab-3299~_bab-sendung-209.html',
196 'only_matching': True,
198 'url': 'http://www.tagesschau.de/multimedia/video/video-102303~_bab-sendung-211.html',
199 'only_matching': True,
201 'url': 'http://www.tagesschau.de/100sekunden/index.html',
202 'only_matching': True,
206 def suitable(cls
, url
):
207 return False if TagesschauPlayerIE
.suitable(url
) else super(TagesschauIE
, cls
).suitable(url
)
209 def _extract_formats(self
, download_text
, media_kind
):
211 r
'<div class="button" title="(?P<title>[^"]*)"><a href="(?P<url>[^"]+)">(?P<name>.+?)</a></div>',
215 link_url
= l
.group('url')
218 format_id
= self
._search
_regex
(
219 r
'.*/[^/.]+\.([^/]+)\.[^/.]+$', link_url
, 'format ID',
220 default
=determine_ext(link_url
))
222 'format_id': format_id
,
223 'url': l
.group('url'),
224 'format_name': l
.group('name'),
226 title
= l
.group('title')
228 if media_kind
.lower() == 'video':
231 Video:\s*(?P<vcodec>[a-zA-Z0-9/._-]+)\s*&\#10;
232 (?P<width>[0-9]+)x(?P<height>[0-9]+)px&\#10;
233 (?P<vbr>[0-9]+)kbps&\#10;
234 Audio:\s*(?P<abr>[0-9]+)kbps,\s*(?P<audio_desc>[A-Za-z\.0-9]+)&\#10;
235 Größe:\s*(?P<filesize_approx>[0-9.,]+\s+[a-zA-Z]*B)''',
239 'format_note': m
.group('audio_desc'),
240 'vcodec': m
.group('vcodec'),
241 'width': int(m
.group('width')),
242 'height': int(m
.group('height')),
243 'abr': int(m
.group('abr')),
244 'vbr': int(m
.group('vbr')),
245 'filesize_approx': parse_filesize(m
.group('filesize_approx')),
249 r
'(?P<format>.+?)-Format\s*:\s*(?P<abr>\d+)kbps\s*,\s*(?P<note>.+)',
253 'format_note': '%s, %s' % (m
.group('format'), m
.group('note')),
255 'abr': int(m
.group('abr')),
257 formats
.append(format
)
258 self
._sort
_formats
(formats
)
261 def _real_extract(self
, url
):
262 mobj
= re
.match(self
._VALID
_URL
, url
)
263 video_id
= mobj
.group('id') or mobj
.group('path')
264 display_id
= video_id
.lstrip('-')
266 webpage
= self
._download
_webpage
(url
, display_id
)
268 title
= self
._html
_search
_regex
(
269 r
'<span[^>]*class="headline"[^>]*>(.+?)</span>',
270 webpage
, 'title', default
=None) or self
._og
_search
_title
(webpage
)
272 DOWNLOAD_REGEX
= r
'(?s)<p>Wir bieten dieses (?P<kind>Video|Audio) in folgenden Formaten zum Download an:</p>\s*<div class="controls">(?P<links>.*?)</div>\s*<p>'
274 webpage_type
= self
._og
_search
_property
('type', webpage
, default
=None)
275 if webpage_type
== 'website': # Article
277 for num
, (entry_title
, media_kind
, download_text
) in enumerate(re
.findall(
278 r
'(?s)<p[^>]+class="infotext"[^>]*>.*?<strong>(.+?)</strong>.*?</p>.*?%s' % DOWNLOAD_REGEX
,
281 'id': '%s-%d' % (display_id
, num
),
282 'title': '%s' % entry_title
,
283 'formats': self
._extract
_formats
(download_text
, media_kind
),
286 return self
.playlist_result(entries
, display_id
, title
)
287 formats
= entries
[0]['formats']
288 else: # Assume single video
289 download_text
= self
._search
_regex
(
290 DOWNLOAD_REGEX
, webpage
, 'download links', group
='links')
291 media_kind
= self
._search
_regex
(
292 DOWNLOAD_REGEX
, webpage
, 'media kind', default
='Video', group
='kind')
293 formats
= self
._extract
_formats
(download_text
, media_kind
)
294 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
295 description
= self
._html
_search
_regex
(
296 r
'(?s)<p class="teasertext">(.*?)</p>',
297 webpage
, 'description', default
=None)
299 self
._sort
_formats
(formats
)
304 'thumbnail': thumbnail
,
306 'description': description
,