logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

rumble.py (15724B)


  1. import itertools
  2. import re
  3. from .common import InfoExtractor
  4. from ..networking.exceptions import HTTPError
  5. from ..utils import (
  6. ExtractorError,
  7. UnsupportedError,
  8. clean_html,
  9. determine_ext,
  10. extract_attributes,
  11. format_field,
  12. get_element_by_class,
  13. get_elements_html_by_class,
  14. int_or_none,
  15. join_nonempty,
  16. parse_count,
  17. parse_iso8601,
  18. traverse_obj,
  19. unescapeHTML,
  20. urljoin,
  21. )
  22. class RumbleEmbedIE(InfoExtractor):
  23. _VALID_URL = r'https?://(?:www\.)?rumble\.com/embed/(?:[0-9a-z]+\.)?(?P<id>[0-9a-z]+)'
  24. _EMBED_REGEX = [fr'(?:<(?:script|iframe)[^>]+\bsrc=|["\']embedUrl["\']\s*:\s*)["\'](?P<url>{_VALID_URL})']
  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',
  34. 'channel_url': 'https://rumble.com/c/WMAR',
  35. 'channel': 'WMAR',
  36. 'thumbnail': 'https://sp.rmbl.ws/s8/1/5/M/z/1/5Mz1a.qR4e-small-WMAR-2-News-Latest-Headline.jpg',
  37. 'duration': 234,
  38. 'uploader': 'WMAR',
  39. 'live_status': 'not_live',
  40. },
  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,
  54. 'uploader': 'CTNews',
  55. 'live_status': 'not_live',
  56. },
  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 to',
  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. 'uploader': 'Lofi Girl',
  94. 'live_status': 'is_live',
  95. },
  96. 'params': {'skip_download': True},
  97. }, {
  98. 'url': 'https://rumble.com/embed/v1amumr',
  99. 'info_dict': {
  100. 'id': 'v1amumr',
  101. 'ext': 'mp4',
  102. 'fps': 60,
  103. 'title': 'Turning Point USA 2022 Student Action Summit DAY 1 - Rumble Exclusive Live',
  104. 'timestamp': 1658518457,
  105. 'upload_date': '20220722',
  106. 'channel_url': 'https://rumble.com/c/RumbleEvents',
  107. 'channel': 'Rumble Events',
  108. 'thumbnail': r're:https://.+\.jpg',
  109. 'duration': 16427,
  110. 'uploader': 'Rumble Events',
  111. 'live_status': 'was_live',
  112. },
  113. 'params': {'skip_download': True},
  114. }, {
  115. 'url': 'https://rumble.com/embed/ufe9n.v5pv5f',
  116. 'only_matching': True,
  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.qR4e-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. @classmethod
  139. def _extract_embed_urls(cls, url, webpage):
  140. embeds = tuple(super()._extract_embed_urls(url, webpage))
  141. if embeds:
  142. return embeds
  143. return [f'https://rumble.com/embed/{mobj.group("id")}' for mobj in re.finditer(
  144. r'<script>[^<]*\bRumble\(\s*"play"\s*,\s*{[^}]*[\'"]?video[\'"]?\s*:\s*[\'"](?P<id>[0-9a-z]+)[\'"]', webpage)]
  145. def _real_extract(self, url):
  146. video_id = self._match_id(url)
  147. video = self._download_json(
  148. 'https://rumble.com/embedJS/u3/', video_id,
  149. query={'request': 'video', 'ver': 2, 'v': video_id})
  150. sys_msg = traverse_obj(video, ('sys', 'msg'))
  151. if sys_msg:
  152. self.report_warning(sys_msg, video_id=video_id)
  153. if video.get('live') == 0:
  154. live_status = 'not_live' if video.get('livestream_has_dvr') is None else 'was_live'
  155. elif video.get('live') == 1:
  156. live_status = 'is_upcoming' if video.get('livestream_has_dvr') else 'was_live'
  157. elif video.get('live') == 2:
  158. live_status = 'is_live'
  159. else:
  160. live_status = None
  161. formats = []
  162. for ext, ext_info in (video.get('ua') or {}).items():
  163. if isinstance(ext_info, dict):
  164. for height, video_info in ext_info.items():
  165. if not traverse_obj(video_info, ('meta', 'h', {int_or_none})):
  166. video_info.setdefault('meta', {})['h'] = height
  167. ext_info = ext_info.values()
  168. for video_info in ext_info:
  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': join_nonempty(ext, format_field(meta, 'h', '%sp')),
  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. subtitles = {
  197. lang: [{
  198. 'url': sub_info['path'],
  199. 'name': sub_info.get('language') or '',
  200. }] for lang, sub_info in (video.get('cc') or {}).items() if sub_info.get('path')
  201. }
  202. author = video.get('author') or {}
  203. thumbnails = traverse_obj(video, ('t', ..., {'url': 'i', 'width': 'w', 'height': 'h'}))
  204. if not thumbnails and video.get('i'):
  205. thumbnails = [{'url': video['i']}]
  206. if live_status in {'is_live', 'post_live'}:
  207. duration = None
  208. else:
  209. duration = int_or_none(video.get('duration'))
  210. return {
  211. 'id': video_id,
  212. 'title': unescapeHTML(video.get('title')),
  213. 'formats': formats,
  214. 'subtitles': subtitles,
  215. 'thumbnails': thumbnails,
  216. 'timestamp': parse_iso8601(video.get('pubDate')),
  217. 'channel': author.get('name'),
  218. 'channel_url': author.get('url'),
  219. 'duration': duration,
  220. 'uploader': author.get('name'),
  221. 'live_status': live_status,
  222. }
  223. class RumbleIE(InfoExtractor):
  224. _VALID_URL = r'https?://(?:www\.)?rumble\.com/(?P<id>v(?!ideos)[\w.-]+)[^/]*$'
  225. _EMBED_REGEX = [
  226. r'<a class=video-item--a href=(?P<url>/v[\w.-]+\.html)>',
  227. r'<a[^>]+class="videostream__link link"[^>]+href=(?P<url>/v[\w.-]+\.html)[^>]*>']
  228. _TESTS = [{
  229. 'add_ie': ['RumbleEmbed'],
  230. 'url': 'https://rumble.com/vdmum1-moose-the-dog-helps-girls-dig-a-snow-fort.html',
  231. 'md5': '53af34098a7f92c4e51cf0bd1c33f009',
  232. 'info_dict': {
  233. 'id': 'vb0ofn',
  234. 'ext': 'mp4',
  235. 'timestamp': 1612662578,
  236. 'uploader': 'LovingMontana',
  237. 'channel': 'LovingMontana',
  238. 'upload_date': '20210207',
  239. 'title': 'Winter-loving dog helps girls dig a snow fort ',
  240. 'description': 'Moose the dog is more than happy to help with digging out this epic snow fort. Great job, Moose!',
  241. 'channel_url': 'https://rumble.com/c/c-546523',
  242. 'thumbnail': r're:https://.+\.jpg',
  243. 'duration': 103,
  244. 'like_count': int,
  245. 'dislike_count': int,
  246. 'view_count': int,
  247. 'live_status': 'not_live',
  248. },
  249. }, {
  250. 'url': 'http://www.rumble.com/vDMUM1?key=value',
  251. 'only_matching': True,
  252. }, {
  253. 'note': 'timeline format',
  254. 'url': 'https://rumble.com/v2ea9qb-the-u.s.-cannot-hide-this-in-ukraine-anymore-redacted-with-natali-and-clayt.html',
  255. 'md5': '40d61fec6c0945bca3d0e1dc1aa53d79',
  256. 'params': {'format': 'wv'},
  257. 'info_dict': {
  258. 'id': 'v2bou5f',
  259. 'ext': 'mp4',
  260. 'uploader': 'Redacted News',
  261. 'upload_date': '20230322',
  262. 'timestamp': 1679445010,
  263. 'title': 'The U.S. CANNOT hide this in Ukraine anymore | Redacted with Natali and Clayton Morris',
  264. 'duration': 892,
  265. 'channel': 'Redacted News',
  266. 'description': 'md5:aaad0c5c3426d7a361c29bdaaced7c42',
  267. 'channel_url': 'https://rumble.com/c/Redacted',
  268. 'live_status': 'not_live',
  269. 'thumbnail': 'https://sp.rmbl.ws/s8/1/d/x/2/O/dx2Oi.qR4e-small-The-U.S.-CANNOT-hide-this-i.jpg',
  270. 'like_count': int,
  271. 'dislike_count': int,
  272. 'view_count': int,
  273. },
  274. }, {
  275. 'url': 'https://rumble.com/v2e7fju-the-covid-twitter-files-drop-protecting-fauci-while-censoring-the-truth-wma.html',
  276. 'info_dict': {
  277. 'id': 'v2blzyy',
  278. 'ext': 'mp4',
  279. 'live_status': 'was_live',
  280. 'release_timestamp': 1679446804,
  281. 'description': 'md5:2ac4908ccfecfb921f8ffa4b30c1e636',
  282. 'release_date': '20230322',
  283. 'timestamp': 1679445692,
  284. 'duration': 4435,
  285. 'upload_date': '20230322',
  286. 'title': 'The Covid Twitter Files Drop: Protecting Fauci While Censoring The Truth w/Matt Taibbi',
  287. 'uploader': 'Kim Iversen',
  288. 'channel_url': 'https://rumble.com/c/KimIversen',
  289. 'channel': 'Kim Iversen',
  290. 'thumbnail': 'https://sp.rmbl.ws/s8/1/6/b/w/O/6bwOi.qR4e-small-The-Covid-Twitter-Files-Dro.jpg',
  291. 'like_count': int,
  292. 'dislike_count': int,
  293. 'view_count': int,
  294. },
  295. }]
  296. _WEBPAGE_TESTS = [{
  297. 'url': 'https://rumble.com/videos?page=2',
  298. 'playlist_mincount': 24,
  299. 'info_dict': {
  300. 'id': 'videos?page=2',
  301. 'title': 'All videos',
  302. 'description': 'Browse videos uploaded to Rumble.com',
  303. 'age_limit': 0,
  304. },
  305. }, {
  306. 'url': 'https://rumble.com/browse/live',
  307. 'playlist_mincount': 25,
  308. 'info_dict': {
  309. 'id': 'live',
  310. 'title': 'Browse',
  311. 'age_limit': 0,
  312. },
  313. }, {
  314. 'url': 'https://rumble.com/search/video?q=rumble&sort=views',
  315. 'playlist_mincount': 24,
  316. 'info_dict': {
  317. 'id': 'video?q=rumble&sort=views',
  318. 'title': 'Search results for: rumble',
  319. 'age_limit': 0,
  320. },
  321. }]
  322. def _real_extract(self, url):
  323. page_id = self._match_id(url)
  324. webpage = self._download_webpage(url, page_id)
  325. url_info = next(RumbleEmbedIE.extract_from_webpage(self._downloader, url, webpage), None)
  326. if not url_info:
  327. raise UnsupportedError(url)
  328. return {
  329. '_type': 'url_transparent',
  330. 'ie_key': url_info['ie_key'],
  331. 'url': url_info['url'],
  332. 'release_timestamp': parse_iso8601(self._search_regex(
  333. r'(?:Livestream begins|Streamed on):\s+<time datetime="([^"]+)', webpage, 'release date', default=None)),
  334. 'view_count': int_or_none(self._search_regex(
  335. r'"userInteractionCount"\s*:\s*(\d+)', webpage, 'view count', default=None)),
  336. 'like_count': parse_count(self._search_regex(
  337. r'<span data-js="rumbles_up_votes">\s*([\d,.KM]+)', webpage, 'like count', default=None)),
  338. 'dislike_count': parse_count(self._search_regex(
  339. r'<span data-js="rumbles_down_votes">\s*([\d,.KM]+)', webpage, 'dislike count', default=None)),
  340. 'description': clean_html(get_element_by_class('media-description', webpage)),
  341. }
  342. class RumbleChannelIE(InfoExtractor):
  343. _VALID_URL = r'(?P<url>https?://(?:www\.)?rumble\.com/(?:c|user)/(?P<id>[^&?#$/]+))'
  344. _TESTS = [{
  345. 'url': 'https://rumble.com/c/Styxhexenhammer666',
  346. 'playlist_mincount': 1160,
  347. 'info_dict': {
  348. 'id': 'Styxhexenhammer666',
  349. },
  350. }, {
  351. 'url': 'https://rumble.com/user/goldenpoodleharleyeuna',
  352. 'playlist_mincount': 4,
  353. 'info_dict': {
  354. 'id': 'goldenpoodleharleyeuna',
  355. },
  356. }]
  357. def entries(self, url, playlist_id):
  358. for page in itertools.count(1):
  359. try:
  360. webpage = self._download_webpage(f'{url}?page={page}', playlist_id, note=f'Downloading page {page}')
  361. except ExtractorError as e:
  362. if isinstance(e.cause, HTTPError) and e.cause.status == 404:
  363. break
  364. raise
  365. for video_url in traverse_obj(
  366. get_elements_html_by_class('videostream__link', webpage), (..., {extract_attributes}, 'href'),
  367. ):
  368. yield self.url_result(urljoin('https://rumble.com', video_url))
  369. def _real_extract(self, url):
  370. url, playlist_id = self._match_valid_url(url).groups()
  371. return self.playlist_result(self.entries(url, playlist_id), playlist_id=playlist_id)