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