2 from __future__ import unicode_literals
6 from hashlib import sha1
7 from .common import InfoExtractor
8 from ..compat import compat_str
19 class ProSiebenSat1BaseIE(InfoExtractor):
22 _SUPPORTED_PROTOCOLS = 'dash:clear,hls:clear,progressive:clear'
23 _V4_BASE_URL = 'https://vas-v4.p7s1video.net/4.0/get'
25 def _extract_video_info(self, url, clip_id):
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,
37 if video.get('is_protected') is True:
38 raise ExtractorError('This video is DRM protected.', expected=True)
42 raw_ct = self._ENCRYPTION_KEY + clip_id + self._IV + self._ACCESS_ID
43 protocols = self._download_json(
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(),
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')
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,
63 }, fatal=False) or {}).get('urls') or {}
64 for protocol, variant in urls.items():
65 source_url = variant.get('clear', {}).get('url')
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))
78 'format_id': protocol,
81 source_ids = [compat_str(source['id']) for source in video['sources']]
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()
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={
88 'access_token': self._TOKEN,
89 'client_id': client_id,
90 'client_location': client_location,
91 'client_name': self._CLIENT_NAME,
93 server_id = sources['server_id']
95 def fix_bitrate(bitrate):
96 bitrate = int_or_none(bitrate)
99 return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
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,
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')
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))
137 tbr = fix_bitrate(source['bitrate'])
138 if protocol in ('rtmp', 'rtmpe'):
139 mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
142 path = mobj.group('path')
143 mp4colon_index = path.rfind('mp4:')
144 app = path[:mp4colon_index]
145 play_path = path[mp4colon_index:]
147 'url': '%s/%s' % (mobj.group('url'), 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',
154 'format_id': 'rtmp%s' % ('-%d' % tbr if tbr else ''),
160 'format_id': 'http%s' % ('-%d' % tbr if tbr else ''),
162 self._sort_formats(formats)
165 'duration': float_or_none(video.get('duration')),
170 class ProSiebenSat1IE(ProSiebenSat1BaseIE):
171 IE_NAME = 'prosiebensat1'
172 IE_DESC = 'ProSiebenSat.1 Digital'
173 _VALID_URL = r'''(?x)
179 prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|advopedia
181 ran\.de|fem\.com|advopedia\.de|galileo\.tv/video
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:
190 # - malformed f4m manifest support
191 # - proper handling of URLs starting with `https?://` in 2.0 manifests
192 # - recursive child f4m manifests extraction
193 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
197 'title': 'CIRCUS HALLIGALLI - Episode 18 - Staffel 2',
198 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
199 'upload_date': '20131231',
201 'series': 'CIRCUS HALLIGALLI',
203 'episode': 'Episode 18 - Staffel 2',
204 'episode_number': 18,
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',
212 'title': 'Lady-Umstyling für Audrina',
213 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
214 'upload_date': '20131014',
219 'skip_download': True,
221 'skip': 'Seems to be broken',
224 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
228 'title': 'Countdown für die Autowerkstatt',
229 'description': 'md5:809fc051a457b5d8666013bc40698817',
230 'upload_date': '20140223',
235 'skip_download': True,
237 'skip': 'This video is unavailable',
240 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
244 'title': 'Sexy laufen in Ugg Boots',
245 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
246 'upload_date': '20140122',
251 'skip_download': True,
253 'skip': 'This video is unavailable',
256 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
260 'title': 'Im Interview: Kai Wiesinger',
261 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
262 'upload_date': '20140203',
267 'skip_download': True,
269 'skip': 'This video is unavailable',
272 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
276 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
277 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
278 'upload_date': '20141014',
283 'skip_download': True,
285 'skip': 'This video is unavailable',
288 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
292 'title': 'Schalke: Tönnies möchte Raul zurück',
293 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
294 'upload_date': '20140226',
299 'skip_download': True,
301 'skip': 'This video is unavailable',
304 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
308 'title': 'The Voice of Germany - Andreas Kümmert: Rocket Man',
309 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
310 'timestamp': 1382041620,
311 'upload_date': '20131017',
315 'skip_download': True,
319 'url': 'http://www.fem.com/videos/beauty-lifestyle/kurztrips-zum-valentinstag',
323 'title': 'Kurztrips zum Valentinstag',
324 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
328 'skip_download': True,
332 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
335 'title': 'Episode 8 - Ganze Folge - Playlist',
336 'description': 'md5:63b8963e71f481782aeea877658dec84',
339 'skip': 'This video is unavailable',
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',
347 'title': 'Jetzt erst enthüllt: Das Geheimnis von Emma Stones Oscar-Robe',
348 'description': 'md5:e5ace2bc43fadf7b63adc6187e9450b9',
349 'upload_date': '20170302',
352 'skip_download': True,
354 'skip': 'geo restricted to Germany',
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,
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,
367 # geo restricted to Germany
368 'url': 'https://www.galileo.tv/video/diese-emojis-werden-oft-missverstanden',
369 'only_matching': True,
372 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
373 'only_matching': True,
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,
382 _SALT = '01!8d8F_)r9]4s[qeuXfP%'
383 _CLIENT_NAME = 'kolibri-2.0.19-splec4'
385 _ACCESS_ID = 'x_prosiebenmaxx-de'
386 _ENCRYPTION_KEY = 'Eeyeey9oquahthainoofashoyoikosag'
387 _IV = 'Aeluchoc6aevechuipiexeeboowedaok'
390 r'"clip_id"\s*:\s+"(\d+)"',
393 r'clip[iI][dD]\s*=\s*["\'](\d+)',
394 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
395 r'proMamsId"\s*:\s*"(\d+)',
396 r'proMamsId"\s*:\s*"(\d+)',
399 r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
400 r'<header class="clearfix">\s*<h3>(.+?)</h3>',
401 r'<!-- start video -->\s*<h1>(.+?)</h1>',
402 r'<h1 class="att-name">\s*(.+?)</h1>',
403 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
404 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
405 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
406 r'<h2[^>]+class="subtitle"[^>]*>([^<]+)</h2>',
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>',
412 r'<p class="att-description">\s*(.+?)\s*</p>',
413 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
414 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
416 _UPLOAD_DATE_REGEXES = [
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/>',
422 _PAGE_TYPE_REGEXES = [
423 r'<meta name="page_type" content="([^"]+)">',
424 r"'itemType'\s*:\s*'([^']*)'",
426 _PLAYLIST_ID_REGEXES = [
427 r'content[iI]d=(\d+)',
428 r"'itemId'\s*:\s*'([^']*)'",
430 _PLAYLIST_CLIP_REGEXES = [
431 r'(?s)data-qvt=.+?<a href="([^"]+)"',
434 def _extract_clip(self, url, webpage):
435 clip_id = self._html_search_regex(
436 self._CLIPID_REGEXES, webpage, 'clip id')
437 title = self._html_search_regex(
438 self._TITLE_REGEXES, webpage, 'title',
439 default=None) or self._og_search_title(webpage)
440 info = self._extract_video_info(url, clip_id)
441 description = self._html_search_regex(
442 self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
443 if description is None:
444 description = self._og_search_description(webpage)
445 thumbnail = self._og_search_thumbnail(webpage)
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))
452 json_ld = self._search_json_ld(webpage, clip_id, default={})
454 return merge_dicts(info, {
457 'description': description,
458 'thumbnail': thumbnail,
459 'upload_date': upload_date,
462 def _extract_playlist(self, url, webpage):
463 playlist_id = self._html_search_regex(
464 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
465 playlist = self._parse_json(
467 r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
468 webpage, 'playlist'),
471 for item in playlist:
472 clip_id = item.get('id') or item.get('upc')
475 info = self._extract_video_info(url, 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'),
486 return self.playlist_result(entries, playlist_id)
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)
499 raise ExtractorError(
500 'Unsupported page type %s' % page_type, expected=True)