From 8172f89075eab498ca8ee043150a1820442b2ecb Mon Sep 17 00:00:00 2001 From: Justas Zabulionis <38244149+jazzzooo@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:32:17 -0700 Subject: [PATCH] [fix] solidtorrents --- searx/engines/solidtorrents.py | 38 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/searx/engines/solidtorrents.py b/searx/engines/solidtorrents.py index 9b5d543d8..248716b2b 100644 --- a/searx/engines/solidtorrents.py +++ b/searx/engines/solidtorrents.py @@ -49,38 +49,30 @@ def response(resp): results = [] dom = html.fromstring(resp.text) - for result in eval_xpath(dom, '//div[contains(@class, "search-result")]'): - a = eval_xpath_getindex(result, './div/h5/a', 0, None) - if a is None: - continue - title = extract_text(a) - url = eval_xpath_getindex(a, '@href', 0, None) - categ = eval_xpath(result, './div//a[contains(@class, "category")]') - metadata = extract_text(categ) - stats = eval_xpath_list(result, './div//div[contains(@class, "stats")]/div', min_len=5) - n, u = extract_text(stats[1]).split() - filesize = get_torrent_size(n, u) - leech = extract_text(stats[2]) - seed = extract_text(stats[3]) - torrentfile = eval_xpath_getindex(result, './div//a[contains(@class, "dl-torrent")]/@href', 0, None) - magnet = eval_xpath_getindex(result, './div//a[contains(@class, "dl-magnet")]/@href', 0, None) + for result in eval_xpath(dom, '//li[contains(@class, "search-result")]'): + torrentfile = eval_xpath_getindex(result, './/a[contains(@class, "dl-torrent")]/@href', 0, None) + magnet = eval_xpath_getindex(result, './/a[contains(@class, "dl-magnet")]/@href', 0, None) + if torrentfile is None or magnet is None: + continue # ignore anime results that which aren't actually torrents + title = eval_xpath_getindex(result, './/h5[contains(@class, "title")]', 0, None) + url = eval_xpath_getindex(result, './/h5[contains(@class, "title")]/a/@href', 0, None) + categ = eval_xpath(result, './/a[contains(@class, "category")]') + stats = eval_xpath_list(result, './/div[contains(@class, "stats")]/div', min_len=5) params = { - 'seed': seed, - 'leech': leech, - 'title': title, + 'seed': extract_text(stats[3]), + 'leech': extract_text(stats[2]), + 'title': extract_text(title), 'url': resp.search_params['base_url'] + url, - 'filesize': filesize, + 'filesize': get_torrent_size(*extract_text(stats[1]).split()), 'magnetlink': magnet, 'torrentfile': torrentfile, - 'metadata': metadata, + 'metadata': extract_text(categ), 'template': "torrent.html", } - date_str = extract_text(stats[4]) - try: - params['publishedDate'] = datetime.strptime(date_str, '%b %d, %Y') + params['publishedDate'] = datetime.strptime(extract_text(stats[4]), '%b %d, %Y') except ValueError: pass