From f9c486814203f25b35903880dd038b35ed0580a2 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 4 Feb 2022 11:00:56 +0100 Subject: [PATCH] [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 --- searx/engines/solidtorrents.py | 17 ++++++++--------- 1 file 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)