]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/rutv.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / rutv.py
CommitLineData
1074982e
S
1import re
2
3from .common import InfoExtractor
e897bd82 4from ..utils import ExtractorError, int_or_none, str_to_int
1074982e
S
5
6
a7515ec2
S
7class RUTVIE(InfoExtractor):
8 IE_DESC = 'RUTV.RU'
342f630d 9 _VALID_URL = r'''(?x)
624bd010
S
10 https?://
11 (?:test)?player\.(?:rutv\.ru|vgtrk\.com)/
12 (?P<path>
13 flash\d+v/container\.swf\?id=|
14 iframe/(?P<type>swf|video|live)/id/|
15 index/iframe/cast_id/
16 )
17 (?P<id>\d+)
18 '''
bfd973ec 19 _EMBED_URLS = [
20 r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1',
21 r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/flash\d+v/container\.swf\?id=.+?\2)',
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 110 def _real_extract(self, url):
5ad28e7f 111 mobj = self._match_valid_url(url)
a7515ec2 112 video_id = mobj.group('id')
342f630d 113 video_path = mobj.group('path')
1074982e 114
1600ed1f 115 if re.match(r'flash\d+v', video_path):
a7515ec2 116 video_type = 'video'
342f630d
S
117 elif video_path.startswith('iframe'):
118 video_type = mobj.group('type')
119 if video_type == 'swf':
120 video_type = 'video'
121 elif video_path.startswith('index/iframe/cast_id'):
122 video_type = 'live'
1074982e 123
e038d5c4
S
124 is_live = video_type == 'live'
125
1074982e 126 json_data = self._download_json(
5c23e3af 127 'http://player.vgtrk.com/iframe/data%s/id/%s' % ('live' if is_live else 'video', video_id),
1074982e
S
128 video_id, 'Downloading JSON')
129
130 if json_data['errors']:
a7515ec2 131 raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
1074982e
S
132
133 playlist = json_data['data']['playlist']
134 medialist = playlist['medialist']
135 media = medialist[0]
136
137 if media['errors']:
a7515ec2 138 raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
1074982e 139
5c8b2ee9 140 view_count = int_or_none(playlist.get('count_views'))
1074982e
S
141 priority_transport = playlist['priority_transport']
142
143 thumbnail = media['picture']
e477dcf6
S
144 width = int_or_none(media['width'])
145 height = int_or_none(media['height'])
1074982e
S
146 description = media['anons']
147 title = media['title']
148 duration = int_or_none(media.get('duration'))
149
150 formats = []
5c8b2ee9 151 subtitles = {}
1074982e
S
152
153 for transport, links in media['sources'].items():
154 for quality, url in links.items():
e038d5c4 155 preference = -1 if priority_transport == transport else -2
1074982e
S
156 if transport == 'rtmp':
157 mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
158 if not mobj:
159 continue
160 fmt = {
161 'url': mobj.group('url'),
162 'play_path': mobj.group('playpath'),
163 'app': mobj.group('app'),
164 'page_url': 'http://player.rutv.ru',
1600ed1f 165 'player_url': 'http://player.rutv.ru/flash3v/osmf.swf?i=22',
1074982e
S
166 'rtmp_live': True,
167 'ext': 'flv',
50e93e03 168 'vbr': str_to_int(quality),
1074982e
S
169 }
170 elif transport == 'm3u8':
5c8b2ee9
L
171 fmt, subs = self._extract_m3u8_formats_and_subtitles(
172 url, video_id, 'mp4', quality=preference, m3u8_id='hls')
173 formats.extend(fmt)
174 self._merge_subtitles(subs, target=subtitles)
c6df6924 175 continue
1074982e
S
176 else:
177 fmt = {
178 'url': url
179 }
180 fmt.update({
3f168f0e
LNO
181 'width': int_or_none(quality, default=height, invscale=width, scale=height),
182 'height': int_or_none(quality, default=height),
1074982e 183 'format_id': '%s-%s' % (transport, quality),
3f168f0e 184 'source_preference': preference,
1074982e
S
185 })
186 formats.append(fmt)
187
1074982e
S
188 return {
189 'id': video_id,
39ca3b5c 190 'title': title,
1074982e
S
191 'description': description,
192 'thumbnail': thumbnail,
193 'view_count': view_count,
194 'duration': duration,
195 'formats': formats,
5c8b2ee9 196 'subtitles': subtitles,
8dab1e90 197 'is_live': is_live,
9f14daf2 198 '_format_sort_fields': ('source', ),
5f6a1245 199 }