]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/prosiebensat1.py
[youtube] Add YoutubeStoriesIE (#3362)
[yt-dlp.git] / yt_dlp / extractor / prosiebensat1.py
CommitLineData
0c7214c4
S
1import re
2
3from hashlib import sha1
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,
45 'client_token': sha1((raw_ct).encode()).hexdigest(),
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,
56 'client_token': 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']]
9d54b02b 79
c5eb75b3 80 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 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:
99 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()
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 self._sort_formats(formats)
160
161 return {
c5eb75b3 162 'duration': float_or_none(video.get('duration')),
9d54b02b
RA
163 'formats': formats,
164 }
165
166
167class ProSiebenSat1IE(ProSiebenSat1BaseIE):
0c7214c4
S
168 IE_NAME = 'prosiebensat1'
169 IE_DESC = 'ProSiebenSat.1 Digital'
63c583eb
S
170 _VALID_URL = r'''(?x)
171 https?://
172 (?:www\.)?
173 (?:
5a586082 174 (?:beta\.)?
63c583eb 175 (?:
2cdfe977 176 prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|advopedia
63c583eb 177 )\.(?:de|at|ch)|
6e3f23d9 178 ran\.de|fem\.com|advopedia\.de|galileo\.tv/video
63c583eb
S
179 )
180 /(?P<id>.+)
181 '''
0c7214c4
S
182
183 _TESTS = [
184 {
067aa17e
S
185 # Tests changes introduced in https://github.com/ytdl-org/youtube-dl/pull/6242
186 # in response to fixing https://github.com/ytdl-org/youtube-dl/issues/6215:
ab9b890b
S
187 # - malformed f4m manifest support
188 # - proper handling of URLs starting with `https?://` in 2.0 manifests
189 # - recursive child f4m manifests extraction
0c7214c4
S
190 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
191 'info_dict': {
192 'id': '2104602',
fe5aa197 193 'ext': 'mp4',
2cdfe977 194 'title': 'CIRCUS HALLIGALLI - Episode 18 - Staffel 2',
0c7214c4
S
195 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
196 'upload_date': '20131231',
197 'duration': 5845.04,
38db9a40
S
198 'series': 'CIRCUS HALLIGALLI',
199 'season_number': 2,
200 'episode': 'Episode 18 - Staffel 2',
201 'episode_number': 18,
0c7214c4 202 },
0c7214c4
S
203 },
204 {
205 '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',
206 'info_dict': {
207 'id': '2570327',
208 'ext': 'mp4',
209 'title': 'Lady-Umstyling für Audrina',
210 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
211 'upload_date': '20131014',
212 'duration': 606.76,
213 },
214 'params': {
215 # rtmp download
216 'skip_download': True,
217 },
218 'skip': 'Seems to be broken',
219 },
220 {
6dadaa99 221 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
0c7214c4 222 'info_dict': {
6dadaa99 223 'id': '2429369',
0c7214c4 224 'ext': 'mp4',
6dadaa99
S
225 'title': 'Countdown für die Autowerkstatt',
226 'description': 'md5:809fc051a457b5d8666013bc40698817',
227 'upload_date': '20140223',
228 'duration': 2595.04,
0c7214c4
S
229 },
230 'params': {
231 # rtmp download
232 'skip_download': True,
233 },
84f214d8 234 'skip': 'This video is unavailable',
0c7214c4
S
235 },
236 {
237 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
238 'info_dict': {
239 'id': '2904997',
240 'ext': 'mp4',
241 'title': 'Sexy laufen in Ugg Boots',
242 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
243 'upload_date': '20140122',
244 'duration': 245.32,
245 },
246 'params': {
247 # rtmp download
248 'skip_download': True,
249 },
84f214d8 250 'skip': 'This video is unavailable',
0c7214c4
S
251 },
252 {
253 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
254 'info_dict': {
255 'id': '2906572',
256 'ext': 'mp4',
257 'title': 'Im Interview: Kai Wiesinger',
258 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
8d1c8cae 259 'upload_date': '20140203',
0c7214c4
S
260 'duration': 522.56,
261 },
262 'params': {
263 # rtmp download
264 'skip_download': True,
265 },
84f214d8 266 'skip': 'This video is unavailable',
0c7214c4
S
267 },
268 {
269 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
270 'info_dict': {
271 'id': '2992323',
272 'ext': 'mp4',
273 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
274 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
8d1c8cae 275 'upload_date': '20141014',
0c7214c4
S
276 'duration': 2410.44,
277 },
278 'params': {
279 # rtmp download
280 'skip_download': True,
281 },
84f214d8 282 'skip': 'This video is unavailable',
0c7214c4
S
283 },
284 {
285 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
286 'info_dict': {
287 'id': '3004256',
288 'ext': 'mp4',
289 'title': 'Schalke: Tönnies möchte Raul zurück',
290 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
291 'upload_date': '20140226',
292 'duration': 228.96,
293 },
294 'params': {
295 # rtmp download
296 'skip_download': True,
297 },
84f214d8 298 'skip': 'This video is unavailable',
0c7214c4
S
299 },
300 {
301 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
302 'info_dict': {
303 'id': '2572814',
fe5aa197 304 'ext': 'mp4',
2cdfe977 305 'title': 'The Voice of Germany - Andreas Kümmert: Rocket Man',
0c7214c4 306 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
38db9a40 307 'timestamp': 1382041620,
0c7214c4
S
308 'upload_date': '20131017',
309 'duration': 469.88,
310 },
311 'params': {
0c7214c4
S
312 'skip_download': True,
313 },
314 },
315 {
2cdfe977 316 'url': 'http://www.fem.com/videos/beauty-lifestyle/kurztrips-zum-valentinstag',
0c7214c4
S
317 'info_dict': {
318 'id': '2156342',
fe5aa197 319 'ext': 'mp4',
0c7214c4 320 'title': 'Kurztrips zum Valentinstag',
81549898 321 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
0c7214c4
S
322 'duration': 307.24,
323 },
324 'params': {
0c7214c4
S
325 'skip_download': True,
326 },
327 },
c84890f7
AK
328 {
329 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
330 'info_dict': {
331 'id': '439664',
332 'title': 'Episode 8 - Ganze Folge - Playlist',
6a52eed8 333 'description': 'md5:63b8963e71f481782aeea877658dec84',
c84890f7
AK
334 },
335 'playlist_count': 2,
fe5aa197 336 'skip': 'This video is unavailable',
c84890f7 337 },
76bee08f
S
338 {
339 # title in <h2 class="subtitle">
340 'url': 'http://www.prosieben.de/stars/oscar-award/videos/jetzt-erst-enthuellt-das-geheimnis-von-emma-stones-oscar-robe-clip',
341 'info_dict': {
342 'id': '4895826',
343 'ext': 'mp4',
344 'title': 'Jetzt erst enthüllt: Das Geheimnis von Emma Stones Oscar-Robe',
345 'description': 'md5:e5ace2bc43fadf7b63adc6187e9450b9',
346 'upload_date': '20170302',
347 },
348 'params': {
349 'skip_download': True,
350 },
351 'skip': 'geo restricted to Germany',
352 },
71ad00c0
S
353 {
354 # geo restricted to Germany
355 'url': 'http://www.kabeleinsdoku.de/tv/mayday-alarm-im-cockpit/video/102-notlandung-im-hudson-river-ganze-folge',
356 'only_matching': True,
357 },
63c583eb
S
358 {
359 # geo restricted to Germany
360 'url': 'http://www.sat1gold.de/tv/edel-starck/video/11-staffel-1-episode-1-partner-wider-willen-ganze-folge',
361 'only_matching': True,
362 },
6e3f23d9 363 {
364 # geo restricted to Germany
365 'url': 'https://www.galileo.tv/video/diese-emojis-werden-oft-missverstanden',
366 'only_matching': True,
367 },
ddde9195
S
368 {
369 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
370 'only_matching': True,
371 },
493353c7
S
372 {
373 'url': 'http://www.advopedia.de/videos/lenssen-klaert-auf/lenssen-klaert-auf-folge-8-staffel-3-feiertage-und-freie-tage',
374 'only_matching': True,
375 },
0c7214c4
S
376 ]
377
9d54b02b
RA
378 _TOKEN = 'prosieben'
379 _SALT = '01!8d8F_)r9]4s[qeuXfP%'
380 _CLIENT_NAME = 'kolibri-2.0.19-splec4'
c5eb75b3
RA
381
382 _ACCESS_ID = 'x_prosiebenmaxx-de'
383 _ENCRYPTION_KEY = 'Eeyeey9oquahthainoofashoyoikosag'
384 _IV = 'Aeluchoc6aevechuipiexeeboowedaok'
385
0c7214c4
S
386 _CLIPID_REGEXES = [
387 r'"clip_id"\s*:\s+"(\d+)"',
388 r'clipid: "(\d+)"',
38a9339b 389 r'clip[iI]d=(\d+)',
6e3f23d9 390 r'clip[iI][dD]\s*=\s*["\'](\d+)',
8d1c8cae 391 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
721a0c3c 392 r'proMamsId&quot;\s*:\s*&quot;(\d+)',
967ebbdb 393 r'proMamsId"\s*:\s*"(\d+)',
0c7214c4
S
394 ]
395 _TITLE_REGEXES = [
396 r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
397 r'<header class="clearfix">\s*<h3>(.+?)</h3>',
398 r'<!-- start video -->\s*<h1>(.+?)</h1>',
38a9339b 399 r'<h1 class="att-name">\s*(.+?)</h1>',
8b6c896c 400 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
0baedd18 401 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
81549898 402 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
76bee08f 403 r'<h2[^>]+class="subtitle"[^>]*>([^<]+)</h2>',
0c7214c4
S
404 ]
405 _DESCRIPTION_REGEXES = [
406 r'<p itemprop="description">\s*(.+?)</p>',
407 r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
408 r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
38a9339b 409 r'<p class="att-description">\s*(.+?)\s*</p>',
0baedd18 410 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
81549898 411 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
0c7214c4
S
412 ]
413 _UPLOAD_DATE_REGEXES = [
0c7214c4
S
414 r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
415 r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
416 r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
417 r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
418 ]
6a52eed8
S
419 _PAGE_TYPE_REGEXES = [
420 r'<meta name="page_type" content="([^"]+)">',
c84890f7
AK
421 r"'itemType'\s*:\s*'([^']*)'",
422 ]
6a52eed8
S
423 _PLAYLIST_ID_REGEXES = [
424 r'content[iI]d=(\d+)',
c84890f7
AK
425 r"'itemId'\s*:\s*'([^']*)'",
426 ]
6a52eed8
S
427 _PLAYLIST_CLIP_REGEXES = [
428 r'(?s)data-qvt=.+?<a href="([^"]+)"',
c84890f7 429 ]
0c7214c4 430
6a52eed8 431 def _extract_clip(self, url, webpage):
84f214d8
RA
432 clip_id = self._html_search_regex(
433 self._CLIPID_REGEXES, webpage, 'clip id')
76bee08f
S
434 title = self._html_search_regex(
435 self._TITLE_REGEXES, webpage, 'title',
436 default=None) or self._og_search_title(webpage)
9d54b02b 437 info = self._extract_video_info(url, clip_id)
84f214d8 438 description = self._html_search_regex(
7882f111 439 self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
fe5aa197 440 if description is None:
7882f111 441 description = self._og_search_description(webpage)
84f214d8 442 thumbnail = self._og_search_thumbnail(webpage)
2cdfe977
PS
443 upload_date = unified_strdate(
444 self._html_search_meta('og:published_time', webpage,
445 'upload date', default=None)
446 or self._html_search_regex(self._UPLOAD_DATE_REGEXES,
447 webpage, 'upload date', default=None))
84f214d8 448
38db9a40
S
449 json_ld = self._search_json_ld(webpage, clip_id, default={})
450
451 return merge_dicts(info, {
0c7214c4
S
452 'id': clip_id,
453 'title': title,
454 'description': description,
455 'thumbnail': thumbnail,
456 'upload_date': upload_date,
38db9a40 457 }, json_ld)
6a52eed8
S
458
459 def _extract_playlist(self, url, webpage):
460 playlist_id = self._html_search_regex(
461 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
ddde9195
S
462 playlist = self._parse_json(
463 self._search_regex(
ec85ded8 464 r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
ddde9195
S
465 webpage, 'playlist'),
466 playlist_id)
467 entries = []
468 for item in playlist:
469 clip_id = item.get('id') or item.get('upc')
470 if not clip_id:
471 continue
472 info = self._extract_video_info(url, clip_id)
473 info.update({
474 'id': clip_id,
475 'title': item.get('title') or item.get('teaser', {}).get('headline'),
476 'description': item.get('teaser', {}).get('description'),
477 'thumbnail': item.get('poster'),
478 'duration': float_or_none(item.get('duration')),
479 'series': item.get('tvShowTitle'),
480 'uploader': item.get('broadcastPublisher'),
481 })
482 entries.append(info)
483 return self.playlist_result(entries, playlist_id)
6a52eed8
S
484
485 def _real_extract(self, url):
486 video_id = self._match_id(url)
487 webpage = self._download_webpage(url, video_id)
488 page_type = self._search_regex(
489 self._PAGE_TYPE_REGEXES, webpage,
490 'page type', default='clip').lower()
491 if page_type == 'clip':
492 return self._extract_clip(url, webpage)
493 elif page_type == 'playlist':
494 return self._extract_playlist(url, webpage)
8ffb8e63
S
495 else:
496 raise ExtractorError(
497 'Unsupported page type %s' % page_type, expected=True)