]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
b542d4bb S |
2 | from __future__ import unicode_literals |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
2006a06e S |
7 | from ..utils import ( |
8 | int_or_none, | |
9 | parse_duration, | |
10 | ) | |
b542d4bb S |
11 | |
12 | ||
13 | class KontrTubeIE(InfoExtractor): | |
14 | IE_NAME = 'kontrtube' | |
15 | IE_DESC = 'KontrTube.ru - Труба зовёт' | |
5886b38d | 16 | _VALID_URL = r'https?://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/(?P<display_id>[^/]+)/' |
b542d4bb S |
17 | |
18 | _TEST = { | |
19 | 'url': 'http://www.kontrtube.ru/videos/2678/nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag/', | |
20 | 'md5': '975a991a4926c9a85f383a736a2e6b80', | |
21 | 'info_dict': { | |
22 | 'id': '2678', | |
2522a0b7 | 23 | 'display_id': 'nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag', |
b542d4bb S |
24 | 'ext': 'mp4', |
25 | 'title': 'Над олимпийской деревней в Сочи поднят российский флаг', | |
26 | 'description': 'md5:80edc4c613d5887ae8ccf1d59432be41', | |
27 | 'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg', | |
28 | 'duration': 270, | |
29 | } | |
30 | } | |
31 | ||
32 | def _real_extract(self, url): | |
33 | mobj = re.match(self._VALID_URL, url) | |
34 | video_id = mobj.group('id') | |
2522a0b7 | 35 | display_id = mobj.group('display_id') |
b542d4bb | 36 | |
2522a0b7 S |
37 | webpage = self._download_webpage( |
38 | url, display_id, 'Downloading page') | |
b542d4bb | 39 | |
2006a06e | 40 | video_url = self._search_regex( |
2522a0b7 | 41 | r"video_url\s*:\s*'(.+?)/?',", webpage, 'video URL') |
2006a06e S |
42 | thumbnail = self._search_regex( |
43 | r"preview_url\s*:\s*'(.+?)/?',", webpage, 'thumbnail', fatal=False) | |
bc2bdf57 | 44 | title = self._html_search_regex( |
2006a06e | 45 | r'(?s)<h2>(.+?)</h2>', webpage, 'title') |
2522a0b7 | 46 | description = self._html_search_meta( |
2006a06e | 47 | 'description', webpage, 'description') |
b542d4bb | 48 | |
2006a06e S |
49 | duration = self._search_regex( |
50 | r'Длительность: <em>([^<]+)</em>', webpage, 'duration', fatal=False) | |
51 | if duration: | |
52 | duration = parse_duration(duration.replace('мин', 'min').replace('сек', 'sec')) | |
b542d4bb | 53 | |
2006a06e S |
54 | view_count = self._search_regex( |
55 | r'Просмотров: <em>([^<]+)</em>', | |
2522a0b7 | 56 | webpage, 'view count', fatal=False) |
2006a06e S |
57 | if view_count: |
58 | view_count = int_or_none(view_count.replace(' ', '')) | |
b542d4bb | 59 | |
2006a06e S |
60 | comment_count = int_or_none(self._search_regex( |
61 | r'Комментарии \((\d+)\)<', webpage, ' comment count', fatal=False)) | |
b542d4bb S |
62 | |
63 | return { | |
64 | 'id': video_id, | |
2522a0b7 | 65 | 'display_id': display_id, |
b542d4bb S |
66 | 'url': video_url, |
67 | 'thumbnail': thumbnail, | |
68 | 'title': title, | |
69 | 'description': description, | |
70 | 'duration': duration, | |
bc2bdf57 S |
71 | 'view_count': int_or_none(view_count), |
72 | 'comment_count': int_or_none(comment_count), | |
5f6a1245 | 73 | } |