]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vesti.py
[youtube] Fix up invalid JSON
[yt-dlp.git] / youtube_dl / extractor / vesti.py
CommitLineData
1074982e
S
1# encoding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 ExtractorError,
9 int_or_none
10)
11
12
13class VestiIE(InfoExtractor):
14 IE_NAME = 'vesti'
15 IE_DESC = 'Вести.Ru'
b773ead7 16 _VALID_URL = r'http://(?:(?:.+?\.)?vesti\.ru|(?:2\.)?russia\.tv|tvkultura\.ru|rutv\.ru)/(?P<id>.+)'
1074982e
S
17
18 _TESTS = [
19 {
20 'url': 'http://www.vesti.ru/videos?vid=575582&cid=1',
21 'info_dict': {
22 'id': '765035',
23 'ext': 'mp4',
24 'title': 'Вести.net: биткоины в России не являются законными',
25 'description': 'md5:d4bb3859dc1177b28a94c5014c35a36b',
26 'duration': 302,
27 },
28 'params': {
29 # m3u8 download
30 'skip_download': True,
31 },
32 },
d37c07c5
S
33 {
34 'url': 'http://www.vesti.ru/doc.html?id=1349233',
35 'info_dict': {
36 'id': '773865',
37 'ext': 'mp4',
38 'title': 'Участники митинга штурмуют Донецкую областную администрацию',
39 'description': 'md5:1a160e98b3195379b4c849f2f4958009',
40 'duration': 210,
41 },
42 'params': {
43 # m3u8 download
44 'skip_download': True,
45 },
46 },
1074982e
S
47 {
48 'url': 'http://www.vesti.ru/only_video.html?vid=576180',
49 'info_dict': {
50 'id': '766048',
51 'ext': 'mp4',
52 'title': 'США заморозило, Британию затопило',
53 'description': 'md5:f0ed0695ec05aed27c56a70a58dc4cc1',
54 'duration': 87,
55 },
56 'params': {
57 # m3u8 download
58 'skip_download': True,
59 },
60 },
d37c07c5
S
61 {
62 'url': 'http://hitech.vesti.ru/news/view/id/4000',
63 'info_dict': {
64 'id': '766888',
65 'ext': 'mp4',
66 'title': 'Вести.net: интернет-гиганты начали перетягивание программных "одеял"',
67 'description': 'md5:65ddd47f9830c4f42ed6475f8730c995',
68 'duration': 279,
69 },
70 'params': {
71 # m3u8 download
72 'skip_download': True,
73 },
74 },
b773ead7
S
75 {
76 'url': 'http://sochi2014.vesti.ru/video/index/video_id/766403',
77 'info_dict': {
78 'id': '766403',
79 'ext': 'mp4',
80 'title': 'XXII зимние Олимпийские игры. Российские хоккеисты стартовали на Олимпиаде с победы',
81 'description': 'md5:55805dfd35763a890ff50fa9e35e31b3',
82 'duration': 271,
83 },
84 'params': {
85 # m3u8 download
86 'skip_download': True,
87 },
88 'skip': 'Blocked outside Russia'
89 },
90 {
91 'url': 'http://sochi2014.vesti.ru/live/play/live_id/301',
92 'info_dict': {
93 'id': '51499',
94 'ext': 'flv',
95 'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ',
96 'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c',
97 },
98 'params': {
99 # rtmp download
100 'skip_download': True,
101 },
102 'skip': 'Translation has finished'
103 },
d37c07c5
S
104 {
105 'url': 'http://russia.tv/video/show/brand_id/5169/episode_id/970443/video_id/975648',
106 'info_dict': {
107 'id': '771852',
108 'ext': 'mp4',
109 'title': 'Прямой эфир. Жертвы загадочной болезни: смерть от старости в 17 лет',
110 'description': 'md5:b81c8c55247a4bd996b43ce17395b2d8',
111 'duration': 3096,
112 },
113 'params': {
114 # m3u8 download
115 'skip_download': True,
116 },
117 },
118 {
119 'url': 'http://russia.tv/brand/show/brand_id/57638',
120 'info_dict': {
121 'id': '774016',
122 'ext': 'mp4',
123 'title': 'Чужой в семье Сталина',
124 'description': '',
125 'duration': 2539,
126 },
127 'params': {
128 # m3u8 download
129 'skip_download': True,
130 },
131 },
1074982e 132 {
b773ead7 133 'url': 'http://2.russia.tv/video/show/brand_id/48863/episode_id/972920/video_id/978667/viewtype/picture',
1074982e 134 'info_dict': {
b773ead7 135 'id': '775081',
1074982e 136 'ext': 'mp4',
b773ead7
S
137 'title': 'XXII зимние Олимпийские игры. Россияне заняли весь пьедестал в лыжных гонках',
138 'description': 'md5:15d3741dd8d04b203fbc031c6a47fb0f',
139 'duration': 101,
1074982e
S
140 },
141 'params': {
142 # m3u8 download
143 'skip_download': True,
144 },
145 },
146 {
b773ead7 147 'url': 'http://tvkultura.ru/video/show/brand_id/31724/episode_id/972347/video_id/978186',
1074982e 148 'info_dict': {
b773ead7
S
149 'id': '774471',
150 'ext': 'mp4',
151 'title': 'Монологи на все времена',
152 'description': 'md5:18d8b5e6a41fb1faa53819471852d5d5',
153 'duration': 2906,
1074982e
S
154 },
155 'params': {
b773ead7 156 # m3u8 download
1074982e
S
157 'skip_download': True,
158 },
b773ead7
S
159 },
160 {
161 'url': 'http://rutv.ru/brand/show/id/6792/channel/75',
162 'info_dict': {
163 'id': '125521',
164 'ext': 'mp4',
165 'title': 'Грустная дама червей. Х/ф',
166 'description': '',
167 'duration': 4882,
168 },
169 'params': {
170 # m3u8 download
171 'skip_download': True,
172 },
173 },
1074982e
S
174 ]
175
176 def _real_extract(self, url):
177 mobj = re.match(self._VALID_URL, url)
178 video_id = mobj.group('id')
179
180 page = self._download_webpage(url, video_id, 'Downloading page')
181
d37c07c5
S
182 mobj = re.search(
183 r'<meta property="og:video" content="http://www\.vesti\.ru/i/flvplayer_videoHost\.swf\?vid=(?P<id>\d+)',
184 page)
185 if mobj:
186 video_id = mobj.group('id')
187 page = self._download_webpage('http://www.vesti.ru/only_video.html?vid=%s' % video_id, video_id,
188 'Downloading video page')
189
190 mobj = re.search(
191 r'<meta property="og:video" content="http://player\.rutv\.ru/flash2v/container\.swf\?id=(?P<id>\d+)', page)
1074982e
S
192 if mobj:
193 video_type = 'video'
194 video_id = mobj.group('id')
195 else:
196 mobj = re.search(
d37c07c5
S
197 r'<iframe.+?src="http://player\.rutv\.ru/iframe/(?P<type>[^/]+)/id/(?P<id>\d+)[^"]*".*?></iframe>',
198 page)
1074982e
S
199
200 if not mobj:
d37c07c5 201 raise ExtractorError('No media found', expected=True)
1074982e
S
202
203 video_type = mobj.group('type')
204 video_id = mobj.group('id')
205
206 json_data = self._download_json(
207 'http://player.rutv.ru/iframe/%splay/id/%s' % ('live-' if video_type == 'live' else '', video_id),
208 video_id, 'Downloading JSON')
209
210 if json_data['errors']:
211 raise ExtractorError('vesti returned error: %s' % json_data['errors'], expected=True)
212
213 playlist = json_data['data']['playlist']
214 medialist = playlist['medialist']
215 media = medialist[0]
216
217 if media['errors']:
218 raise ExtractorError('vesti returned error: %s' % media['errors'], expected=True)
219
220 view_count = playlist.get('count_views')
221 priority_transport = playlist['priority_transport']
222
223 thumbnail = media['picture']
e477dcf6
S
224 width = int_or_none(media['width'])
225 height = int_or_none(media['height'])
1074982e
S
226 description = media['anons']
227 title = media['title']
228 duration = int_or_none(media.get('duration'))
229
230 formats = []
231
232 for transport, links in media['sources'].items():
233 for quality, url in links.items():
234 if transport == 'rtmp':
235 mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
236 if not mobj:
237 continue
238 fmt = {
239 'url': mobj.group('url'),
240 'play_path': mobj.group('playpath'),
241 'app': mobj.group('app'),
242 'page_url': 'http://player.rutv.ru',
243 'player_url': 'http://player.rutv.ru/flash2v/osmf.swf?i=22',
244 'rtmp_live': True,
245 'ext': 'flv',
246 'vbr': int(quality),
247 }
248 elif transport == 'm3u8':
249 fmt = {
250 'url': url,
251 'ext': 'mp4',
252 }
253 else:
254 fmt = {
255 'url': url
256 }
257 fmt.update({
258 'width': width,
259 'height': height,
260 'format_id': '%s-%s' % (transport, quality),
261 'preference': -1 if priority_transport == transport else -2,
262 })
263 formats.append(fmt)
264
265 if not formats:
266 raise ExtractorError('No media links available for %s' % video_id)
267
268 self._sort_formats(formats)
269
270 return {
271 'id': video_id,
272 'title': title,
273 'description': description,
274 'thumbnail': thumbnail,
275 'view_count': view_count,
276 'duration': duration,
277 'formats': formats,
278 }