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