]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/prosiebensat1.py
c6eee3b72a6e428012644ee7c10caad9be78fa86
[youtubedl] / youtube_dl / extractor / prosiebensat1.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from hashlib import sha1
7 from .common import InfoExtractor
8 from ..compat import compat_str
9 from ..utils import (
10 ExtractorError,
11 determine_ext,
12 float_or_none,
13 int_or_none,
14 unified_strdate,
15 )
16
17
18 class ProSiebenSat1IE(InfoExtractor):
19 IE_NAME = 'prosiebensat1'
20 IE_DESC = 'ProSiebenSat.1 Digital'
21 _VALID_URL = r'https?://(?:www\.)?(?:(?:prosieben|prosiebenmaxx|sixx|sat1|kabeleins|the-voice-of-germany|7tv)\.(?:de|at|ch)|ran\.de|fem\.com)/(?P<id>.+)'
22
23 _TESTS = [
24 {
25 # Tests changes introduced in https://github.com/rg3/youtube-dl/pull/6242
26 # in response to fixing https://github.com/rg3/youtube-dl/issues/6215:
27 # - malformed f4m manifest support
28 # - proper handling of URLs starting with `https?://` in 2.0 manifests
29 # - recursive child f4m manifests extraction
30 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
31 'info_dict': {
32 'id': '2104602',
33 'ext': 'flv',
34 'title': 'Episode 18 - Staffel 2',
35 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
36 'upload_date': '20131231',
37 'duration': 5845.04,
38 },
39 'params': {
40 # rtmp download
41 'skip_download': True,
42 },
43 },
44 {
45 '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',
46 'info_dict': {
47 'id': '2570327',
48 'ext': 'mp4',
49 'title': 'Lady-Umstyling für Audrina',
50 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
51 'upload_date': '20131014',
52 'duration': 606.76,
53 },
54 'params': {
55 # rtmp download
56 'skip_download': True,
57 },
58 'skip': 'Seems to be broken',
59 },
60 {
61 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
62 'info_dict': {
63 'id': '2429369',
64 'ext': 'mp4',
65 'title': 'Countdown für die Autowerkstatt',
66 'description': 'md5:809fc051a457b5d8666013bc40698817',
67 'upload_date': '20140223',
68 'duration': 2595.04,
69 },
70 'params': {
71 # rtmp download
72 'skip_download': True,
73 },
74 'skip': 'This video is unavailable',
75 },
76 {
77 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
78 'info_dict': {
79 'id': '2904997',
80 'ext': 'mp4',
81 'title': 'Sexy laufen in Ugg Boots',
82 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
83 'upload_date': '20140122',
84 'duration': 245.32,
85 },
86 'params': {
87 # rtmp download
88 'skip_download': True,
89 },
90 'skip': 'This video is unavailable',
91 },
92 {
93 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
94 'info_dict': {
95 'id': '2906572',
96 'ext': 'mp4',
97 'title': 'Im Interview: Kai Wiesinger',
98 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
99 'upload_date': '20140203',
100 'duration': 522.56,
101 },
102 'params': {
103 # rtmp download
104 'skip_download': True,
105 },
106 'skip': 'This video is unavailable',
107 },
108 {
109 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
110 'info_dict': {
111 'id': '2992323',
112 'ext': 'mp4',
113 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
114 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
115 'upload_date': '20141014',
116 'duration': 2410.44,
117 },
118 'params': {
119 # rtmp download
120 'skip_download': True,
121 },
122 'skip': 'This video is unavailable',
123 },
124 {
125 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
126 'info_dict': {
127 'id': '3004256',
128 'ext': 'mp4',
129 'title': 'Schalke: Tönnies möchte Raul zurück',
130 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
131 'upload_date': '20140226',
132 'duration': 228.96,
133 },
134 'params': {
135 # rtmp download
136 'skip_download': True,
137 },
138 'skip': 'This video is unavailable',
139 },
140 {
141 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
142 'info_dict': {
143 'id': '2572814',
144 'ext': 'flv',
145 'title': 'Andreas Kümmert: Rocket Man',
146 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
147 'upload_date': '20131017',
148 'duration': 469.88,
149 },
150 'params': {
151 'skip_download': True,
152 },
153 },
154 {
155 'url': 'http://www.fem.com/wellness/videos/wellness-video-clip-kurztripps-zum-valentinstag.html',
156 'info_dict': {
157 'id': '2156342',
158 'ext': 'flv',
159 'title': 'Kurztrips zum Valentinstag',
160 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
161 'duration': 307.24,
162 },
163 'params': {
164 'skip_download': True,
165 },
166 },
167 {
168 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
169 'info_dict': {
170 'id': '439664',
171 'title': 'Episode 8 - Ganze Folge - Playlist',
172 'description': 'md5:63b8963e71f481782aeea877658dec84',
173 },
174 'playlist_count': 2,
175 },
176 {
177 'url': 'http://www.7tv.de/circus-halligalli/615-best-of-circus-halligalli-ganze-folge',
178 'info_dict': {
179 'id': '4187506',
180 'ext': 'flv',
181 'title': 'Best of Circus HalliGalli',
182 'description': 'md5:8849752efd90b9772c9db6fdf87fb9e9',
183 'upload_date': '20151229',
184 },
185 'params': {
186 'skip_download': True,
187 },
188 },
189 ]
190
191 _CLIPID_REGEXES = [
192 r'"clip_id"\s*:\s+"(\d+)"',
193 r'clipid: "(\d+)"',
194 r'clip[iI]d=(\d+)',
195 r'clip[iI]d\s*=\s*["\'](\d+)',
196 r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
197 ]
198 _TITLE_REGEXES = [
199 r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
200 r'<header class="clearfix">\s*<h3>(.+?)</h3>',
201 r'<!-- start video -->\s*<h1>(.+?)</h1>',
202 r'<h1 class="att-name">\s*(.+?)</h1>',
203 r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
204 r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
205 r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
206 ]
207 _DESCRIPTION_REGEXES = [
208 r'<p itemprop="description">\s*(.+?)</p>',
209 r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
210 r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
211 r'<p class="att-description">\s*(.+?)\s*</p>',
212 r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
213 r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
214 ]
215 _UPLOAD_DATE_REGEXES = [
216 r'<meta property="og:published_time" content="(.+?)">',
217 r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
218 r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
219 r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
220 r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
221 ]
222 _PAGE_TYPE_REGEXES = [
223 r'<meta name="page_type" content="([^"]+)">',
224 r"'itemType'\s*:\s*'([^']*)'",
225 ]
226 _PLAYLIST_ID_REGEXES = [
227 r'content[iI]d=(\d+)',
228 r"'itemId'\s*:\s*'([^']*)'",
229 ]
230 _PLAYLIST_CLIP_REGEXES = [
231 r'(?s)data-qvt=.+?<a href="([^"]+)"',
232 ]
233
234 def _extract_clip(self, url, webpage):
235 clip_id = self._html_search_regex(
236 self._CLIPID_REGEXES, webpage, 'clip id')
237
238 access_token = 'prosieben'
239 client_name = 'kolibri-2.0.19-splec4'
240 client_location = url
241
242 video = self._download_json(
243 'http://vas.sim-technik.de/vas/live/v2/videos',
244 clip_id, 'Downloading videos JSON', query={
245 'access_token': access_token,
246 'client_location': client_location,
247 'client_name': client_name,
248 'ids': clip_id,
249 })[0]
250
251 if video.get('is_protected') is True:
252 raise ExtractorError('This video is DRM protected.', expected=True)
253
254 duration = float_or_none(video.get('duration'))
255 source_ids = [compat_str(source['id']) for source in video['sources']]
256
257 g = '01!8d8F_)r9]4s[qeuXfP%'
258 client_id = g[:2] + sha1(''.join([clip_id, g, access_token, client_location, g, client_name]).encode('utf-8')).hexdigest()
259
260 sources = self._download_json(
261 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources' % clip_id,
262 clip_id, 'Downloading sources JSON', query={
263 'access_token': access_token,
264 'client_id': client_id,
265 'client_location': client_location,
266 'client_name': client_name,
267 })
268 server_id = sources['server_id']
269
270 title = self._html_search_regex(self._TITLE_REGEXES, webpage, 'title')
271
272 def fix_bitrate(bitrate):
273 bitrate = int_or_none(bitrate)
274 if not bitrate:
275 return None
276 return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
277
278 formats = []
279 for source_id in source_ids:
280 client_id = g[:2] + sha1(''.join([g, clip_id, access_token, server_id, client_location, source_id, g, client_name]).encode('utf-8')).hexdigest()
281 urls = self._download_json(
282 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url' % clip_id,
283 clip_id, 'Downloading urls JSON', fatal=False, query={
284 'access_token': access_token,
285 'client_id': client_id,
286 'client_location': client_location,
287 'client_name': client_name,
288 'server_id': server_id,
289 'source_ids': source_id,
290 })
291 if not urls:
292 continue
293 if urls.get('status_code') != 0:
294 raise ExtractorError('This video is unavailable', expected=True)
295 urls_sources = urls['sources']
296 if isinstance(urls_sources, dict):
297 urls_sources = urls_sources.values()
298 for source in urls_sources:
299 source_url = source.get('url')
300 if not source_url:
301 continue
302 protocol = source.get('protocol')
303 mimetype = source.get('mimetype')
304 if mimetype == 'application/f4m+xml' or 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
305 formats.extend(self._extract_f4m_formats(
306 source_url, clip_id, f4m_id='hds', fatal=False))
307 elif mimetype == 'application/x-mpegURL':
308 formats.extend(self._extract_m3u8_formats(
309 source_url, clip_id, 'mp4', 'm3u8_native',
310 m3u8_id='hls', fatal=False))
311 else:
312 tbr = fix_bitrate(source['bitrate'])
313 if protocol in ('rtmp', 'rtmpe'):
314 mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
315 if not mobj:
316 continue
317 path = mobj.group('path')
318 mp4colon_index = path.rfind('mp4:')
319 app = path[:mp4colon_index]
320 play_path = path[mp4colon_index:]
321 formats.append({
322 'url': '%s/%s' % (mobj.group('url'), app),
323 'app': app,
324 'play_path': play_path,
325 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
326 'page_url': 'http://www.prosieben.de',
327 'tbr': tbr,
328 'ext': 'flv',
329 'format_id': 'rtmp%s' % ('-%d' % tbr if tbr else ''),
330 })
331 else:
332 formats.append({
333 'url': source_url,
334 'tbr': tbr,
335 'format_id': 'http%s' % ('-%d' % tbr if tbr else ''),
336 })
337 self._sort_formats(formats)
338
339 description = self._html_search_regex(
340 self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
341 thumbnail = self._og_search_thumbnail(webpage)
342 upload_date = unified_strdate(self._html_search_regex(
343 self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
344
345 return {
346 'id': clip_id,
347 'title': title,
348 'description': description,
349 'thumbnail': thumbnail,
350 'upload_date': upload_date,
351 'duration': duration,
352 'formats': formats,
353 }
354
355 def _extract_playlist(self, url, webpage):
356 playlist_id = self._html_search_regex(
357 self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
358 for regex in self._PLAYLIST_CLIP_REGEXES:
359 playlist_clips = re.findall(regex, webpage)
360 if playlist_clips:
361 title = self._html_search_regex(
362 self._TITLE_REGEXES, webpage, 'title')
363 description = self._html_search_regex(
364 self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
365 entries = [
366 self.url_result(
367 re.match('(.+?//.+?)/', url).group(1) + clip_path,
368 'ProSiebenSat1')
369 for clip_path in playlist_clips]
370 return self.playlist_result(entries, playlist_id, title, description)
371
372 def _real_extract(self, url):
373 video_id = self._match_id(url)
374 webpage = self._download_webpage(url, video_id)
375 page_type = self._search_regex(
376 self._PAGE_TYPE_REGEXES, webpage,
377 'page type', default='clip').lower()
378 if page_type == 'clip':
379 return self._extract_clip(url, webpage)
380 elif page_type == 'playlist':
381 return self._extract_playlist(url, webpage)