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