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.

65 lines
2.7 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class KontrTubeIE(InfoExtractor):
  7. IE_NAME = 'kontrtube'
  8. IE_DESC = 'KontrTube.ru - Труба зовёт'
  9. _VALID_URL = r'http://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/.+'
  10. _TEST = {
  11. 'url': 'http://www.kontrtube.ru/videos/2678/nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag/',
  12. 'md5': '975a991a4926c9a85f383a736a2e6b80',
  13. 'info_dict': {
  14. 'id': '2678',
  15. 'ext': 'mp4',
  16. 'title': 'Над олимпийской деревней в Сочи поднят российский флаг',
  17. 'description': 'md5:80edc4c613d5887ae8ccf1d59432be41',
  18. 'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg',
  19. 'duration': 270,
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage(url, video_id, 'Downloading page')
  26. video_url = self._html_search_regex(r"video_url: '(.+?)/?',", webpage, 'video URL')
  27. thumbnail = self._html_search_regex(r"preview_url: '(.+?)/?',", webpage, 'video thumbnail', fatal=False)
  28. title = self._html_search_regex(
  29. r'<title>(.+?) - Труба зовёт - Интересный видеохостинг</title>', webpage, 'video title')
  30. description = self._html_search_meta('description', webpage, 'video description')
  31. mobj = re.search(
  32. r'<div class="col_2">Длительность: <span>(?P<minutes>\d+)м:(?P<seconds>\d+)с</span></div>', webpage)
  33. duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
  34. view_count = self._html_search_regex(
  35. r'<div class="col_2">Просмотров: <span>(\d+)</span></div>', webpage, 'view count', fatal=False)
  36. comment_count = None
  37. comment_str = self._html_search_regex(
  38. r'Комментарии: <span>([^<]+)</span>', webpage, 'comment count', fatal=False)
  39. if comment_str.startswith('комментариев нет'):
  40. comment_count = 0
  41. else:
  42. mobj = re.search(r'\d+ из (?P<total>\d+) комментариев', comment_str)
  43. if mobj:
  44. comment_count = mobj.group('total')
  45. return {
  46. 'id': video_id,
  47. 'url': video_url,
  48. 'thumbnail': thumbnail,
  49. 'title': title,
  50. 'description': description,
  51. 'duration': duration,
  52. 'view_count': int_or_none(view_count),
  53. 'comment_count': int_or_none(comment_count),
  54. }