You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.2 KiB

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