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.

57 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(
  35. 'video:width', webpage, 'video width', default=None))
  36. height = int_or_none(self._og_search_property(
  37. 'video:height', webpage, 'video height', default=None))
  38. return {
  39. 'id': video_id,
  40. 'url': video_url,
  41. 'title': title,
  42. 'description': description,
  43. 'thumbnail': thumbnail,
  44. 'duration': duration,
  45. 'width': width,
  46. 'height': height,
  47. }