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