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