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