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