]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/prosiebensat1.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / prosiebensat1.py
1 import hashlib
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 determine_ext,
8 float_or_none,
9 int_or_none,
10 merge_dicts,
11 unified_strdate,
12 )
13
14
15 class ProSiebenSat1BaseIE(InfoExtractor):
16 _GEO_BYPASS = False
17 _ACCESS_ID = None
18 _SUPPORTED_PROTOCOLS = 'dash:clear,hls:clear,progressive:clear'
19 _V4_BASE_URL = 'https://vas-v4.p7s1video.net/4.0/get'
20
21 def _extract_video_info(self, url, clip_id):
22 client_location = url
23
24 video = self._download_json(
25 'http://vas.sim-technik.de/vas/live/v2/videos',
26 clip_id, 'Downloading videos JSON', query={
27 'access_token': self._TOKEN,
28 'client_location': client_location,
29 'client_name': self._CLIENT_NAME,
30 'ids': clip_id,
31 })[0]
32
33 if not self.get_param('allow_unplayable_formats') and video.get('is_protected') is True:
34 self.report_drm(clip_id)
35
36 formats = []
37 if self._ACCESS_ID:
38 raw_ct = self._ENCRYPTION_KEY + clip_id + self._IV + self._ACCESS_ID
39 protocols = self._download_json(
40 self._V4_BASE_URL + 'protocols', clip_id,
41 'Downloading protocols JSON',
42 headers=self.geo_verification_headers(), query={
43 'access_id': self._ACCESS_ID,
44 'client_token': hashlib.sha1((raw_ct).encode()).hexdigest(),
45 'video_id': clip_id,
46 }, fatal=False, expected_status=(403,)) or {}
47 error = protocols.get('error') or {}
48 if error.get('title') == 'Geo check failed':
49 self.raise_geo_restricted(countries=['AT', 'CH', 'DE'])
50 server_token = protocols.get('server_token')
51 if server_token:
52 urls = (self._download_json(
53 self._V4_BASE_URL + 'urls', clip_id, 'Downloading urls JSON', query={
54 'access_id': self._ACCESS_ID,
55 'client_token': hashlib.sha1((raw_ct + server_token + self._SUPPORTED_PROTOCOLS).encode()).hexdigest(),
56 'protocols': self._SUPPORTED_PROTOCOLS,
57 'server_token': server_token,
58 'video_id': clip_id,
59 }, fatal=False) or {}).get('urls') or {}
60 for protocol, variant in urls.items():
61 source_url = variant.get('clear', {}).get('url')
62 if not source_url:
63 continue
64 if protocol == 'dash':
65 formats.extend(self._extract_mpd_formats(
66 source_url, clip_id, mpd_id=protocol, fatal=False))
67 elif protocol == 'hls':
68 formats.extend(self._extract_m3u8_formats(
69 source_url, clip_id, 'mp4', 'm3u8_native',
70 m3u8_id=protocol, fatal=False))
71 else:
72 formats.append({
73 'url': source_url,
74 'format_id': protocol,
75 })
76 if not formats:
77 source_ids = [str(source['id']) for source in video['sources']]
78
79 client_id = self._SALT[:2] + hashlib.sha1(''.join([clip_id, self._SALT, self._TOKEN, client_location, self._SALT, self._CLIENT_NAME]).encode()).hexdigest()
80
81 sources = self._download_json(
82 f'http://vas.sim-technik.de/vas/live/v2/videos/{clip_id}/sources',
83 clip_id, 'Downloading sources JSON', query={
84 'access_token': self._TOKEN,
85 'client_id': client_id,
86 'client_location': client_location,
87 'client_name': self._CLIENT_NAME,
88 })
89 server_id = sources['server_id']
90
91 def fix_bitrate(bitrate):
92 bitrate = int_or_none(bitrate)
93 if not bitrate:
94 return None
95 return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
96
97 for source_id in source_ids:
98 client_id = self._SALT[:2] + hashlib.sha1(''.join([self._SALT, clip_id, self._TOKEN, server_id, client_location, source_id, self._SALT, self._CLIENT_NAME]).encode()).hexdigest()
99 urls = self._download_json(
100 f'http://vas.sim-technik.de/vas/live/v2/videos/{clip_id}/sources/url',
101 clip_id, 'Downloading urls JSON', fatal=False, query={
102 'access_token': self._TOKEN,
103 'client_id': client_id,
104 'client_location': client_location,
105 'client_name': self._CLIENT_NAME,
106 'server_id': server_id,
107 'source_ids': source_id,
108 })
109 if not urls:
110 continue
111 if urls.get('status_code') != 0:
112 raise ExtractorError('This video is unavailable', expected=True)
113 urls_sources = urls['sources']
114 if isinstance(urls_sources, dict):
115 urls_sources = urls_sources.values()
116 for source in urls_sources:
117 source_url = source.get('url')
118 if not source_url:
119 continue
120 protocol = source.get('protocol')
121 mimetype = source.get('mimetype')
122 if mimetype == 'application/f4m+xml' or 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
123 formats.extend(self._extract_f4m_formats(
124 source_url, clip_id, f4m_id='hds', fatal=False))
125 elif mimetype == 'application/x-mpegURL':
126 formats.extend(self._extract_m3u8_formats(
127 source_url, clip_id, 'mp4', 'm3u8_native',
128 m3u8_id='hls', fatal=False))
129 elif mimetype == 'application/dash+xml':
130 formats.extend(self._extract_mpd_formats(
131 source_url, clip_id, mpd_id='dash', fatal=False))
132 else:
133 tbr = fix_bitrate(source['bitrate'])
134 if protocol in ('rtmp', 'rtmpe'):
135 mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
136 if not mobj:
137 continue
138 path = mobj.group('path')
139 mp4colon_index = path.rfind('mp4:')
140 app = path[:mp4colon_index]
141 play_path = path[mp4colon_index:]
142 formats.append({
143 'url': '{}/{}'.format(mobj.group('url'), app),
144 'app': app,
145 'play_path': play_path,
146 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
147 'page_url': 'http://www.prosieben.de',
148 'tbr': tbr,
149 'ext': 'flv',
150 'format_id': 'rtmp{}'.format(f'-{tbr}' if tbr else ''),
151 })
152 else:
153 formats.append({
154 'url': source_url,
155 'tbr': tbr,
156 'format_id': 'http{}'.format(f'-{tbr}' if tbr else ''),
157 })
158
159 return {
160 'duration': float_or_none(video.get('duration')),
161 'formats': formats,
162 }
163
164
165 class ProSiebenSat1IE(ProSiebenSat1BaseIE):
166 IE_NAME = 'prosiebensat1'
167 IE_DESC = 'ProSiebenSat.1 Digital'
168 _VALID_URL = r'''(?x)
169 https?://
170 (?:www\.)?
171 (?:
172 (?:beta\.)?
173 (?:
174 prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|advopedia
175 )\.(?:de|at|ch)|
176 ran\.de|fem\.com|advopedia\.de|galileo\.tv/video
177 )
178 /(?P<id>.+)
179 '''
180
181 _TESTS = [
182 {
183 # Tests changes introduced in https://github.com/ytdl-org/youtube-dl/pull/6242
184 # in response to fixing https://github.com/ytdl-org/youtube-dl/issues/6215:
185 # - malformed f4m manifest support
186 # - proper handling of URLs starting with `https?://` in 2.0 manifests
187 # - recursive child f4m manifests extraction
188 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
189 'info_dict': {
190 'id': '2104602',
191 'ext': 'mp4',
192 'title': 'CIRCUS HALLIGALLI - Episode 18 - Staffel 2',
193 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
194 'upload_date': '20131231',
195 'duration': 5845.04,
196 'series': 'CIRCUS HALLIGALLI',
197 'season_number': 2,
198 'episode': 'Episode 18 - Staffel 2',
199 'episode_number': 18,
200 },
201 },
202 {
203 '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',
204 'info_dict': {
205 'id': '2570327',
206 'ext': 'mp4',
207 'title': 'Lady-Umstyling für Audrina',
208 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
209 'upload_date': '20131014',
210 'duration': 606.76,
211 },
212 'params': {
213 # rtmp download
214 'skip_download': True,
215 },
216 'skip': 'Seems to be broken',
217 },
218 {
219 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
220 'info_dict': {
221 'id': '2429369',
222 'ext': 'mp4',
223 'title': 'Countdown für die Autowerkstatt',
224 'description': 'md5:809fc051a457b5d8666013bc40698817',
225 'upload_date': '20140223',
226 'duration': 2595.04,
227 },
228 'params': {
229 # rtmp download
230 'skip_download': True,
231 },
232 'skip': 'This video is unavailable',
233 },
234 {
235 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
236 'info_dict': {
237 'id': '2904997',
238 'ext': 'mp4',
239 'title': 'Sexy laufen in Ugg Boots',
240 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
241 'upload_date': '20140122',
242 'duration': 245.32,
243 },
244 'params': {
245 # rtmp download
246 'skip_download': True,
247 },
248 'skip': 'This video is unavailable',
249 },
250 {
251 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
252 'info_dict': {
253 'id': '2906572',
254 'ext': 'mp4',
255 'title': 'Im Interview: Kai Wiesinger',
256 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
257 'upload_date': '20140203',
258 'duration': 522.56,
259 },
260 'params': {
261 # rtmp download
262 'skip_download': True,
263 },
264 'skip': 'This video is unavailable',
265 },
266 {
267 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
268 'info_dict': {
269 'id': '2992323',
270 'ext': 'mp4',
271 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
272 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
273 'upload_date': '20141014',
274 'duration': 2410.44,
275 },
276 'params': {
277 # rtmp download
278 'skip_download': True,
279 },
280 'skip': 'This video is unavailable',
281 },
282 {
283 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
284 'info_dict': {
285 'id': '3004256',
286 'ext': 'mp4',
287 'title': 'Schalke: Tönnies möchte Raul zurück',
288 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
289 'upload_date': '20140226',
290 'duration': 228.96,
291 },
292 'params': {
293 # rtmp download
294 'skip_download': True,
295 },
296 'skip': 'This video is unavailable',
297 },
298 {
299 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
300 'info_dict': {
301 'id': '2572814',
302 'ext': 'mp4',
303 'title': 'The Voice of Germany - Andreas Kümmert: Rocket Man',
304 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
305 'timestamp': 1382041620,
306 'upload_date': '20131017',
307 'duration': 469.88,
308 },
309 'params': {
310 'skip_download': True,
311 },
312 },
313 {
314 'url': 'http://www.fem.com/videos/beauty-lifestyle/kurztrips-zum-valentinstag',
315 'info_dict': {
316 'id': '2156342',
317 'ext': 'mp4',
318 'title': 'Kurztrips zum Valentinstag',
319 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
320 'duration': 307.24,
321 },
322 'params': {
323 'skip_download': True,
324 },
325 },
326 {
327 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
328 'info_dict': {
329 'id': '439664',
330 'title': 'Episode 8 - Ganze Folge - Playlist',
331 'description': 'md5:63b8963e71f481782aeea877658dec84',
332 },
333 'playlist_count': 2,
334 'skip': 'This video is unavailable',
335 },
336 {
337 # title in <h2 class="subtitle">
338 'url': 'http://www.prosieben.de/stars/oscar-award/videos/jetzt-erst-enthuellt-das-geheimnis-von-emma-stones-oscar-robe-clip',
339 'info_dict': {
340 'id': '4895826',
341 'ext': 'mp4',
342 'title': 'Jetzt erst enthüllt: Das Geheimnis von Emma Stones Oscar-Robe',
343 'description': 'md5:e5ace2bc43fadf7b63adc6187e9450b9',
344 'upload_date': '20170302',
345 },
346 'params': {
347 'skip_download': True,
348 },
349 'skip': 'geo restricted to Germany',
350 },
351 {
352 # geo restricted to Germany
353 'url': 'http://www.kabeleinsdoku.de/tv/mayday-alarm-im-cockpit/video/102-notlandung-im-hudson-river-ganze-folge',
354 'only_matching': True,
355 },
356 {
357 # geo restricted to Germany
358 'url': 'http://www.sat1gold.de/tv/edel-starck/video/11-staffel-1-episode-1-partner-wider-willen-ganze-folge',
359 'only_matching': True,
360 },
361 {
362 # geo restricted to Germany
363 'url': 'https://www.galileo.tv/video/diese-emojis-werden-oft-missverstanden',
364 'only_matching': True,
365 },
366 {
367 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
368 'only_matching': True,
369 },
370 {
371 'url': 'http://www.advopedia.de/videos/lenssen-klaert-auf/lenssen-klaert-auf-folge-8-staffel-3-feiertage-und-freie-tage',
372 'only_matching': True,
373 },
374 ]
375
376 _TOKEN = 'prosieben'
377 _SALT = '01!8d8F_)r9]4s[qeuXfP%'
378 _CLIENT_NAME = 'kolibri-2.0.19-splec4'
379
380 _ACCESS_ID = 'x_prosiebenmaxx-de'
381 _ENCRYPTION_KEY = 'Eeyeey9oquahthainoofashoyoikosag'
382 _IV = 'Aeluchoc6aevechuipiexeeboowedaok'
383
384 _CLIPID_REGEXES = [
385 r'"clip_id"\s*:\s+"(\d+)"',
386 r'clipid: "(\d+)"',
387 r'clip[iI]d=(\d+)',
388 r'clip[iI][dD]\s*=\s*["\'](\d+)',
389 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
390 r'proMamsId&quot;\s*:\s*&quot;(\d+)',
391 r'proMamsId"\s*:\s*"(\d+)',
392 ]
393 _TITLE_REGEXES = [
394 r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
395 r'<header class="clearfix">\s*<h3>(.+?)</h3>',
396 r'<!-- start video -->\s*<h1>(.+?)</h1>',
397 r'<h1 class="att-name">\s*(.+?)</h1>',
398 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
399 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
400 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
401 r'<h2[^>]+class="subtitle"[^>]*>([^<]+)</h2>',
402 ]
403 _DESCRIPTION_REGEXES = [
404 r'<p itemprop="description">\s*(.+?)</p>',
405 r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
406 r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
407 r'<p class="att-description">\s*(.+?)\s*</p>',
408 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
409 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
410 ]
411 _UPLOAD_DATE_REGEXES = [
412 r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
413 r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
414 r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
415 r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
416 ]
417 _PAGE_TYPE_REGEXES = [
418 r'<meta name="page_type" content="([^"]+)">',
419 r"'itemType'\s*:\s*'([^']*)'",
420 ]
421 _PLAYLIST_ID_REGEXES = [
422 r'content[iI]d=(\d+)',
423 r"'itemId'\s*:\s*'([^']*)'",
424 ]
425 _PLAYLIST_CLIP_REGEXES = [
426 r'(?s)data-qvt=.+?<a href="([^"]+)"',
427 ]
428
429 def _extract_clip(self, url, webpage):
430 clip_id = self._html_search_regex(
431 self._CLIPID_REGEXES, webpage, 'clip id')
432 title = self._html_search_regex(
433 self._TITLE_REGEXES, webpage, 'title',
434 default=None) or self._og_search_title(webpage)
435 info = self._extract_video_info(url, clip_id)
436 description = self._html_search_regex(
437 self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
438 if description is None:
439 description = self._og_search_description(webpage)
440 thumbnail = self._og_search_thumbnail(webpage)
441 upload_date = unified_strdate(
442 self._html_search_meta('og:published_time', webpage,
443 'upload date', default=None)
444 or self._html_search_regex(self._UPLOAD_DATE_REGEXES,
445 webpage, 'upload date', default=None))
446
447 json_ld = self._search_json_ld(webpage, clip_id, default={})
448
449 return merge_dicts(info, {
450 'id': clip_id,
451 'title': title,
452 'description': description,
453 'thumbnail': thumbnail,
454 'upload_date': upload_date,
455 }, json_ld)
456
457 def _extract_playlist(self, url, webpage):
458 playlist_id = self._html_search_regex(
459 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
460 playlist = self._parse_json(
461 self._search_regex(
462 r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
463 webpage, 'playlist'),
464 playlist_id)
465 entries = []
466 for item in playlist:
467 clip_id = item.get('id') or item.get('upc')
468 if not clip_id:
469 continue
470 info = self._extract_video_info(url, clip_id)
471 info.update({
472 'id': clip_id,
473 'title': item.get('title') or item.get('teaser', {}).get('headline'),
474 'description': item.get('teaser', {}).get('description'),
475 'thumbnail': item.get('poster'),
476 'duration': float_or_none(item.get('duration')),
477 'series': item.get('tvShowTitle'),
478 'uploader': item.get('broadcastPublisher'),
479 })
480 entries.append(info)
481 return self.playlist_result(entries, playlist_id)
482
483 def _real_extract(self, url):
484 video_id = self._match_id(url)
485 webpage = self._download_webpage(url, video_id)
486 page_type = self._search_regex(
487 self._PAGE_TYPE_REGEXES, webpage,
488 'page type', default='clip').lower()
489 if page_type == 'clip':
490 return self._extract_clip(url, webpage)
491 elif page_type == 'playlist':
492 return self._extract_playlist(url, webpage)
493 else:
494 raise ExtractorError(
495 f'Unsupported page type {page_type}', expected=True)