2 from __future__ import unicode_literals
7 from .common import InfoExtractor
14 def _get_api_key(api_path):
15 if api_path.endswith('?'):
16 api_path = api_path[:-1]
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()
23 class StreamCZIE(InfoExtractor):
24 _VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<id>[0-9]+)'
25 _API_URL = 'http://www.stream.cz/API'
28 'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti',
29 'md5': '934bb6a6d220d99c010783c9719960d5',
33 'title': 'Peklo na talíři: Éčka pro děti',
34 'description': 'Taška s grónskou pomazánkou a další pekelnosti ZDE',
35 'thumbnail': 're:^http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
39 'url': 'http://www.stream.cz/blanik/10002447-tri-roky-pro-mazanka',
40 'md5': '849a88c1e1ca47d41403c2ba5e59e261',
44 'title': 'Kancelář Blaník: Tři roky pro Mazánka',
45 'description': 'md5:3862a00ba7bf0b3e44806b544032c859',
46 'thumbnail': 're:^http://im.stream.cz/episode/537f838c50c11f8d21320000',
51 def _real_extract(self, url):
52 video_id = self._match_id(url)
53 api_path = '/episode/%s' % video_id
55 req = sanitized_Request(self._API_URL + api_path)
56 req.add_header('Api-Password', _get_api_key(api_path))
57 data = self._download_json(req, video_id)
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')
65 'format_note': '%s-%s' % (qlabel, typ) if qlabel else typ,
66 'format_id': '%s-%s' % (typ, f['quality']),
68 'height': int_or_none(f['quality'].rstrip('p')),
71 self._sort_formats(formats)
73 image = data.get('image')
75 thumbnail = self._proto_relative_url(
76 image.replace('{width}', '1240').replace('{height}', '697'),
82 stream = data.get('_embedded', {}).get('stream:show', {}).get('name')
84 title = '%s: %s' % (stream, data['name'])
89 srt_url = data.get('subtitles_srt')
99 'thumbnail': thumbnail,
101 'description': data.get('web_site_text'),
102 'duration': int_or_none(data.get('duration')),
103 'view_count': int_or_none(data.get('views')),
104 'subtitles': subtitles,