]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vgtrk.py
[ted] Add 'http://' to the thumbnail url if it's missing
[yt-dlp.git] / youtube_dl / extractor / vgtrk.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
3ee52157
S
13class VGTRKIE(InfoExtractor):
14 IE_DESC = 'ВГТРК'
15 _VALID_URL = r'http://(?:.+?\.)?(?:vesti\.ru|russia2?\.tv|tvkultura\.ru|rutv\.ru)/(?P<id>.+)'
1074982e
S
16
17 _TESTS = [
18 {
19 'url': 'http://www.vesti.ru/videos?vid=575582&cid=1',
20 'info_dict': {
21 'id': '765035',
22 'ext': 'mp4',
23 'title': 'Вести.net: биткоины в России не являются законными',
24 'description': 'md5:d4bb3859dc1177b28a94c5014c35a36b',
25 'duration': 302,
26 },
27 'params': {
28 # m3u8 download
29 'skip_download': True,
30 },
31 },
d37c07c5
S
32 {
33 'url': 'http://www.vesti.ru/doc.html?id=1349233',
34 'info_dict': {
35 'id': '773865',
36 'ext': 'mp4',
37 'title': 'Участники митинга штурмуют Донецкую областную администрацию',
38 'description': 'md5:1a160e98b3195379b4c849f2f4958009',
39 'duration': 210,
40 },
41 'params': {
42 # m3u8 download
43 'skip_download': True,
44 },
45 },
1074982e
S
46 {
47 'url': 'http://www.vesti.ru/only_video.html?vid=576180',
48 'info_dict': {
49 'id': '766048',
50 'ext': 'mp4',
51 'title': 'США заморозило, Британию затопило',
52 'description': 'md5:f0ed0695ec05aed27c56a70a58dc4cc1',
53 'duration': 87,
54 },
55 'params': {
56 # m3u8 download
57 'skip_download': True,
58 },
59 },
d37c07c5
S
60 {
61 'url': 'http://hitech.vesti.ru/news/view/id/4000',
62 'info_dict': {
63 'id': '766888',
64 'ext': 'mp4',
65 'title': 'Вести.net: интернет-гиганты начали перетягивание программных "одеял"',
66 'description': 'md5:65ddd47f9830c4f42ed6475f8730c995',
67 'duration': 279,
68 },
69 'params': {
70 # m3u8 download
71 'skip_download': True,
72 },
73 },
b773ead7
S
74 {
75 'url': 'http://sochi2014.vesti.ru/video/index/video_id/766403',
76 'info_dict': {
77 'id': '766403',
78 'ext': 'mp4',
79 'title': 'XXII зимние Олимпийские игры. Российские хоккеисты стартовали на Олимпиаде с победы',
80 'description': 'md5:55805dfd35763a890ff50fa9e35e31b3',
81 'duration': 271,
82 },
83 'params': {
84 # m3u8 download
85 'skip_download': True,
86 },
aa51d20d 87 'skip': 'Blocked outside Russia',
b773ead7
S
88 },
89 {
90 'url': 'http://sochi2014.vesti.ru/live/play/live_id/301',
91 'info_dict': {
92 'id': '51499',
93 'ext': 'flv',
94 'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ',
95 'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c',
96 },
97 'params': {
98 # rtmp download
99 'skip_download': True,
100 },
101 'skip': 'Translation has finished'
102 },
d37c07c5
S
103 {
104 'url': 'http://russia.tv/video/show/brand_id/5169/episode_id/970443/video_id/975648',
105 'info_dict': {
106 'id': '771852',
107 'ext': 'mp4',
108 'title': 'Прямой эфир. Жертвы загадочной болезни: смерть от старости в 17 лет',
109 'description': 'md5:b81c8c55247a4bd996b43ce17395b2d8',
110 'duration': 3096,
111 },
112 'params': {
113 # m3u8 download
114 'skip_download': True,
115 },
116 },
117 {
118 'url': 'http://russia.tv/brand/show/brand_id/57638',
119 'info_dict': {
120 'id': '774016',
121 'ext': 'mp4',
122 'title': 'Чужой в семье Сталина',
123 'description': '',
124 'duration': 2539,
125 },
126 'params': {
127 # m3u8 download
128 'skip_download': True,
129 },
130 },
1074982e 131 {
b773ead7 132 'url': 'http://2.russia.tv/video/show/brand_id/48863/episode_id/972920/video_id/978667/viewtype/picture',
1074982e 133 'info_dict': {
b773ead7 134 'id': '775081',
1074982e 135 'ext': 'mp4',
b773ead7
S
136 'title': 'XXII зимние Олимпийские игры. Россияне заняли весь пьедестал в лыжных гонках',
137 'description': 'md5:15d3741dd8d04b203fbc031c6a47fb0f',
138 'duration': 101,
1074982e
S
139 },
140 'params': {
141 # m3u8 download
142 'skip_download': True,
143 },
aa51d20d 144 'skip': 'Blocked outside Russia',
1074982e
S
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 }