2014-02-09 05:53:11 -07:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-08-23 09:43:28 -06:00
|
|
|
|
from ..utils import (
|
|
|
|
|
int_or_none,
|
|
|
|
|
parse_duration,
|
|
|
|
|
)
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KontrTubeIE(InfoExtractor):
|
|
|
|
|
IE_NAME = 'kontrtube'
|
|
|
|
|
IE_DESC = 'KontrTube.ru - Труба зовёт'
|
2016-03-21 09:36:32 -06:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/(?P<display_id>[^/]+)/'
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
|
|
|
|
_TEST = {
|
|
|
|
|
'url': 'http://www.kontrtube.ru/videos/2678/nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag/',
|
|
|
|
|
'md5': '975a991a4926c9a85f383a736a2e6b80',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2678',
|
2015-01-02 09:28:48 -07:00
|
|
|
|
'display_id': 'nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag',
|
2014-02-09 05:53:11 -07:00
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Над олимпийской деревней в Сочи поднят российский флаг',
|
|
|
|
|
'description': 'md5:80edc4c613d5887ae8ccf1d59432be41',
|
|
|
|
|
'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg',
|
|
|
|
|
'duration': 270,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
|
video_id = mobj.group('id')
|
2015-01-02 09:28:48 -07:00
|
|
|
|
display_id = mobj.group('display_id')
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
2015-01-02 09:28:48 -07:00
|
|
|
|
webpage = self._download_webpage(
|
|
|
|
|
url, display_id, 'Downloading page')
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
2015-08-23 09:43:28 -06:00
|
|
|
|
video_url = self._search_regex(
|
2015-01-02 09:28:48 -07:00
|
|
|
|
r"video_url\s*:\s*'(.+?)/?',", webpage, 'video URL')
|
2015-08-23 09:43:28 -06:00
|
|
|
|
thumbnail = self._search_regex(
|
|
|
|
|
r"preview_url\s*:\s*'(.+?)/?',", webpage, 'thumbnail', fatal=False)
|
2014-03-20 10:05:57 -06:00
|
|
|
|
title = self._html_search_regex(
|
2015-08-23 09:43:28 -06:00
|
|
|
|
r'(?s)<h2>(.+?)</h2>', webpage, 'title')
|
2015-01-02 09:28:48 -07:00
|
|
|
|
description = self._html_search_meta(
|
2015-08-23 09:43:28 -06:00
|
|
|
|
'description', webpage, 'description')
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
2015-08-23 09:43:28 -06:00
|
|
|
|
duration = self._search_regex(
|
|
|
|
|
r'Длительность: <em>([^<]+)</em>', webpage, 'duration', fatal=False)
|
|
|
|
|
if duration:
|
|
|
|
|
duration = parse_duration(duration.replace('мин', 'min').replace('сек', 'sec'))
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
2015-08-23 09:43:28 -06:00
|
|
|
|
view_count = self._search_regex(
|
|
|
|
|
r'Просмотров: <em>([^<]+)</em>',
|
2015-01-02 09:28:48 -07:00
|
|
|
|
webpage, 'view count', fatal=False)
|
2015-08-23 09:43:28 -06:00
|
|
|
|
if view_count:
|
|
|
|
|
view_count = int_or_none(view_count.replace(' ', ''))
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
2015-08-23 09:43:28 -06:00
|
|
|
|
comment_count = int_or_none(self._search_regex(
|
|
|
|
|
r'Комментарии \((\d+)\)<', webpage, ' comment count', fatal=False))
|
2014-02-09 05:53:11 -07:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
2015-01-02 09:28:48 -07:00
|
|
|
|
'display_id': display_id,
|
2014-02-09 05:53:11 -07:00
|
|
|
|
'url': video_url,
|
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
|
'title': title,
|
|
|
|
|
'description': description,
|
|
|
|
|
'duration': duration,
|
2014-03-20 10:05:57 -06:00
|
|
|
|
'view_count': int_or_none(view_count),
|
|
|
|
|
'comment_count': int_or_none(comment_count),
|
2014-11-23 12:41:03 -07:00
|
|
|
|
}
|