streamcz.py 2.8 KB

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