]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/prosiebensat1.py
[prosiebensat1] Improve title extraction (closes #12318)
[yt-dlp.git] / youtube_dl / extractor / prosiebensat1.py
CommitLineData
dcdb292f 1# coding: utf-8
0c7214c4
S
2from __future__ import unicode_literals
3
4import re
5
6from hashlib import sha1
7from .common import InfoExtractor
84f214d8 8from ..compat import compat_str
1cc79574 9from ..utils import (
61be92e2 10 ExtractorError,
f01f7311 11 determine_ext,
993df6bc 12 float_or_none,
01534bf5 13 int_or_none,
2af0f87c 14 unified_strdate,
0c7214c4
S
15)
16
17
9d54b02b
RA
18class ProSiebenSat1BaseIE(InfoExtractor):
19 def _extract_video_info(self, url, clip_id):
20 client_location = url
21
22 video = self._download_json(
23 'http://vas.sim-technik.de/vas/live/v2/videos',
24 clip_id, 'Downloading videos JSON', query={
25 'access_token': self._TOKEN,
26 'client_location': client_location,
27 'client_name': self._CLIENT_NAME,
28 'ids': clip_id,
29 })[0]
30
31 if video.get('is_protected') is True:
32 raise ExtractorError('This video is DRM protected.', expected=True)
33
34 duration = float_or_none(video.get('duration'))
35 source_ids = [compat_str(source['id']) for source in video['sources']]
36
37 client_id = self._SALT[:2] + sha1(''.join([clip_id, self._SALT, self._TOKEN, client_location, self._SALT, self._CLIENT_NAME]).encode('utf-8')).hexdigest()
38
39 sources = self._download_json(
40 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources' % clip_id,
41 clip_id, 'Downloading sources JSON', query={
42 'access_token': self._TOKEN,
43 'client_id': client_id,
44 'client_location': client_location,
45 'client_name': self._CLIENT_NAME,
46 })
47 server_id = sources['server_id']
48
49 def fix_bitrate(bitrate):
50 bitrate = int_or_none(bitrate)
51 if not bitrate:
52 return None
53 return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
54
55 formats = []
56 for source_id in source_ids:
57 client_id = self._SALT[:2] + sha1(''.join([self._SALT, clip_id, self._TOKEN, server_id, client_location, source_id, self._SALT, self._CLIENT_NAME]).encode('utf-8')).hexdigest()
58 urls = self._download_json(
59 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url' % clip_id,
60 clip_id, 'Downloading urls JSON', fatal=False, query={
61 'access_token': self._TOKEN,
62 'client_id': client_id,
63 'client_location': client_location,
64 'client_name': self._CLIENT_NAME,
65 'server_id': server_id,
66 'source_ids': source_id,
67 })
68 if not urls:
69 continue
70 if urls.get('status_code') != 0:
71 raise ExtractorError('This video is unavailable', expected=True)
72 urls_sources = urls['sources']
73 if isinstance(urls_sources, dict):
74 urls_sources = urls_sources.values()
75 for source in urls_sources:
76 source_url = source.get('url')
77 if not source_url:
78 continue
79 protocol = source.get('protocol')
80 mimetype = source.get('mimetype')
81 if mimetype == 'application/f4m+xml' or 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
82 formats.extend(self._extract_f4m_formats(
83 source_url, clip_id, f4m_id='hds', fatal=False))
84 elif mimetype == 'application/x-mpegURL':
85 formats.extend(self._extract_m3u8_formats(
86 source_url, clip_id, 'mp4', 'm3u8_native',
87 m3u8_id='hls', fatal=False))
f41db405
RA
88 elif mimetype == 'application/dash+xml':
89 formats.extend(self._extract_mpd_formats(
90 source_url, clip_id, mpd_id='dash', fatal=False))
9d54b02b
RA
91 else:
92 tbr = fix_bitrate(source['bitrate'])
93 if protocol in ('rtmp', 'rtmpe'):
94 mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
95 if not mobj:
96 continue
97 path = mobj.group('path')
98 mp4colon_index = path.rfind('mp4:')
99 app = path[:mp4colon_index]
100 play_path = path[mp4colon_index:]
101 formats.append({
102 'url': '%s/%s' % (mobj.group('url'), app),
103 'app': app,
104 'play_path': play_path,
105 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
106 'page_url': 'http://www.prosieben.de',
107 'tbr': tbr,
108 'ext': 'flv',
109 'format_id': 'rtmp%s' % ('-%d' % tbr if tbr else ''),
110 })
111 else:
112 formats.append({
113 'url': source_url,
114 'tbr': tbr,
115 'format_id': 'http%s' % ('-%d' % tbr if tbr else ''),
116 })
117 self._sort_formats(formats)
118
119 return {
120 'duration': duration,
121 'formats': formats,
122 }
123
124
125class ProSiebenSat1IE(ProSiebenSat1BaseIE):
0c7214c4
S
126 IE_NAME = 'prosiebensat1'
127 IE_DESC = 'ProSiebenSat.1 Digital'
63c583eb
S
128 _VALID_URL = r'''(?x)
129 https?://
130 (?:www\.)?
131 (?:
132 (?:
493353c7 133 prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|7tv|advopedia
63c583eb 134 )\.(?:de|at|ch)|
493353c7 135 ran\.de|fem\.com|advopedia\.de
63c583eb
S
136 )
137 /(?P<id>.+)
138 '''
0c7214c4
S
139
140 _TESTS = [
141 {
ab9b890b
S
142 # Tests changes introduced in https://github.com/rg3/youtube-dl/pull/6242
143 # in response to fixing https://github.com/rg3/youtube-dl/issues/6215:
144 # - malformed f4m manifest support
145 # - proper handling of URLs starting with `https?://` in 2.0 manifests
146 # - recursive child f4m manifests extraction
0c7214c4
S
147 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
148 'info_dict': {
149 'id': '2104602',
fe5aa197 150 'ext': 'mp4',
16fa0129 151 'title': 'Episode 18 - Staffel 2',
0c7214c4
S
152 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
153 'upload_date': '20131231',
154 'duration': 5845.04,
155 },
0c7214c4
S
156 },
157 {
158 'url': 'http://www.prosieben.de/videokatalog/Gesellschaft/Leben/Trends/video-Lady-Umstyling-f%C3%BCr-Audrina-Rebekka-Audrina-Fergen-billig-aussehen-Battal-Modica-700544.html',
159 'info_dict': {
160 'id': '2570327',
161 'ext': 'mp4',
162 'title': 'Lady-Umstyling für Audrina',
163 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
164 'upload_date': '20131014',
165 'duration': 606.76,
166 },
167 'params': {
168 # rtmp download
169 'skip_download': True,
170 },
171 'skip': 'Seems to be broken',
172 },
173 {
6dadaa99 174 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
0c7214c4 175 'info_dict': {
6dadaa99 176 'id': '2429369',
0c7214c4 177 'ext': 'mp4',
6dadaa99
S
178 'title': 'Countdown für die Autowerkstatt',
179 'description': 'md5:809fc051a457b5d8666013bc40698817',
180 'upload_date': '20140223',
181 'duration': 2595.04,
0c7214c4
S
182 },
183 'params': {
184 # rtmp download
185 'skip_download': True,
186 },
84f214d8 187 'skip': 'This video is unavailable',
0c7214c4
S
188 },
189 {
190 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
191 'info_dict': {
192 'id': '2904997',
193 'ext': 'mp4',
194 'title': 'Sexy laufen in Ugg Boots',
195 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
196 'upload_date': '20140122',
197 'duration': 245.32,
198 },
199 'params': {
200 # rtmp download
201 'skip_download': True,
202 },
84f214d8 203 'skip': 'This video is unavailable',
0c7214c4
S
204 },
205 {
206 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
207 'info_dict': {
208 'id': '2906572',
209 'ext': 'mp4',
210 'title': 'Im Interview: Kai Wiesinger',
211 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
8d1c8cae 212 'upload_date': '20140203',
0c7214c4
S
213 'duration': 522.56,
214 },
215 'params': {
216 # rtmp download
217 'skip_download': True,
218 },
84f214d8 219 'skip': 'This video is unavailable',
0c7214c4
S
220 },
221 {
222 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
223 'info_dict': {
224 'id': '2992323',
225 'ext': 'mp4',
226 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
227 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
8d1c8cae 228 'upload_date': '20141014',
0c7214c4
S
229 'duration': 2410.44,
230 },
231 'params': {
232 # rtmp download
233 'skip_download': True,
234 },
84f214d8 235 'skip': 'This video is unavailable',
0c7214c4
S
236 },
237 {
238 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
239 'info_dict': {
240 'id': '3004256',
241 'ext': 'mp4',
242 'title': 'Schalke: Tönnies möchte Raul zurück',
243 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
244 'upload_date': '20140226',
245 'duration': 228.96,
246 },
247 'params': {
248 # rtmp download
249 'skip_download': True,
250 },
84f214d8 251 'skip': 'This video is unavailable',
0c7214c4
S
252 },
253 {
254 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
255 'info_dict': {
256 'id': '2572814',
fe5aa197 257 'ext': 'mp4',
0c7214c4
S
258 'title': 'Andreas Kümmert: Rocket Man',
259 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
260 'upload_date': '20131017',
261 'duration': 469.88,
262 },
263 'params': {
0c7214c4
S
264 'skip_download': True,
265 },
266 },
267 {
268 'url': 'http://www.fem.com/wellness/videos/wellness-video-clip-kurztripps-zum-valentinstag.html',
269 'info_dict': {
270 'id': '2156342',
fe5aa197 271 'ext': 'mp4',
0c7214c4 272 'title': 'Kurztrips zum Valentinstag',
81549898 273 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
0c7214c4
S
274 'duration': 307.24,
275 },
276 'params': {
0c7214c4
S
277 'skip_download': True,
278 },
279 },
c84890f7
AK
280 {
281 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
282 'info_dict': {
283 'id': '439664',
284 'title': 'Episode 8 - Ganze Folge - Playlist',
6a52eed8 285 'description': 'md5:63b8963e71f481782aeea877658dec84',
c84890f7
AK
286 },
287 'playlist_count': 2,
fe5aa197 288 'skip': 'This video is unavailable',
c84890f7 289 },
0baedd18
L
290 {
291 'url': 'http://www.7tv.de/circus-halligalli/615-best-of-circus-halligalli-ganze-folge',
292 'info_dict': {
293 'id': '4187506',
fe5aa197 294 'ext': 'mp4',
0baedd18
L
295 'title': 'Best of Circus HalliGalli',
296 'description': 'md5:8849752efd90b9772c9db6fdf87fb9e9',
297 'upload_date': '20151229',
298 },
299 'params': {
0baedd18
L
300 'skip_download': True,
301 },
302 },
71ad00c0
S
303 {
304 # geo restricted to Germany
305 'url': 'http://www.kabeleinsdoku.de/tv/mayday-alarm-im-cockpit/video/102-notlandung-im-hudson-river-ganze-folge',
306 'only_matching': True,
307 },
63c583eb
S
308 {
309 # geo restricted to Germany
310 'url': 'http://www.sat1gold.de/tv/edel-starck/video/11-staffel-1-episode-1-partner-wider-willen-ganze-folge',
311 'only_matching': True,
312 },
ddde9195
S
313 {
314 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
315 'only_matching': True,
316 },
493353c7
S
317 {
318 'url': 'http://www.advopedia.de/videos/lenssen-klaert-auf/lenssen-klaert-auf-folge-8-staffel-3-feiertage-und-freie-tage',
319 'only_matching': True,
320 },
0c7214c4
S
321 ]
322
9d54b02b
RA
323 _TOKEN = 'prosieben'
324 _SALT = '01!8d8F_)r9]4s[qeuXfP%'
325 _CLIENT_NAME = 'kolibri-2.0.19-splec4'
0c7214c4
S
326 _CLIPID_REGEXES = [
327 r'"clip_id"\s*:\s+"(\d+)"',
328 r'clipid: "(\d+)"',
38a9339b 329 r'clip[iI]d=(\d+)',
81549898 330 r'clip[iI]d\s*=\s*["\'](\d+)',
8d1c8cae 331 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
0c7214c4
S
332 ]
333 _TITLE_REGEXES = [
334 r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
335 r'<header class="clearfix">\s*<h3>(.+?)</h3>',
336 r'<!-- start video -->\s*<h1>(.+?)</h1>',
38a9339b 337 r'<h1 class="att-name">\s*(.+?)</h1>',
8b6c896c 338 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
0baedd18 339 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
81549898 340 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
0c7214c4
S
341 ]
342 _DESCRIPTION_REGEXES = [
343 r'<p itemprop="description">\s*(.+?)</p>',
344 r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
345 r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
38a9339b 346 r'<p class="att-description">\s*(.+?)\s*</p>',
0baedd18 347 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
81549898 348 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
0c7214c4
S
349 ]
350 _UPLOAD_DATE_REGEXES = [
351 r'<meta property="og:published_time" content="(.+?)">',
352 r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
353 r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
354 r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
355 r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
356 ]
6a52eed8
S
357 _PAGE_TYPE_REGEXES = [
358 r'<meta name="page_type" content="([^"]+)">',
c84890f7
AK
359 r"'itemType'\s*:\s*'([^']*)'",
360 ]
6a52eed8
S
361 _PLAYLIST_ID_REGEXES = [
362 r'content[iI]d=(\d+)',
c84890f7
AK
363 r"'itemId'\s*:\s*'([^']*)'",
364 ]
6a52eed8
S
365 _PLAYLIST_CLIP_REGEXES = [
366 r'(?s)data-qvt=.+?<a href="([^"]+)"',
c84890f7 367 ]
0c7214c4 368
6a52eed8 369 def _extract_clip(self, url, webpage):
84f214d8
RA
370 clip_id = self._html_search_regex(
371 self._CLIPID_REGEXES, webpage, 'clip id')
29138217
TC
372 title = self._html_search_regex(self._TITLE_REGEXES, webpage, 'title', default=None)
373 if title is None:
374 title = self._og_search_title(webpage)
9d54b02b 375 info = self._extract_video_info(url, clip_id)
84f214d8 376 description = self._html_search_regex(
7882f111 377 self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
fe5aa197 378 if description is None:
7882f111 379 description = self._og_search_description(webpage)
84f214d8
RA
380 thumbnail = self._og_search_thumbnail(webpage)
381 upload_date = unified_strdate(self._html_search_regex(
382 self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
383
9d54b02b 384 info.update({
0c7214c4
S
385 'id': clip_id,
386 'title': title,
387 'description': description,
388 'thumbnail': thumbnail,
389 'upload_date': upload_date,
9d54b02b
RA
390 })
391 return info
6a52eed8
S
392
393 def _extract_playlist(self, url, webpage):
394 playlist_id = self._html_search_regex(
395 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
ddde9195
S
396 playlist = self._parse_json(
397 self._search_regex(
ec85ded8 398 r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
ddde9195
S
399 webpage, 'playlist'),
400 playlist_id)
401 entries = []
402 for item in playlist:
403 clip_id = item.get('id') or item.get('upc')
404 if not clip_id:
405 continue
406 info = self._extract_video_info(url, clip_id)
407 info.update({
408 'id': clip_id,
409 'title': item.get('title') or item.get('teaser', {}).get('headline'),
410 'description': item.get('teaser', {}).get('description'),
411 'thumbnail': item.get('poster'),
412 'duration': float_or_none(item.get('duration')),
413 'series': item.get('tvShowTitle'),
414 'uploader': item.get('broadcastPublisher'),
415 })
416 entries.append(info)
417 return self.playlist_result(entries, playlist_id)
6a52eed8
S
418
419 def _real_extract(self, url):
420 video_id = self._match_id(url)
421 webpage = self._download_webpage(url, video_id)
422 page_type = self._search_regex(
423 self._PAGE_TYPE_REGEXES, webpage,
424 'page type', default='clip').lower()
425 if page_type == 'clip':
426 return self._extract_clip(url, webpage)
427 elif page_type == 'playlist':
428 return self._extract_playlist(url, webpage)
8ffb8e63
S
429 else:
430 raise ExtractorError(
431 'Unsupported page type %s' % page_type, expected=True)