]>
Commit | Line | Data |
---|---|---|
87446dc6 HL |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | int_or_none, | |
7 | str_or_none, | |
8 | ) | |
9 | ||
10 | ||
11 | class TVCIE(InfoExtractor): | |
12 | _VALID_URL = r'http://(?:www\.)?tvc\.ru/.*/show/.*id/(?P<id>\d+)' | |
13 | _TESTS = [ | |
14 | { | |
15 | 'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/', | |
16 | 'md5': 'aa6fb3cf384e18a0ad3b30ee2898beba', | |
17 | 'info_dict': { | |
18 | 'id': '74622', | |
19 | 'display_id': '39702', | |
20 | 'ext': 'mp4', | |
21 | 'title': 'События. "События". Эфир от 22.05.2015 14:30', | |
22 | 'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd', | |
23 | 'thumbnail': 're:^https?://.*\.jpg$', | |
24 | 'duration': 1122, | |
25 | }, | |
26 | }, | |
27 | { | |
28 | 'url': 'http://www.tvc.ru/news/show/id/69944', | |
29 | 'md5': 'b173128ee7b88b5b06c84e5f7880909f', | |
30 | 'info_dict': { | |
31 | 'id': '75399', | |
32 | 'display_id': '69944', | |
33 | 'ext': 'mp4', | |
34 | 'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках', | |
35 | 'description': 'md5:f675c8eaf23aab9df542d31773ed6518', | |
36 | 'thumbnail': 're:^https?://.*\.jpg$', | |
37 | 'duration': 278, | |
38 | }, | |
39 | }, | |
40 | ] | |
41 | ||
42 | def _real_extract(self, url): | |
43 | display_id = self._match_id(url) | |
44 | ||
45 | webpage = self._download_webpage(url, display_id) | |
46 | ||
47 | video_url = self._og_search_video_url(webpage) | |
48 | ||
49 | video_id = self._search_regex( | |
50 | r'video/iframe/id/(\d+)/', video_url, 'video id') | |
51 | ||
52 | video_json_url = 'http://www.tvc.ru/video/json/id/%s' % (video_id) | |
53 | ||
54 | video_json = self._download_json(video_json_url, video_id) | |
55 | ||
56 | formats = [] | |
57 | for info in video_json.get('path', {}).get('quality', []): | |
58 | format_id = self._search_regex( | |
59 | r'cdnvideo/([^-]+)-[^/]+/', info.get('url'), 'format id', | |
60 | fatal=False) | |
61 | formats.append({ | |
62 | 'format_id': str_or_none(format_id), | |
63 | 'url': info.get('url'), | |
64 | 'width': int_or_none(info.get('width')), | |
65 | 'height': int_or_none(info.get('height')), | |
66 | 'tbr': int_or_none(info.get('bitrate')), | |
67 | }) | |
68 | ||
69 | self._sort_formats(formats) | |
70 | ||
71 | return { | |
72 | 'id': video_id, | |
73 | 'display_id': display_id, | |
74 | 'title': self._og_search_title(webpage), | |
75 | 'description': self._og_search_description(webpage), | |
76 | 'thumbnail': self._og_search_thumbnail(webpage), | |
77 | 'duration': int_or_none(video_json.get('duration')), | |
78 | 'formats': formats, | |
79 | } |