2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..utils import int_or_none
10 class KontrTubeIE(InfoExtractor):
12 IE_DESC = 'KontrTube.ru - Труба зовёт'
13 _VALID_URL = r'http://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/.+'
16 'url': 'http://www.kontrtube.ru/videos/2678/nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag/',
17 'md5': '975a991a4926c9a85f383a736a2e6b80',
21 'title': 'Над олимпийской деревней в Сочи поднят российский флаг',
22 'description': 'md5:80edc4c613d5887ae8ccf1d59432be41',
23 'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg',
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
32 webpage = self._download_webpage(url, video_id, 'Downloading page')
34 video_url = self._html_search_regex(r"video_url: '(.+?)/?',", webpage, 'video URL')
35 thumbnail = self._html_search_regex(r"preview_url: '(.+?)/?',", webpage, 'video thumbnail', fatal=False)
36 title = self._html_search_regex(
37 r'<title>(.+?)</title>', webpage, 'video title')
38 description = self._html_search_meta('description', webpage, 'video description')
41 r'<div class="col_2">Длительность: <span>(?P<minutes>\d+)м:(?P<seconds>\d+)с</span></div>', webpage)
42 duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
44 view_count = self._html_search_regex(
45 r'<div class="col_2">Просмотров: <span>(\d+)</span></div>', webpage, 'view count', fatal=False)
48 comment_str = self._html_search_regex(
49 r'Комментарии: <span>([^<]+)</span>', webpage, 'comment count', fatal=False)
50 if comment_str.startswith('комментариев нет'):
53 mobj = re.search(r'\d+ из (?P<total>\d+) комментариев', comment_str)
55 comment_count = mobj.group('total')
60 'thumbnail': thumbnail,
62 'description': description,
64 'view_count': int_or_none(view_count),
65 'comment_count': int_or_none(comment_count),