]>
Commit | Line | Data |
---|---|---|
29902c8e S |
1 | import re |
2 | ||
87446dc6 HL |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
9f15bdab | 5 | clean_html, |
87446dc6 | 6 | int_or_none, |
87446dc6 HL |
7 | ) |
8 | ||
9 | ||
954c1d05 | 10 | class TVCIE(InfoExtractor): |
5886b38d | 11 | _VALID_URL = r'https?://(?:www\.)?tvc\.ru/video/iframe/id/(?P<id>\d+)' |
9f15bdab S |
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', | |
ec85ded8 | 19 | 'thumbnail': r're:^https?://.*\.jpg$', |
9f15bdab | 20 | 'duration': 1122, |
87446dc6 | 21 | }, |
9f15bdab | 22 | } |
87446dc6 | 23 | |
29902c8e S |
24 | @classmethod |
25 | def _extract_url(cls, webpage): | |
26 | mobj = re.search( | |
3d535e04 | 27 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:http:)?//(?:www\.)?tvc\.ru/video/iframe/id/[^"]+)\1', webpage) |
29902c8e S |
28 | if mobj: |
29 | return mobj.group('url') | |
30 | ||
87446dc6 | 31 | def _real_extract(self, url): |
9f15bdab | 32 | video_id = self._match_id(url) |
87446dc6 | 33 | |
9f15bdab S |
34 | video = self._download_json( |
35 | 'http://www.tvc.ru/video/json/id/%s' % video_id, video_id) | |
87446dc6 HL |
36 | |
37 | formats = [] | |
9f15bdab S |
38 | for info in video.get('path', {}).get('quality', []): |
39 | video_url = info.get('url') | |
40 | if not video_url: | |
41 | continue | |
87446dc6 | 42 | format_id = self._search_regex( |
9f15bdab S |
43 | r'cdnvideo/([^/]+?)(?:-[^/]+?)?/', video_url, |
44 | 'format id', default=None) | |
87446dc6 | 45 | formats.append({ |
9f15bdab S |
46 | 'url': video_url, |
47 | 'format_id': format_id, | |
87446dc6 HL |
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 | }) | |
87446dc6 HL |
52 | self._sort_formats(formats) |
53 | ||
54 | return { | |
55 | 'id': video_id, | |
9f15bdab S |
56 | 'title': video['title'], |
57 | 'thumbnail': video.get('picture'), | |
58 | 'duration': int_or_none(video.get('duration')), | |
87446dc6 HL |
59 | 'formats': formats, |
60 | } | |
9f15bdab S |
61 | |
62 | ||
954c1d05 | 63 | class TVCArticleIE(InfoExtractor): |
5886b38d | 64 | _VALID_URL = r'https?://(?:www\.)?tvc\.ru/(?!video/iframe/id/)(?P<id>[^?#]+)' |
9f15bdab S |
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', | |
ec85ded8 | 72 | 'thumbnail': r're:^https?://.*\.jpg$', |
9f15bdab S |
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', | |
ec85ded8 | 82 | 'thumbnail': r're:^https?://.*\.jpg$', |
9f15bdab S |
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', | |
ec85ded8 | 92 | 'thumbnail': r're:^https?://.*\.jpg$', |
9f15bdab S |
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', | |
5ccddb7e | 101 | 'ie_key': 'TVC', |
9f15bdab S |
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 | } |