rumble.py 15 KB

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