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.

55 lines
1.8 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. js_to_json,
  8. )
  9. class KrasViewIE(InfoExtractor):
  10. IE_DESC = 'Красвью'
  11. _VALID_URL = r'https?://krasview\.ru/(?:video|embed)/(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'http://krasview.ru/video/512228',
  14. 'md5': '3b91003cf85fc5db277870c8ebd98eae',
  15. 'info_dict': {
  16. 'id': '512228',
  17. 'ext': 'mp4',
  18. 'title': 'Снег, лёд, заносы',
  19. 'description': 'Снято в городе Нягань, в Ханты-Мансийском автономном округе.',
  20. 'duration': 27,
  21. 'thumbnail': 're:^https?://.*\.jpg',
  22. },
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. flashvars = json.loads(js_to_json(self._search_regex(
  28. r'video_Init\(({.+?})', webpage, 'flashvars')))
  29. video_url = flashvars['url']
  30. title = self._og_search_title(webpage)
  31. description = self._og_search_description(webpage, default=None)
  32. thumbnail = flashvars.get('image') or self._og_search_thumbnail(webpage)
  33. duration = int_or_none(flashvars.get('duration'))
  34. width = int_or_none(self._og_search_property('video:width', webpage, 'video width'))
  35. height = int_or_none(self._og_search_property('video:height', webpage, 'video height'))
  36. return {
  37. 'id': video_id,
  38. 'url': video_url,
  39. 'title': title,
  40. 'description': description,
  41. 'thumbnail': thumbnail,
  42. 'duration': duration,
  43. 'width': width,
  44. 'height': height,
  45. }