]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
0793a7b3 | 2 | from __future__ import unicode_literals |
3 | ||
a294bce8 NJ |
4 | import hashlib |
5 | import time | |
6 | ||
0793a7b3 | 7 | from .common import InfoExtractor |
418424e5 S |
8 | from ..utils import ( |
9 | int_or_none, | |
5c2266df | 10 | sanitized_Request, |
418424e5 | 11 | ) |
0793a7b3 | 12 | |
13 | ||
a294bce8 NJ |
14 | def _get_api_key(api_path): |
15 | if api_path.endswith('?'): | |
16 | api_path = api_path[:-1] | |
17 | ||
18 | api_key = 'fb5f58a820353bd7095de526253c14fd' | |
19 | a = '{0:}{1:}{2:}'.format(api_key, api_path, int(round(time.time() / 24 / 3600))) | |
20 | return hashlib.md5(a.encode('ascii')).hexdigest() | |
21 | ||
22 | ||
0793a7b3 | 23 | class StreamCZIE(InfoExtractor): |
20e35880 | 24 | _VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<id>[0-9]+)' |
a294bce8 | 25 | _API_URL = 'http://www.stream.cz/API' |
0793a7b3 | 26 | |
865dbd4a | 27 | _TESTS = [{ |
0793a7b3 | 28 | 'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti', |
29 | 'md5': '6d3ca61a8d0633c9c542b92fcb936b0c', | |
30 | 'info_dict': { | |
31 | 'id': '765767', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'Peklo na talíři: Éčka pro děti', | |
20e35880 PH |
34 | 'description': 'Taška s grónskou pomazánkou a další pekelnosti ZDE', |
35 | 'thumbnail': 're:^http://im.stream.cz/episode/52961d7e19d423f8f06f0100', | |
fa78f133 | 36 | 'duration': 256, |
0793a7b3 | 37 | }, |
865dbd4a | 38 | }, { |
c70df210 | 39 | 'url': 'http://www.stream.cz/blanik/10002447-tri-roky-pro-mazanka', |
20e35880 | 40 | 'md5': 'e54a254fb8b871968fd8403255f28589', |
865dbd4a | 41 | 'info_dict': { |
42 | 'id': '10002447', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'Kancelář Blaník: Tři roky pro Mazánka', | |
20e35880 PH |
45 | 'description': 'md5:3862a00ba7bf0b3e44806b544032c859', |
46 | 'thumbnail': 're:^http://im.stream.cz/episode/537f838c50c11f8d21320000', | |
865dbd4a | 47 | 'duration': 368, |
48 | }, | |
49 | }] | |
0793a7b3 | 50 | |
51 | def _real_extract(self, url): | |
20e35880 | 52 | video_id = self._match_id(url) |
a294bce8 NJ |
53 | api_path = '/episode/%s' % video_id |
54 | ||
5c2266df | 55 | req = sanitized_Request(self._API_URL + api_path) |
a294bce8 NJ |
56 | req.add_header('Api-Password', _get_api_key(api_path)) |
57 | data = self._download_json(req, video_id) | |
0793a7b3 | 58 | |
59 | formats = [] | |
20e35880 PH |
60 | for quality, video in enumerate(data['video_qualities']): |
61 | for f in video['formats']: | |
62 | typ = f['type'].partition('/')[2] | |
63 | qlabel = video.get('quality_label') | |
fa78f133 | 64 | formats.append({ |
20e35880 PH |
65 | 'format_note': '%s-%s' % (qlabel, typ) if qlabel else typ, |
66 | 'format_id': '%s-%s' % (typ, f['quality']), | |
67 | 'url': f['source'], | |
68 | 'height': int_or_none(f['quality'].rstrip('p')), | |
fa78f133 S |
69 | 'quality': quality, |
70 | }) | |
0793a7b3 | 71 | self._sort_formats(formats) |
72 | ||
20e35880 PH |
73 | image = data.get('image') |
74 | if image: | |
75 | thumbnail = self._proto_relative_url( | |
76 | image.replace('{width}', '1240').replace('{height}', '697'), | |
77 | scheme='http:', | |
78 | ) | |
79 | else: | |
80 | thumbnail = None | |
81 | ||
82 | stream = data.get('_embedded', {}).get('stream:show', {}).get('name') | |
83 | if stream: | |
84 | title = '%s: %s' % (stream, data['name']) | |
85 | else: | |
86 | title = data['name'] | |
87 | ||
0793a7b3 | 88 | return { |
20e35880 PH |
89 | 'id': video_id, |
90 | 'title': title, | |
91 | 'thumbnail': thumbnail, | |
0793a7b3 | 92 | 'formats': formats, |
20e35880 PH |
93 | 'description': data.get('web_site_text'), |
94 | 'duration': int_or_none(data.get('duration')), | |
95 | 'view_count': int_or_none(data.get('views')), | |
0793a7b3 | 96 | } |