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