]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
1074982e S |
2 | from __future__ import unicode_literals |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | ExtractorError, | |
9 | int_or_none | |
10 | ) | |
11 | ||
12 | ||
a7515ec2 S |
13 | class RUTVIE(InfoExtractor): |
14 | IE_DESC = 'RUTV.RU' | |
342f630d | 15 | _VALID_URL = r'''(?x) |
624bd010 S |
16 | https?:// |
17 | (?:test)?player\.(?:rutv\.ru|vgtrk\.com)/ | |
18 | (?P<path> | |
19 | flash\d+v/container\.swf\?id=| | |
20 | iframe/(?P<type>swf|video|live)/id/| | |
21 | index/iframe/cast_id/ | |
22 | ) | |
23 | (?P<id>\d+) | |
24 | ''' | |
1074982e S |
25 | |
26 | _TESTS = [ | |
27 | { | |
a7515ec2 | 28 | 'url': 'http://player.rutv.ru/flash2v/container.swf?id=774471&sid=kultura&fbv=true&isPlay=true&ssl=false&i=560&acc_video_id=episode_id/972347/video_id/978186/brand_id/31724', |
1074982e | 29 | 'info_dict': { |
a7515ec2 | 30 | 'id': '774471', |
d37c07c5 | 31 | 'ext': 'mp4', |
a7515ec2 S |
32 | 'title': 'Монологи на все времена', |
33 | 'description': 'md5:18d8b5e6a41fb1faa53819471852d5d5', | |
34 | 'duration': 2906, | |
d37c07c5 S |
35 | }, |
36 | 'params': { | |
37 | # m3u8 download | |
38 | 'skip_download': True, | |
39 | }, | |
40 | }, | |
1074982e | 41 | { |
a7515ec2 | 42 | 'url': 'https://player.vgtrk.com/flash2v/container.swf?id=774016&sid=russiatv&fbv=true&isPlay=true&ssl=false&i=560&acc_video_id=episode_id/972098/video_id/977760/brand_id/57638', |
1074982e | 43 | 'info_dict': { |
a7515ec2 | 44 | 'id': '774016', |
1074982e | 45 | 'ext': 'mp4', |
a7515ec2 S |
46 | 'title': 'Чужой в семье Сталина', |
47 | 'description': '', | |
48 | 'duration': 2539, | |
1074982e S |
49 | }, |
50 | 'params': { | |
51 | # m3u8 download | |
52 | 'skip_download': True, | |
53 | }, | |
54 | }, | |
d37c07c5 | 55 | { |
a7515ec2 | 56 | 'url': 'http://player.rutv.ru/iframe/swf/id/766888/sid/hitech/?acc_video_id=4000', |
d37c07c5 S |
57 | 'info_dict': { |
58 | 'id': '766888', | |
59 | 'ext': 'mp4', | |
60 | 'title': 'Вести.net: интернет-гиганты начали перетягивание программных "одеял"', | |
61 | 'description': 'md5:65ddd47f9830c4f42ed6475f8730c995', | |
62 | 'duration': 279, | |
63 | }, | |
64 | 'params': { | |
65 | # m3u8 download | |
66 | 'skip_download': True, | |
67 | }, | |
68 | }, | |
b773ead7 | 69 | { |
a7515ec2 | 70 | 'url': 'http://player.rutv.ru/iframe/video/id/771852/start_zoom/true/showZoomBtn/false/sid/russiatv/?acc_video_id=episode_id/970443/video_id/975648/brand_id/5169', |
b773ead7 | 71 | 'info_dict': { |
a7515ec2 | 72 | 'id': '771852', |
b773ead7 | 73 | 'ext': 'mp4', |
a7515ec2 S |
74 | 'title': 'Прямой эфир. Жертвы загадочной болезни: смерть от старости в 17 лет', |
75 | 'description': 'md5:b81c8c55247a4bd996b43ce17395b2d8', | |
76 | 'duration': 3096, | |
b773ead7 S |
77 | }, |
78 | 'params': { | |
79 | # m3u8 download | |
80 | 'skip_download': True, | |
81 | }, | |
b773ead7 S |
82 | }, |
83 | { | |
a7515ec2 | 84 | 'url': 'http://player.rutv.ru/iframe/live/id/51499/showZoomBtn/false/isPlay/true/sid/sochi2014', |
b773ead7 S |
85 | 'info_dict': { |
86 | 'id': '51499', | |
87 | 'ext': 'flv', | |
88 | 'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ', | |
89 | 'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c', | |
90 | }, | |
d0fd3050 S |
91 | 'skip': 'Translation has finished', |
92 | }, | |
93 | { | |
dfad3aac | 94 | 'url': 'http://player.rutv.ru/iframe/live/id/21/showZoomBtn/false/isPlay/true/', |
d0fd3050 S |
95 | 'info_dict': { |
96 | 'id': '21', | |
97 | 'ext': 'mp4', | |
98 | 'title': 're:^Россия 24. Прямой эфир [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', | |
99 | 'is_live': True, | |
100 | }, | |
b773ead7 | 101 | 'params': { |
d0fd3050 | 102 | # m3u8 download |
b773ead7 S |
103 | 'skip_download': True, |
104 | }, | |
b773ead7 | 105 | }, |
624bd010 S |
106 | { |
107 | 'url': 'https://testplayer.vgtrk.com/iframe/live/id/19201/showZoomBtn/false/isPlay/true/', | |
108 | 'only_matching': True, | |
109 | }, | |
1074982e S |
110 | ] |
111 | ||
a7515ec2 S |
112 | @classmethod |
113 | def _extract_url(cls, webpage): | |
d37c07c5 | 114 | mobj = re.search( |
624bd010 | 115 | r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1', webpage) |
d37c07c5 | 116 | if mobj: |
a7515ec2 | 117 | return mobj.group('url') |
d37c07c5 S |
118 | |
119 | mobj = re.search( | |
624bd010 | 120 | r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/flash\d+v/container\.swf\?id=.+?\2)', |
a7515ec2 | 121 | webpage) |
1074982e | 122 | if mobj: |
a7515ec2 | 123 | return mobj.group('url') |
1074982e | 124 | |
a7515ec2 S |
125 | def _real_extract(self, url): |
126 | mobj = re.match(self._VALID_URL, url) | |
127 | video_id = mobj.group('id') | |
342f630d | 128 | video_path = mobj.group('path') |
1074982e | 129 | |
1600ed1f | 130 | if re.match(r'flash\d+v', video_path): |
a7515ec2 | 131 | video_type = 'video' |
342f630d S |
132 | elif video_path.startswith('iframe'): |
133 | video_type = mobj.group('type') | |
134 | if video_type == 'swf': | |
135 | video_type = 'video' | |
136 | elif video_path.startswith('index/iframe/cast_id'): | |
137 | video_type = 'live' | |
1074982e | 138 | |
e038d5c4 S |
139 | is_live = video_type == 'live' |
140 | ||
1074982e | 141 | json_data = self._download_json( |
6418b243 | 142 | 'http://player.rutv.ru/iframe/data%s/id/%s' % ('live' if is_live else 'video', video_id), |
1074982e S |
143 | video_id, 'Downloading JSON') |
144 | ||
145 | if json_data['errors']: | |
a7515ec2 | 146 | raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True) |
1074982e S |
147 | |
148 | playlist = json_data['data']['playlist'] | |
149 | medialist = playlist['medialist'] | |
150 | media = medialist[0] | |
151 | ||
152 | if media['errors']: | |
a7515ec2 | 153 | raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True) |
1074982e S |
154 | |
155 | view_count = playlist.get('count_views') | |
156 | priority_transport = playlist['priority_transport'] | |
157 | ||
158 | thumbnail = media['picture'] | |
e477dcf6 S |
159 | width = int_or_none(media['width']) |
160 | height = int_or_none(media['height']) | |
1074982e S |
161 | description = media['anons'] |
162 | title = media['title'] | |
163 | duration = int_or_none(media.get('duration')) | |
164 | ||
165 | formats = [] | |
166 | ||
167 | for transport, links in media['sources'].items(): | |
168 | for quality, url in links.items(): | |
e038d5c4 | 169 | preference = -1 if priority_transport == transport else -2 |
1074982e S |
170 | if transport == 'rtmp': |
171 | mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url) | |
172 | if not mobj: | |
173 | continue | |
174 | fmt = { | |
175 | 'url': mobj.group('url'), | |
176 | 'play_path': mobj.group('playpath'), | |
177 | 'app': mobj.group('app'), | |
178 | 'page_url': 'http://player.rutv.ru', | |
1600ed1f | 179 | 'player_url': 'http://player.rutv.ru/flash3v/osmf.swf?i=22', |
1074982e S |
180 | 'rtmp_live': True, |
181 | 'ext': 'flv', | |
182 | 'vbr': int(quality), | |
e038d5c4 | 183 | 'preference': preference, |
1074982e S |
184 | } |
185 | elif transport == 'm3u8': | |
e038d5c4 S |
186 | formats.extend(self._extract_m3u8_formats( |
187 | url, video_id, 'mp4', preference=preference, m3u8_id='hls')) | |
c6df6924 | 188 | continue |
1074982e S |
189 | else: |
190 | fmt = { | |
191 | 'url': url | |
192 | } | |
193 | fmt.update({ | |
194 | 'width': width, | |
195 | 'height': height, | |
196 | 'format_id': '%s-%s' % (transport, quality), | |
1074982e S |
197 | }) |
198 | formats.append(fmt) | |
199 | ||
1074982e S |
200 | self._sort_formats(formats) |
201 | ||
202 | return { | |
203 | 'id': video_id, | |
8dab1e90 | 204 | 'title': self._live_title(title) if is_live else title, |
1074982e S |
205 | 'description': description, |
206 | 'thumbnail': thumbnail, | |
207 | 'view_count': view_count, | |
208 | 'duration': duration, | |
209 | 'formats': formats, | |
8dab1e90 | 210 | 'is_live': is_live, |
5f6a1245 | 211 | } |