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