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.

81 lines
2.7 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 (
  7. int_or_none,
  8. compat_str,
  9. )
  10. class StreamCZIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?stream\.cz/.+/(?P<videoid>.+)'
  12. _TESTS = [{
  13. 'url': 'http://www.stream.cz/peklonataliri/765767-ecka-pro-deti',
  14. 'md5': '6d3ca61a8d0633c9c542b92fcb936b0c',
  15. 'info_dict': {
  16. 'id': '765767',
  17. 'ext': 'mp4',
  18. 'title': 'Peklo na talíři: Éčka pro děti',
  19. 'description': 'md5:49ace0df986e95e331d0fe239d421519',
  20. 'thumbnail': 'http://im.stream.cz/episode/52961d7e19d423f8f06f0100',
  21. 'duration': 256,
  22. },
  23. }, {
  24. 'url': 'http://www.stream.cz/blanik/10002447-tri-roky-pro-mazanka',
  25. 'md5': '246272e753e26bbace7fcd9deca0650c',
  26. 'info_dict': {
  27. 'id': '10002447',
  28. 'ext': 'mp4',
  29. 'title': 'Kancelář Blaník: Tři roky pro Mazánka',
  30. 'description': 'md5:9177695a8b756a0a8ab160de4043b392',
  31. 'thumbnail': 'http://im.stream.cz/episode/537f838c50c11f8d21320000',
  32. 'duration': 368,
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. mobj = re.match(self._VALID_URL, url)
  37. video_id = mobj.group('videoid')
  38. webpage = self._download_webpage(url, video_id)
  39. data = self._html_search_regex(r'Stream\.Data\.Episode\((.+?)\);', webpage, 'stream data')
  40. jsonData = json.loads(data)
  41. formats = []
  42. for video in jsonData['instances']:
  43. for video_format in video['instances']:
  44. format_id = video_format['quality']
  45. if format_id == '240p':
  46. quality = 0
  47. elif format_id == '360p':
  48. quality = 1
  49. elif format_id == '480p':
  50. quality = 2
  51. elif format_id == '720p':
  52. quality = 3
  53. formats.append({
  54. 'format_id': '%s-%s' % (video_format['type'].split('/')[1], format_id),
  55. 'url': video_format['source'],
  56. 'quality': quality,
  57. })
  58. self._sort_formats(formats)
  59. return {
  60. 'id': compat_str(jsonData['episode_id']),
  61. 'title': self._og_search_title(webpage),
  62. 'thumbnail': jsonData['episode_image_original_url'].replace('//', 'http://'),
  63. 'formats': formats,
  64. 'description': self._og_search_description(webpage),
  65. 'duration': int_or_none(jsonData['duration']),
  66. 'view_count': int_or_none(jsonData['stats_total']),
  67. }