.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
rumble.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Rumble (Videos)
3
4"""
5
6from datetime import datetime
7
8from urllib.parse import urlencode
9from lxml import html
10
11# about
12from searx.utils import extract_text
13
14about = {
15 "website": 'https://rumble.com/',
16 "wikidata_id": 'Q104765127',
17 "official_api_documentation": 'https://help.rumble.com/',
18 "use_official_api": False,
19 "require_api_key": False,
20 "results": 'HTML',
21}
22
23# engine dependent config
24categories = ['videos']
25paging = True
26
27# search-url
28base_url = 'https://rumble.com/'
29
30url_xpath = './/a[@class="video-item--a"]/@href'
31thumbnail_xpath = './/img[@class="video-item--img"]/@src'
32title_xpath = './/h3[@class="video-item--title"]'
33published_date = './/time[@class="video-item--meta video-item--time"]/@datetime'
34earned_xpath = './/span[@class="video-item--meta video-item--earned"]/@data-value'
35views_xpath = './/span[@class="video-item--meta video-item--views"]/@data-value'
36rumbles_xpath = './/span[@class="video-item--meta video-item--rumbles"]/@data-value'
37author_xpath = './/div[@class="ellipsis-1"]'
38length_xpath = './/span[@class="video-item--duration"]/@data-value'
39
40
41def request(query, params):
42 args = {"q": query}
43 if params["pageno"] > 1:
44 args['page'] = params["pageno"]
45 params['url'] = f'{base_url}search/video?{urlencode(args)}'
46 return params
47
48
49def response(resp):
50 results = []
51 dom = html.fromstring(resp.text)
52 results_dom = dom.xpath('//li[contains(@class, "video-listing-entry")]')
53
54 if not results_dom:
55 return []
56
57 for result_dom in results_dom:
58 url = base_url + extract_text(result_dom.xpath(url_xpath))
59 thumbnail = extract_text(result_dom.xpath(thumbnail_xpath))
60 title = extract_text(result_dom.xpath(title_xpath))
61 p_date = extract_text(result_dom.xpath(published_date))
62 # fix offset date for line 644 webapp.py check
63 fixed_date = datetime.strptime(p_date, '%Y-%m-%dT%H:%M:%S%z')
64 earned = extract_text(result_dom.xpath(earned_xpath))
65 views = extract_text(result_dom.xpath(views_xpath))
66 rumbles = extract_text(result_dom.xpath(rumbles_xpath))
67 author = extract_text(result_dom.xpath(author_xpath))
68 length = extract_text(result_dom.xpath(length_xpath))
69 if earned:
70 content = f"{views} views - {rumbles} rumbles - ${earned}"
71 else:
72 content = f"{views} views - {rumbles} rumbles"
73
74 results.append(
75 {
76 'url': url,
77 'title': title,
78 'content': content,
79 'author': author,
80 'length': length,
81 'template': 'videos.html',
82 'publishedDate': fixed_date,
83 'thumbnail': thumbnail,
84 }
85 )
86 return results
request(query, params)
Definition rumble.py:41