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