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