[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / rumble.py
blob74c7e4f176cea155bc5d2388a6e90fa2b8e61755
1 import itertools
2 import re
4 from .common import InfoExtractor
5 from ..networking.exceptions import HTTPError
6 from ..utils import (
7 ExtractorError,
8 UnsupportedError,
9 clean_html,
10 determine_ext,
11 extract_attributes,
12 format_field,
13 get_element_by_class,
14 get_elements_html_by_class,
15 int_or_none,
16 join_nonempty,
17 parse_count,
18 parse_iso8601,
19 traverse_obj,
20 unescapeHTML,
21 urljoin,
25 class RumbleEmbedIE(InfoExtractor):
26 _VALID_URL = r'https?://(?:www\.)?rumble\.com/embed/(?:[0-9a-z]+\.)?(?P<id>[0-9a-z]+)'
27 _EMBED_REGEX = [fr'(?:<(?:script|iframe)[^>]+\bsrc=|["\']embedUrl["\']\s*:\s*)["\'](?P<url>{_VALID_URL})']
28 _TESTS = [{
29 'url': 'https://rumble.com/embed/v5pv5f',
30 'md5': '36a18a049856720189f30977ccbb2c34',
31 'info_dict': {
32 'id': 'v5pv5f',
33 'ext': 'mp4',
34 'title': 'WMAR 2 News Latest Headlines | October 20, 6pm',
35 'timestamp': 1571611968,
36 'upload_date': '20191020',
37 'channel_url': 'https://rumble.com/c/WMAR',
38 'channel': 'WMAR',
39 'thumbnail': 'https://sp.rmbl.ws/s8/1/5/M/z/1/5Mz1a.qR4e-small-WMAR-2-News-Latest-Headline.jpg',
40 'duration': 234,
41 'uploader': 'WMAR',
42 'live_status': 'not_live',
44 }, {
45 'url': 'https://rumble.com/embed/vslb7v',
46 'md5': '7418035de1a30a178b8af34dc2b6a52b',
47 'info_dict': {
48 'id': 'vslb7v',
49 'ext': 'mp4',
50 'title': 'Defense Sec. says US Commitment to NATO Defense \'Ironclad\'',
51 'timestamp': 1645142135,
52 'upload_date': '20220217',
53 'channel_url': 'https://rumble.com/c/CyberTechNews',
54 'channel': 'CTNews',
55 'thumbnail': 'https://sp.rmbl.ws/s8/6/7/i/9/h/7i9hd.OvCc.jpg',
56 'duration': 901,
57 'uploader': 'CTNews',
58 'live_status': 'not_live',
60 }, {
61 'url': 'https://rumble.com/embed/vunh1h',
62 'info_dict': {
63 'id': 'vunh1h',
64 'ext': 'mp4',
65 'title': '‘Gideon, op zoek naar de waarheid’ including ENG SUBS',
66 'timestamp': 1647197663,
67 'upload_date': '20220313',
68 'channel_url': 'https://rumble.com/user/BLCKBX',
69 'channel': 'BLCKBX',
70 'thumbnail': r're:https://.+\.jpg',
71 'duration': 5069,
72 'uploader': 'BLCKBX',
73 'live_status': 'not_live',
74 'subtitles': {
75 'en': [
77 'url': r're:https://.+\.vtt',
78 'name': 'English',
79 'ext': 'vtt',
84 'params': {'skip_download': True},
85 }, {
86 'url': 'https://rumble.com/embed/v1essrt',
87 'info_dict': {
88 'id': 'v1essrt',
89 'ext': 'mp4',
90 'title': 'startswith:lofi hip hop radio 📚 - beats to relax/study to',
91 'timestamp': 1661519399,
92 'upload_date': '20220826',
93 'channel_url': 'https://rumble.com/c/LofiGirl',
94 'channel': 'Lofi Girl',
95 'thumbnail': r're:https://.+\.jpg',
96 'uploader': 'Lofi Girl',
97 'live_status': 'is_live',
99 'params': {'skip_download': True},
100 }, {
101 'url': 'https://rumble.com/embed/v1amumr',
102 'info_dict': {
103 'id': 'v1amumr',
104 'ext': 'mp4',
105 'fps': 60,
106 'title': 'Turning Point USA 2022 Student Action Summit DAY 1 - Rumble Exclusive Live',
107 'timestamp': 1658518457,
108 'upload_date': '20220722',
109 'channel_url': 'https://rumble.com/c/RumbleEvents',
110 'channel': 'Rumble Events',
111 'thumbnail': r're:https://.+\.jpg',
112 'duration': 16427,
113 'uploader': 'Rumble Events',
114 'live_status': 'was_live',
116 'params': {'skip_download': True},
117 }, {
118 'url': 'https://rumble.com/embed/ufe9n.v5pv5f',
119 'only_matching': True,
122 _WEBPAGE_TESTS = [
124 'note': 'Rumble JS embed',
125 'url': 'https://therightscoop.com/what-does-9-plus-1-plus-1-equal-listen-to-this-audio-of-attempted-kavanaugh-assassins-call-and-youll-get-it',
126 'md5': '4701209ac99095592e73dbba21889690',
127 'info_dict': {
128 'id': 'v15eqxl',
129 'ext': 'mp4',
130 'channel': 'Mr Producer Media',
131 'duration': 92,
132 'title': '911 Audio From The Man Who Wanted To Kill Supreme Court Justice Kavanaugh',
133 'channel_url': 'https://rumble.com/c/RichSementa',
134 'thumbnail': 'https://sp.rmbl.ws/s8/1/P/j/f/A/PjfAe.qR4e-small-911-Audio-From-The-Man-Who-.jpg',
135 'timestamp': 1654892716,
136 'uploader': 'Mr Producer Media',
137 'upload_date': '20220610',
138 'live_status': 'not_live',
143 @classmethod
144 def _extract_embed_urls(cls, url, webpage):
145 embeds = tuple(super()._extract_embed_urls(url, webpage))
146 if embeds:
147 return embeds
148 return [f'https://rumble.com/embed/{mobj.group("id")}' for mobj in re.finditer(
149 r'<script>[^<]*\bRumble\(\s*"play"\s*,\s*{[^}]*[\'"]?video[\'"]?\s*:\s*[\'"](?P<id>[0-9a-z]+)[\'"]', webpage)]
151 def _real_extract(self, url):
152 video_id = self._match_id(url)
153 video = self._download_json(
154 'https://rumble.com/embedJS/u3/', video_id,
155 query={'request': 'video', 'ver': 2, 'v': video_id})
157 sys_msg = traverse_obj(video, ('sys', 'msg'))
158 if sys_msg:
159 self.report_warning(sys_msg, video_id=video_id)
161 if video.get('live') == 0:
162 live_status = 'not_live' if video.get('livestream_has_dvr') is None else 'was_live'
163 elif video.get('live') == 1:
164 live_status = 'is_upcoming' if video.get('livestream_has_dvr') else 'was_live'
165 elif video.get('live') == 2:
166 live_status = 'is_live'
167 else:
168 live_status = None
170 formats = []
171 for ext, ext_info in (video.get('ua') or {}).items():
172 if isinstance(ext_info, dict):
173 for height, video_info in ext_info.items():
174 if not traverse_obj(video_info, ('meta', 'h', {int_or_none})):
175 video_info.setdefault('meta', {})['h'] = height
176 ext_info = ext_info.values()
178 for video_info in ext_info:
179 meta = video_info.get('meta') or {}
180 if not video_info.get('url'):
181 continue
182 if ext == 'hls':
183 if meta.get('live') is True and video.get('live') == 1:
184 live_status = 'post_live'
185 formats.extend(self._extract_m3u8_formats(
186 video_info['url'], video_id,
187 ext='mp4', m3u8_id='hls', fatal=False, live=live_status == 'is_live'))
188 continue
189 timeline = ext == 'timeline'
190 if timeline:
191 ext = determine_ext(video_info['url'])
192 formats.append({
193 'ext': ext,
194 'acodec': 'none' if timeline else None,
195 'url': video_info['url'],
196 'format_id': join_nonempty(ext, format_field(meta, 'h', '%sp')),
197 'format_note': 'Timeline' if timeline else None,
198 'fps': None if timeline else video.get('fps'),
199 **traverse_obj(meta, {
200 'tbr': 'bitrate',
201 'filesize': 'size',
202 'width': 'w',
203 'height': 'h',
204 }, expected_type=lambda x: int(x) or None),
207 subtitles = {
208 lang: [{
209 'url': sub_info['path'],
210 'name': sub_info.get('language') or '',
211 }] for lang, sub_info in (video.get('cc') or {}).items() if sub_info.get('path')
214 author = video.get('author') or {}
215 thumbnails = traverse_obj(video, ('t', ..., {'url': 'i', 'width': 'w', 'height': 'h'}))
216 if not thumbnails and video.get('i'):
217 thumbnails = [{'url': video['i']}]
219 if live_status in {'is_live', 'post_live'}:
220 duration = None
221 else:
222 duration = int_or_none(video.get('duration'))
224 return {
225 'id': video_id,
226 'title': unescapeHTML(video.get('title')),
227 'formats': formats,
228 'subtitles': subtitles,
229 'thumbnails': thumbnails,
230 'timestamp': parse_iso8601(video.get('pubDate')),
231 'channel': author.get('name'),
232 'channel_url': author.get('url'),
233 'duration': duration,
234 'uploader': author.get('name'),
235 'live_status': live_status,
239 class RumbleIE(InfoExtractor):
240 _VALID_URL = r'https?://(?:www\.)?rumble\.com/(?P<id>v(?!ideos)[\w.-]+)[^/]*$'
241 _EMBED_REGEX = [
242 r'<a class=video-item--a href=(?P<url>/v[\w.-]+\.html)>',
243 r'<a[^>]+class="videostream__link link"[^>]+href=(?P<url>/v[\w.-]+\.html)[^>]*>']
244 _TESTS = [{
245 'add_ie': ['RumbleEmbed'],
246 'url': 'https://rumble.com/vdmum1-moose-the-dog-helps-girls-dig-a-snow-fort.html',
247 'md5': '53af34098a7f92c4e51cf0bd1c33f009',
248 'info_dict': {
249 'id': 'vb0ofn',
250 'ext': 'mp4',
251 'timestamp': 1612662578,
252 'uploader': 'LovingMontana',
253 'channel': 'LovingMontana',
254 'upload_date': '20210207',
255 'title': 'Winter-loving dog helps girls dig a snow fort ',
256 'description': 'Moose the dog is more than happy to help with digging out this epic snow fort. Great job, Moose!',
257 'channel_url': 'https://rumble.com/c/c-546523',
258 'thumbnail': r're:https://.+\.jpg',
259 'duration': 103,
260 'like_count': int,
261 'dislike_count': int,
262 'view_count': int,
263 'live_status': 'not_live',
265 }, {
266 'url': 'http://www.rumble.com/vDMUM1?key=value',
267 'only_matching': True,
268 }, {
269 'note': 'timeline format',
270 'url': 'https://rumble.com/v2ea9qb-the-u.s.-cannot-hide-this-in-ukraine-anymore-redacted-with-natali-and-clayt.html',
271 'md5': '40d61fec6c0945bca3d0e1dc1aa53d79',
272 'params': {'format': 'wv'},
273 'info_dict': {
274 'id': 'v2bou5f',
275 'ext': 'mp4',
276 'uploader': 'Redacted News',
277 'upload_date': '20230322',
278 'timestamp': 1679445010,
279 'title': 'The U.S. CANNOT hide this in Ukraine anymore | Redacted with Natali and Clayton Morris',
280 'duration': 892,
281 'channel': 'Redacted News',
282 'description': 'md5:aaad0c5c3426d7a361c29bdaaced7c42',
283 'channel_url': 'https://rumble.com/c/Redacted',
284 'live_status': 'not_live',
285 'thumbnail': 'https://sp.rmbl.ws/s8/1/d/x/2/O/dx2Oi.qR4e-small-The-U.S.-CANNOT-hide-this-i.jpg',
286 'like_count': int,
287 'dislike_count': int,
288 'view_count': int,
290 }, {
291 'url': 'https://rumble.com/v2e7fju-the-covid-twitter-files-drop-protecting-fauci-while-censoring-the-truth-wma.html',
292 'info_dict': {
293 'id': 'v2blzyy',
294 'ext': 'mp4',
295 'live_status': 'was_live',
296 'release_timestamp': 1679446804,
297 'description': 'md5:2ac4908ccfecfb921f8ffa4b30c1e636',
298 'release_date': '20230322',
299 'timestamp': 1679445692,
300 'duration': 4435,
301 'upload_date': '20230322',
302 'title': 'The Covid Twitter Files Drop: Protecting Fauci While Censoring The Truth w/Matt Taibbi',
303 'uploader': 'Kim Iversen',
304 'channel_url': 'https://rumble.com/c/KimIversen',
305 'channel': 'Kim Iversen',
306 'thumbnail': 'https://sp.rmbl.ws/s8/1/6/b/w/O/6bwOi.qR4e-small-The-Covid-Twitter-Files-Dro.jpg',
307 'like_count': int,
308 'dislike_count': int,
309 'view_count': int,
313 _WEBPAGE_TESTS = [{
314 'url': 'https://rumble.com/videos?page=2',
315 'playlist_mincount': 24,
316 'info_dict': {
317 'id': 'videos?page=2',
318 'title': 'All videos',
319 'description': 'Browse videos uploaded to Rumble.com',
320 'age_limit': 0,
322 }, {
323 'url': 'https://rumble.com/browse/live',
324 'playlist_mincount': 25,
325 'info_dict': {
326 'id': 'live',
327 'title': 'Browse',
328 'age_limit': 0,
330 }, {
331 'url': 'https://rumble.com/search/video?q=rumble&sort=views',
332 'playlist_mincount': 24,
333 'info_dict': {
334 'id': 'video?q=rumble&sort=views',
335 'title': 'Search results for: rumble',
336 'age_limit': 0,
340 def _real_extract(self, url):
341 page_id = self._match_id(url)
342 webpage = self._download_webpage(url, page_id)
343 url_info = next(RumbleEmbedIE.extract_from_webpage(self._downloader, url, webpage), None)
344 if not url_info:
345 raise UnsupportedError(url)
347 return {
348 '_type': 'url_transparent',
349 'ie_key': url_info['ie_key'],
350 'url': url_info['url'],
351 'release_timestamp': parse_iso8601(self._search_regex(
352 r'(?:Livestream begins|Streamed on):\s+<time datetime="([^"]+)', webpage, 'release date', default=None)),
353 'view_count': int_or_none(self._search_regex(
354 r'"userInteractionCount"\s*:\s*(\d+)', webpage, 'view count', default=None)),
355 'like_count': parse_count(self._search_regex(
356 r'<span data-js="rumbles_up_votes">\s*([\d,.KM]+)', webpage, 'like count', default=None)),
357 'dislike_count': parse_count(self._search_regex(
358 r'<span data-js="rumbles_down_votes">\s*([\d,.KM]+)', webpage, 'dislike count', default=None)),
359 'description': clean_html(get_element_by_class('media-description', webpage)),
363 class RumbleChannelIE(InfoExtractor):
364 _VALID_URL = r'(?P<url>https?://(?:www\.)?rumble\.com/(?:c|user)/(?P<id>[^&?#$/]+))'
366 _TESTS = [{
367 'url': 'https://rumble.com/c/Styxhexenhammer666',
368 'playlist_mincount': 1160,
369 'info_dict': {
370 'id': 'Styxhexenhammer666',
372 }, {
373 'url': 'https://rumble.com/user/goldenpoodleharleyeuna',
374 'playlist_mincount': 4,
375 'info_dict': {
376 'id': 'goldenpoodleharleyeuna',
380 def entries(self, url, playlist_id):
381 for page in itertools.count(1):
382 try:
383 webpage = self._download_webpage(f'{url}?page={page}', playlist_id, note=f'Downloading page {page}')
384 except ExtractorError as e:
385 if isinstance(e.cause, HTTPError) and e.cause.status == 404:
386 break
387 raise
388 for video_url in traverse_obj(
389 get_elements_html_by_class('videostream__link', webpage), (..., {extract_attributes}, 'href'),
391 yield self.url_result(urljoin('https://rumble.com', video_url))
393 def _real_extract(self, url):
394 url, playlist_id = self._match_valid_url(url).groups()
395 return self.playlist_result(self.entries(url, playlist_id), playlist_id=playlist_id)