]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tvc.py
4ccc8f5227bada759c22fcbf404393dd07cc46b2
[yt-dlp.git] / yt_dlp / extractor / tvc.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 clean_html,
6 int_or_none,
7 )
8
9
10 class TVCIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?tvc\.ru/video/iframe/id/(?P<id>\d+)'
12 _TEST = {
13 'url': 'http://www.tvc.ru/video/iframe/id/74622/isPlay/false/id_stat/channel/?acc_video_id=/channel/brand/id/17/show/episodes/episode_id/39702',
14 'md5': 'bbc5ff531d1e90e856f60fc4b3afd708',
15 'info_dict': {
16 'id': '74622',
17 'ext': 'mp4',
18 'title': 'События. "События". Эфир от 22.05.2015 14:30',
19 'thumbnail': r're:^https?://.*\.jpg$',
20 'duration': 1122,
21 },
22 }
23
24 @classmethod
25 def _extract_url(cls, webpage):
26 mobj = re.search(
27 r'<iframe[^>]+?src=(["\'])(?P<url>(?:http:)?//(?:www\.)?tvc\.ru/video/iframe/id/[^"]+)\1', webpage)
28 if mobj:
29 return mobj.group('url')
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33
34 video = self._download_json(
35 'http://www.tvc.ru/video/json/id/%s' % video_id, video_id)
36
37 formats = []
38 for info in video.get('path', {}).get('quality', []):
39 video_url = info.get('url')
40 if not video_url:
41 continue
42 format_id = self._search_regex(
43 r'cdnvideo/([^/]+?)(?:-[^/]+?)?/', video_url,
44 'format id', default=None)
45 formats.append({
46 'url': video_url,
47 'format_id': format_id,
48 'width': int_or_none(info.get('width')),
49 'height': int_or_none(info.get('height')),
50 'tbr': int_or_none(info.get('bitrate')),
51 })
52 self._sort_formats(formats)
53
54 return {
55 'id': video_id,
56 'title': video['title'],
57 'thumbnail': video.get('picture'),
58 'duration': int_or_none(video.get('duration')),
59 'formats': formats,
60 }
61
62
63 class TVCArticleIE(InfoExtractor):
64 _VALID_URL = r'https?://(?:www\.)?tvc\.ru/(?!video/iframe/id/)(?P<id>[^?#]+)'
65 _TESTS = [{
66 'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/',
67 'info_dict': {
68 'id': '74622',
69 'ext': 'mp4',
70 'title': 'События. "События". Эфир от 22.05.2015 14:30',
71 'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd',
72 'thumbnail': r're:^https?://.*\.jpg$',
73 'duration': 1122,
74 },
75 }, {
76 'url': 'http://www.tvc.ru/news/show/id/69944',
77 'info_dict': {
78 'id': '75399',
79 'ext': 'mp4',
80 'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках',
81 'description': 'md5:f2098f71e21f309e89f69b525fd9846e',
82 'thumbnail': r're:^https?://.*\.jpg$',
83 'duration': 278,
84 },
85 }, {
86 'url': 'http://www.tvc.ru/channel/brand/id/47/show/episodes#',
87 'info_dict': {
88 'id': '2185',
89 'ext': 'mp4',
90 'title': 'Ещё не поздно. Эфир от 03.08.2013',
91 'description': 'md5:51fae9f3f8cfe67abce014e428e5b027',
92 'thumbnail': r're:^https?://.*\.jpg$',
93 'duration': 3316,
94 },
95 }]
96
97 def _real_extract(self, url):
98 webpage = self._download_webpage(url, self._match_id(url))
99 return {
100 '_type': 'url_transparent',
101 'ie_key': 'TVC',
102 'url': self._og_search_video_url(webpage),
103 'title': clean_html(self._og_search_title(webpage)),
104 'description': clean_html(self._og_search_description(webpage)),
105 'thumbnail': self._og_search_thumbnail(webpage),
106 }