]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
4 | format_field, | |
5 | float_or_none, | |
6 | int_or_none, | |
7 | try_get, | |
8 | ) | |
9 | ||
10 | from .videomore import VideomoreIE | |
11 | ||
12 | ||
13 | class CarambaTVIE(InfoExtractor): | |
14 | _VALID_URL = r'(?:carambatv:|https?://video1\.carambatv\.ru/v/)(?P<id>\d+)' | |
15 | _TESTS = [{ | |
16 | 'url': 'http://video1.carambatv.ru/v/191910501', | |
17 | 'md5': '2f4a81b7cfd5ab866ee2d7270cb34a2a', | |
18 | 'info_dict': { | |
19 | 'id': '191910501', | |
20 | 'ext': 'mp4', | |
21 | 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)', | |
22 | 'thumbnail': r're:^https?://.*\.jpg', | |
23 | 'duration': 2678.31, | |
24 | }, | |
25 | }, { | |
26 | 'url': 'carambatv:191910501', | |
27 | 'only_matching': True, | |
28 | }] | |
29 | ||
30 | def _real_extract(self, url): | |
31 | video_id = self._match_id(url) | |
32 | ||
33 | video = self._download_json( | |
34 | 'http://video1.carambatv.ru/v/%s/videoinfo.js' % video_id, | |
35 | video_id) | |
36 | ||
37 | title = video['title'] | |
38 | ||
39 | base_url = video.get('video') or 'http://video1.carambatv.ru/v/%s/' % video_id | |
40 | ||
41 | formats = [{ | |
42 | 'url': base_url + f['fn'], | |
43 | 'height': int_or_none(f.get('height')), | |
44 | 'format_id': format_field(f, 'height', '%sp'), | |
45 | } for f in video['qualities'] if f.get('fn')] | |
46 | ||
47 | thumbnail = video.get('splash') | |
48 | duration = float_or_none(try_get( | |
49 | video, lambda x: x['annotations'][0]['end_time'], compat_str)) | |
50 | ||
51 | return { | |
52 | 'id': video_id, | |
53 | 'title': title, | |
54 | 'thumbnail': thumbnail, | |
55 | 'duration': duration, | |
56 | 'formats': formats, | |
57 | } | |
58 | ||
59 | ||
60 | class CarambaTVPageIE(InfoExtractor): | |
61 | _VALID_URL = r'https?://carambatv\.ru/(?:[^/]+/)+(?P<id>[^/?#&]+)' | |
62 | _TEST = { | |
63 | 'url': 'http://carambatv.ru/movie/bad-comedian/razborka-v-manile/', | |
64 | 'md5': 'a49fb0ec2ad66503eeb46aac237d3c86', | |
65 | 'info_dict': { | |
66 | 'id': '475222', | |
67 | 'ext': 'flv', | |
68 | 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)', | |
69 | 'thumbnail': r're:^https?://.*\.jpg', | |
70 | # duration reported by videomore is incorrect | |
71 | 'duration': int, | |
72 | }, | |
73 | 'add_ie': [VideomoreIE.ie_key()], | |
74 | } | |
75 | ||
76 | def _real_extract(self, url): | |
77 | video_id = self._match_id(url) | |
78 | ||
79 | webpage = self._download_webpage(url, video_id) | |
80 | ||
81 | videomore_url = VideomoreIE._extract_url(webpage) | |
82 | if not videomore_url: | |
83 | videomore_id = self._search_regex( | |
84 | r'getVMCode\s*\(\s*["\']?(\d+)', webpage, 'videomore id', | |
85 | default=None) | |
86 | if videomore_id: | |
87 | videomore_url = 'videomore:%s' % videomore_id | |
88 | if videomore_url: | |
89 | title = self._og_search_title(webpage) | |
90 | return { | |
91 | '_type': 'url_transparent', | |
92 | 'url': videomore_url, | |
93 | 'ie_key': VideomoreIE.ie_key(), | |
94 | 'title': title, | |
95 | } | |
96 | ||
97 | video_url = self._og_search_property('video:iframe', webpage, default=None) | |
98 | ||
99 | if not video_url: | |
100 | video_id = self._search_regex( | |
101 | r'(?:video_id|crmb_vuid)\s*[:=]\s*["\']?(\d+)', | |
102 | webpage, 'video id') | |
103 | video_url = 'carambatv:%s' % video_id | |
104 | ||
105 | return self.url_result(video_url, CarambaTVIE.ie_key()) |