]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kontrtube.py
Update upstream source from tag 'upstream/2018.11.07'
[youtubedl] / youtube_dl / extractor / kontrtube.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 parse_duration,
10 )
11
12
13 class KontrTubeIE(InfoExtractor):
14 IE_NAME = 'kontrtube'
15 IE_DESC = 'KontrTube.ru - Труба зовёт'
16 _VALID_URL = r'https?://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/(?P<display_id>[^/]+)/'
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',
23 'display_id': 'nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag',
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')
35 display_id = mobj.group('display_id')
36
37 webpage = self._download_webpage(
38 url, display_id, 'Downloading page')
39
40 video_url = self._search_regex(
41 r"video_url\s*:\s*'(.+?)/?',", webpage, 'video URL')
42 thumbnail = self._search_regex(
43 r"preview_url\s*:\s*'(.+?)/?',", webpage, 'thumbnail', fatal=False)
44 title = self._html_search_regex(
45 r'(?s)<h2>(.+?)</h2>', webpage, 'title')
46 description = self._html_search_meta(
47 'description', webpage, 'description')
48
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'))
53
54 view_count = self._search_regex(
55 r'Просмотров: <em>([^<]+)</em>',
56 webpage, 'view count', fatal=False)
57 if view_count:
58 view_count = int_or_none(view_count.replace(' ', ''))
59
60 comment_count = int_or_none(self._search_regex(
61 r'Комментарии \((\d+)\)<', webpage, ' comment count', fatal=False))
62
63 return {
64 'id': video_id,
65 'display_id': display_id,
66 'url': video_url,
67 'thumbnail': thumbnail,
68 'title': title,
69 'description': description,
70 'duration': duration,
71 'view_count': int_or_none(view_count),
72 'comment_count': int_or_none(comment_count),
73 }