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.

60 lines
1.9 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. 'params': {
  24. 'skip_download': 'Not accessible from Travis CI server',
  25. },
  26. }
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. flashvars = json.loads(js_to_json(self._search_regex(
  31. r'video_Init\(({.+?})', webpage, 'flashvars')))
  32. video_url = flashvars['url']
  33. title = self._og_search_title(webpage)
  34. description = self._og_search_description(webpage, default=None)
  35. thumbnail = flashvars.get('image') or self._og_search_thumbnail(webpage)
  36. duration = int_or_none(flashvars.get('duration'))
  37. width = int_or_none(self._og_search_property(
  38. 'video:width', webpage, 'video width', default=None))
  39. height = int_or_none(self._og_search_property(
  40. 'video:height', webpage, 'video height', default=None))
  41. return {
  42. 'id': video_id,
  43. 'url': video_url,
  44. 'title': title,
  45. 'description': description,
  46. 'thumbnail': thumbnail,
  47. 'duration': duration,
  48. 'width': width,
  49. 'height': height,
  50. }