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