summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-02-04 11:00:56 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2022-02-04 14:53:42 +0100
commitf9c486814203f25b35903880dd038b35ed0580a2 (patch)
tree9cff8b5870e053c14b8254079a2b74dcaf86b1ff /searx
parentd92b3d96fdfad4dd009cefa3762d70fa76a987c7 (diff)
downloadsearxng-f9c486814203f25b35903880dd038b35ed0580a2.tar.gz
searxng-f9c486814203f25b35903880dd038b35ed0580a2.zip
[fix] solidtorrents engine: use get_torrent_size from searx.utils
Suggested-by: @dalf https://github.com/searxng/searxng/pull/862#pullrequestreview-872858489 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/solidtorrents.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/searx/engines/solidtorrents.py b/searx/engines/solidtorrents.py
index 6a98a1c29..7f005c4a3 100644
--- a/searx/engines/solidtorrents.py
+++ b/searx/engines/solidtorrents.py
@@ -9,7 +9,12 @@ import random
from lxml import html
-from searx.utils import extract_text, eval_xpath, eval_xpath_getindex
+from searx.utils import (
+ extract_text,
+ eval_xpath,
+ eval_xpath_getindex,
+ get_torrent_size,
+)
about = {
"website": 'https://www.solidtorrents.net/',
@@ -26,13 +31,6 @@ paging = True
base_url = ''
base_url_rand = ''
-units = {"B": 1, "KB": 2 ** 10, "MB": 2 ** 20, "GB": 2 ** 30, "TB": 2 ** 40}
-
-
-def size2int(size_str):
- n, u = size_str.split()
- return int(float(n.strip()) * units[u.strip()])
-
def request(query, params):
global base_url_rand # pylint: disable=global-statement
@@ -58,7 +56,8 @@ def response(resp):
title = extract_text(a)
url = eval_xpath_getindex(a, '@href', 0, None)
stats = eval_xpath(result, './div//div[contains(@class, "stats")]/div')
- filesize = size2int(extract_text(stats[1]))
+ n, u = extract_text(stats[1]).split()
+ filesize = get_torrent_size(n, u)
leech = extract_text(stats[2])
seed = extract_text(stats[3])
magnet = eval_xpath_getindex(result, './div//a[contains(@class, "dl-magnet")]/@href', 0, None)