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