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