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