]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/prosiebensat1.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / prosiebensat1.py
CommitLineData
e3a3ed8a 1import hashlib
0c7214c4
S
2import re
3
0c7214c4 4from .common import InfoExtractor
84f214d8 5from ..compat import compat_str
1cc79574 6from ..utils import (
61be92e2 7 ExtractorError,
f01f7311 8 determine_ext,
993df6bc 9 float_or_none,
01534bf5 10 int_or_none,
38db9a40 11 merge_dicts,
2af0f87c 12 unified_strdate,
0c7214c4
S
13)
14
15
9d54b02b 16class ProSiebenSat1BaseIE(InfoExtractor):
0c15a56f 17 _GEO_BYPASS = False
c5eb75b3
RA
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
9d54b02b
RA
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
a06916d9 34 if not self.get_param('allow_unplayable_formats') and video.get('is_protected') is True:
88acdbc2 35 self.report_drm(clip_id)
9d54b02b 36
c5eb75b3
RA
37 formats = []
38 if self._ACCESS_ID:
39 raw_ct = self._ENCRYPTION_KEY + clip_id + self._IV + self._ACCESS_ID
0c15a56f 40 protocols = self._download_json(
c5eb75b3
RA
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,
e3a3ed8a 45 'client_token': hashlib.sha1((raw_ct).encode()).hexdigest(),
c5eb75b3 46 'video_id': clip_id,
0c15a56f
RA
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')
c5eb75b3
RA
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,
e3a3ed8a 56 'client_token': hashlib.sha1((raw_ct + server_token + self._SUPPORTED_PROTOCOLS).encode()).hexdigest(),
c5eb75b3
RA
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']]
9d54b02b 79
e3a3ed8a 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()
9d54b02b 81
c5eb75b3
RA
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={
9d54b02b
RA
85 'access_token': self._TOKEN,
86 'client_id': client_id,
87 'client_location': client_location,
88 'client_name': self._CLIENT_NAME,
9d54b02b 89 })
c5eb75b3
RA
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:
e3a3ed8a 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()
c5eb75b3
RA
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:
9d54b02b 111 continue
c5eb75b3
RA
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))
9d54b02b 133 else:
c5eb75b3
RA
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 })
9d54b02b
RA
159
160 return {
c5eb75b3 161 'duration': float_or_none(video.get('duration')),
9d54b02b
RA
162 'formats': formats,
163 }
164
165
166class ProSiebenSat1IE(ProSiebenSat1BaseIE):
0c7214c4
S
167 IE_NAME = 'prosiebensat1'
168 IE_DESC = 'ProSiebenSat.1 Digital'
63c583eb
S
169 _VALID_URL = r'''(?x)
170 https?://
171 (?:www\.)?
172 (?:
5a586082 173 (?:beta\.)?
63c583eb 174 (?:
2cdfe977 175 prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|advopedia
63c583eb 176 )\.(?:de|at|ch)|
6e3f23d9 177 ran\.de|fem\.com|advopedia\.de|galileo\.tv/video
63c583eb
S
178 )
179 /(?P<id>.+)
180 '''
0c7214c4
S
181
182 _TESTS = [
183 {
067aa17e
S
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:
ab9b890b
S
186 # - malformed f4m manifest support
187 # - proper handling of URLs starting with `https?://` in 2.0 manifests
188 # - recursive child f4m manifests extraction
0c7214c4
S
189 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
190 'info_dict': {
191 'id': '2104602',
fe5aa197 192 'ext': 'mp4',
2cdfe977 193 'title': 'CIRCUS HALLIGALLI - Episode 18 - Staffel 2',
0c7214c4
S
194 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
195 'upload_date': '20131231',
196 'duration': 5845.04,
38db9a40
S
197 'series': 'CIRCUS HALLIGALLI',
198 'season_number': 2,
199 'episode': 'Episode 18 - Staffel 2',
200 'episode_number': 18,
0c7214c4 201 },
0c7214c4
S
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 {
6dadaa99 220 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
0c7214c4 221 'info_dict': {
6dadaa99 222 'id': '2429369',
0c7214c4 223 'ext': 'mp4',
6dadaa99
S
224 'title': 'Countdown für die Autowerkstatt',
225 'description': 'md5:809fc051a457b5d8666013bc40698817',
226 'upload_date': '20140223',
227 'duration': 2595.04,
0c7214c4
S
228 },
229 'params': {
230 # rtmp download
231 'skip_download': True,
232 },
84f214d8 233 'skip': 'This video is unavailable',
0c7214c4
S
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 },
84f214d8 249 'skip': 'This video is unavailable',
0c7214c4
S
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',
8d1c8cae 258 'upload_date': '20140203',
0c7214c4
S
259 'duration': 522.56,
260 },
261 'params': {
262 # rtmp download
263 'skip_download': True,
264 },
84f214d8 265 'skip': 'This video is unavailable',
0c7214c4
S
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',
8d1c8cae 274 'upload_date': '20141014',
0c7214c4
S
275 'duration': 2410.44,
276 },
277 'params': {
278 # rtmp download
279 'skip_download': True,
280 },
84f214d8 281 'skip': 'This video is unavailable',
0c7214c4
S
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 },
84f214d8 297 'skip': 'This video is unavailable',
0c7214c4
S
298 },
299 {
300 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
301 'info_dict': {
302 'id': '2572814',
fe5aa197 303 'ext': 'mp4',
2cdfe977 304 'title': 'The Voice of Germany - Andreas Kümmert: Rocket Man',
0c7214c4 305 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
38db9a40 306 'timestamp': 1382041620,
0c7214c4
S
307 'upload_date': '20131017',
308 'duration': 469.88,
309 },
310 'params': {
0c7214c4
S
311 'skip_download': True,
312 },
313 },
314 {
2cdfe977 315 'url': 'http://www.fem.com/videos/beauty-lifestyle/kurztrips-zum-valentinstag',
0c7214c4
S
316 'info_dict': {
317 'id': '2156342',
fe5aa197 318 'ext': 'mp4',
0c7214c4 319 'title': 'Kurztrips zum Valentinstag',
81549898 320 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
0c7214c4
S
321 'duration': 307.24,
322 },
323 'params': {
0c7214c4
S
324 'skip_download': True,
325 },
326 },
c84890f7
AK
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',
6a52eed8 332 'description': 'md5:63b8963e71f481782aeea877658dec84',
c84890f7
AK
333 },
334 'playlist_count': 2,
fe5aa197 335 'skip': 'This video is unavailable',
c84890f7 336 },
76bee08f
S
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 },
71ad00c0
S
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 },
63c583eb
S
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 },
6e3f23d9 362 {
363 # geo restricted to Germany
364 'url': 'https://www.galileo.tv/video/diese-emojis-werden-oft-missverstanden',
365 'only_matching': True,
366 },
ddde9195
S
367 {
368 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
369 'only_matching': True,
370 },
493353c7
S
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 },
0c7214c4
S
375 ]
376
9d54b02b
RA
377 _TOKEN = 'prosieben'
378 _SALT = '01!8d8F_)r9]4s[qeuXfP%'
379 _CLIENT_NAME = 'kolibri-2.0.19-splec4'
c5eb75b3
RA
380
381 _ACCESS_ID = 'x_prosiebenmaxx-de'
382 _ENCRYPTION_KEY = 'Eeyeey9oquahthainoofashoyoikosag'
383 _IV = 'Aeluchoc6aevechuipiexeeboowedaok'
384
0c7214c4
S
385 _CLIPID_REGEXES = [
386 r'"clip_id"\s*:\s+"(\d+)"',
387 r'clipid: "(\d+)"',
38a9339b 388 r'clip[iI]d=(\d+)',
6e3f23d9 389 r'clip[iI][dD]\s*=\s*["\'](\d+)',
8d1c8cae 390 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
721a0c3c 391 r'proMamsId&quot;\s*:\s*&quot;(\d+)',
967ebbdb 392 r'proMamsId"\s*:\s*"(\d+)',
0c7214c4
S
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>',
38a9339b 398 r'<h1 class="att-name">\s*(.+?)</h1>',
8b6c896c 399 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
0baedd18 400 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
81549898 401 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
76bee08f 402 r'<h2[^>]+class="subtitle"[^>]*>([^<]+)</h2>',
0c7214c4
S
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>',
38a9339b 408 r'<p class="att-description">\s*(.+?)\s*</p>',
0baedd18 409 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
81549898 410 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
0c7214c4
S
411 ]
412 _UPLOAD_DATE_REGEXES = [
0c7214c4
S
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 ]
6a52eed8
S
418 _PAGE_TYPE_REGEXES = [
419 r'<meta name="page_type" content="([^"]+)">',
c84890f7
AK
420 r"'itemType'\s*:\s*'([^']*)'",
421 ]
6a52eed8
S
422 _PLAYLIST_ID_REGEXES = [
423 r'content[iI]d=(\d+)',
c84890f7
AK
424 r"'itemId'\s*:\s*'([^']*)'",
425 ]
6a52eed8
S
426 _PLAYLIST_CLIP_REGEXES = [
427 r'(?s)data-qvt=.+?<a href="([^"]+)"',
c84890f7 428 ]
0c7214c4 429
6a52eed8 430 def _extract_clip(self, url, webpage):
84f214d8
RA
431 clip_id = self._html_search_regex(
432 self._CLIPID_REGEXES, webpage, 'clip id')
76bee08f
S
433 title = self._html_search_regex(
434 self._TITLE_REGEXES, webpage, 'title',
435 default=None) or self._og_search_title(webpage)
9d54b02b 436 info = self._extract_video_info(url, clip_id)
84f214d8 437 description = self._html_search_regex(
7882f111 438 self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
fe5aa197 439 if description is None:
7882f111 440 description = self._og_search_description(webpage)
84f214d8 441 thumbnail = self._og_search_thumbnail(webpage)
2cdfe977
PS
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))
84f214d8 447
38db9a40
S
448 json_ld = self._search_json_ld(webpage, clip_id, default={})
449
450 return merge_dicts(info, {
0c7214c4
S
451 'id': clip_id,
452 'title': title,
453 'description': description,
454 'thumbnail': thumbnail,
455 'upload_date': upload_date,
38db9a40 456 }, json_ld)
6a52eed8
S
457
458 def _extract_playlist(self, url, webpage):
459 playlist_id = self._html_search_regex(
460 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
ddde9195
S
461 playlist = self._parse_json(
462 self._search_regex(
ec85ded8 463 r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
ddde9195
S
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)
6a52eed8
S
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)
8ffb8e63
S
494 else:
495 raise ExtractorError(
496 'Unsupported page type %s' % page_type, expected=True)