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