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.

79 lines
2.7 KiB

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