]>
Commit | Line | Data |
---|---|---|
eb451890 S |
1 | from .common import InfoExtractor |
2 | from ..compat import compat_str | |
3 | from ..utils import ( | |
e0ddbd02 | 4 | format_field, |
eb451890 S |
5 | float_or_none, |
6 | int_or_none, | |
7 | try_get, | |
8 | ) | |
9 | ||
62a0b86e YCH |
10 | from .videomore import VideomoreIE |
11 | ||
eb451890 S |
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] - Разборка в Маниле (Абсолютный обзор)', | |
ec85ded8 | 22 | 'thumbnail': r're:^https?://.*\.jpg', |
eb451890 S |
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')), | |
e0ddbd02 | 44 | 'format_id': format_field(f, 'height', '%sp'), |
eb451890 S |
45 | } for f in video['qualities'] if f.get('fn')] |
46 | self._sort_formats(formats) | |
47 | ||
48 | thumbnail = video.get('splash') | |
49 | duration = float_or_none(try_get( | |
50 | video, lambda x: x['annotations'][0]['end_time'], compat_str)) | |
51 | ||
52 | return { | |
53 | 'id': video_id, | |
54 | 'title': title, | |
55 | 'thumbnail': thumbnail, | |
56 | 'duration': duration, | |
57 | 'formats': formats, | |
58 | } | |
59 | ||
60 | ||
61 | class CarambaTVPageIE(InfoExtractor): | |
62 | _VALID_URL = r'https?://carambatv\.ru/(?:[^/]+/)+(?P<id>[^/?#&]+)' | |
63 | _TEST = { | |
64 | 'url': 'http://carambatv.ru/movie/bad-comedian/razborka-v-manile/', | |
62a0b86e | 65 | 'md5': 'a49fb0ec2ad66503eeb46aac237d3c86', |
eb451890 | 66 | 'info_dict': { |
62a0b86e YCH |
67 | 'id': '475222', |
68 | 'ext': 'flv', | |
eb451890 | 69 | 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)', |
ec85ded8 | 70 | 'thumbnail': r're:^https?://.*\.jpg', |
62a0b86e YCH |
71 | # duration reported by videomore is incorrect |
72 | 'duration': int, | |
eb451890 | 73 | }, |
62a0b86e | 74 | 'add_ie': [VideomoreIE.ie_key()], |
eb451890 S |
75 | } |
76 | ||
77 | def _real_extract(self, url): | |
78 | video_id = self._match_id(url) | |
79 | ||
80 | webpage = self._download_webpage(url, video_id) | |
81 | ||
62a0b86e | 82 | videomore_url = VideomoreIE._extract_url(webpage) |
c87f65e4 S |
83 | if not videomore_url: |
84 | videomore_id = self._search_regex( | |
85 | r'getVMCode\s*\(\s*["\']?(\d+)', webpage, 'videomore id', | |
86 | default=None) | |
87 | if videomore_id: | |
88 | videomore_url = 'videomore:%s' % videomore_id | |
62a0b86e YCH |
89 | if videomore_url: |
90 | title = self._og_search_title(webpage) | |
91 | return { | |
92 | '_type': 'url_transparent', | |
93 | 'url': videomore_url, | |
94 | 'ie_key': VideomoreIE.ie_key(), | |
95 | 'title': title, | |
96 | } | |
97 | ||
eb451890 S |
98 | video_url = self._og_search_property('video:iframe', webpage, default=None) |
99 | ||
100 | if not video_url: | |
101 | video_id = self._search_regex( | |
102 | r'(?:video_id|crmb_vuid)\s*[:=]\s*["\']?(\d+)', | |
103 | webpage, 'video id') | |
104 | video_url = 'carambatv:%s' % video_id | |
105 | ||
106 | return self.url_result(video_url, CarambaTVIE.ie_key()) |