1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
7 from .common import InfoExtractor
16 def _get_api_key(api_path):
17 if api_path.endswith('?'):
18 api_path = api_path[:-1]
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()
25 class StreamCZIE(InfoExtractor):
26 _VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<id>[0-9]+)'
27 _API_URL = 'http://www.stream.cz/API'
30 'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti',
31 'md5': '6d3ca61a8d0633c9c542b92fcb936b0c',
35 'title': 'Peklo na talíři: Éčka pro děti',
36 'description': 'Taška s grónskou pomazánkou a další pekelnosti ZDE',
37 'thumbnail': 're:^http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
41 'url': 'http://www.stream.cz/blanik/10002447-tri-roky-pro-mazanka',
42 'md5': 'e54a254fb8b871968fd8403255f28589',
46 'title': 'Kancelář Blaník: Tři roky pro Mazánka',
47 'description': 'md5:3862a00ba7bf0b3e44806b544032c859',
48 'thumbnail': 're:^http://im.stream.cz/episode/537f838c50c11f8d21320000',
53 def _real_extract(self, url):
54 video_id = self._match_id(url)
55 api_path = '/episode/%s' % video_id
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)
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')
67 'format_note': '%s-%s' % (qlabel, typ) if qlabel else typ,
68 'format_id': '%s-%s' % (typ, f['quality']),
70 'height': int_or_none(f['quality'].rstrip('p')),
73 self._sort_formats(formats)
75 image = data.get('image')
77 thumbnail = self._proto_relative_url(
78 image.replace('{width}', '1240').replace('{height}', '697'),
84 stream = data.get('_embedded', {}).get('stream:show', {}).get('name')
86 title = '%s: %s' % (stream, data['name'])
93 'thumbnail': thumbnail,
95 'description': data.get('web_site_text'),
96 'duration': int_or_none(data.get('duration')),
97 'view_count': int_or_none(data.get('views')),