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.

67 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import int_or_none
  7. class StreamCZIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<videoid>.+)'
  9. _TEST = {
  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': 'md5:49ace0df986e95e331d0fe239d421519',
  17. 'thumbnail': 'http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
  18. 'duration': 256,
  19. },
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('videoid')
  24. webpage = self._download_webpage(url, video_id)
  25. data = self._html_search_regex(r'Stream\.Data\.Episode\((.+?)\);', webpage, 'stream data')
  26. jsonData = json.loads(data)
  27. formats = []
  28. for video in jsonData['instances']:
  29. for video_format in video['instances']:
  30. format_id = video_format['quality']
  31. if format_id == '240p':
  32. quality = 0
  33. elif format_id == '360p':
  34. quality = 1
  35. elif format_id == '480p':
  36. quality = 2
  37. elif format_id == '720p':
  38. quality = 3
  39. formats.append({
  40. 'format_id': '%s-%s' % (video_format['type'].split('/')[1], format_id),
  41. 'url': video_format['source'],
  42. 'quality': quality,
  43. })
  44. self._sort_formats(formats)
  45. return {
  46. 'id': str(jsonData['id']),
  47. 'title': self._og_search_title(webpage),
  48. 'thumbnail': jsonData['episode_image_original_url'].replace('//', 'http://'),
  49. 'formats': formats,
  50. 'description': self._og_search_description(webpage),
  51. 'duration': int_or_none(jsonData['duration']),
  52. 'view_count': int_or_none(jsonData['stats_total']),
  53. }