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