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.

75 lines
2.9 KiB

10 years ago
  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+)/(?P<display_id>[^/]+)/'
  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. 'display_id': 'nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag',
  16. 'ext': 'mp4',
  17. 'title': 'Над олимпийской деревней в Сочи поднят российский флаг',
  18. 'description': 'md5:80edc4c613d5887ae8ccf1d59432be41',
  19. 'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg',
  20. 'duration': 270,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. display_id = mobj.group('display_id')
  27. webpage = self._download_webpage(
  28. url, display_id, 'Downloading page')
  29. video_url = self._html_search_regex(
  30. r"video_url\s*:\s*'(.+?)/?',", webpage, 'video URL')
  31. thumbnail = self._html_search_regex(
  32. r"preview_url\s*:\s*'(.+?)/?',", webpage, 'video thumbnail', fatal=False)
  33. title = self._html_search_regex(
  34. r'<title>(.+?)</title>', webpage, 'video title')
  35. description = self._html_search_meta(
  36. 'description', webpage, 'video description')
  37. mobj = re.search(
  38. r'<div class="col_2">Длительность: <span>(?P<minutes>\d+)м:(?P<seconds>\d+)с</span></div>',
  39. webpage)
  40. duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
  41. view_count = self._html_search_regex(
  42. r'<div class="col_2">Просмотров: <span>(\d+)</span></div>',
  43. webpage, 'view count', fatal=False)
  44. comment_count = None
  45. comment_str = self._html_search_regex(
  46. r'Комментарии: <span>([^<]+)</span>', webpage, 'comment count', fatal=False)
  47. if comment_str.startswith('комментариев нет'):
  48. comment_count = 0
  49. else:
  50. mobj = re.search(r'\d+ из (?P<total>\d+) комментариев', comment_str)
  51. if mobj:
  52. comment_count = mobj.group('total')
  53. return {
  54. 'id': video_id,
  55. 'display_id': display_id,
  56. 'url': video_url,
  57. 'thumbnail': thumbnail,
  58. 'title': title,
  59. 'description': description,
  60. 'duration': duration,
  61. 'view_count': int_or_none(view_count),
  62. 'comment_count': int_or_none(comment_count),
  63. }