[fix] solidtorrents

This commit is contained in:
Justas Zabulionis 2023-09-14 00:32:17 -07:00 committed by Markus Heiser
parent 74600c028d
commit 8172f89075
1 changed files with 15 additions and 23 deletions

View File

@ -49,38 +49,30 @@ def response(resp):
results = [] results = []
dom = html.fromstring(resp.text) dom = html.fromstring(resp.text)
for result in eval_xpath(dom, '//div[contains(@class, "search-result")]'): for result in eval_xpath(dom, '//li[contains(@class, "search-result")]'):
a = eval_xpath_getindex(result, './div/h5/a', 0, None) torrentfile = eval_xpath_getindex(result, './/a[contains(@class, "dl-torrent")]/@href', 0, None)
if a is None: magnet = eval_xpath_getindex(result, './/a[contains(@class, "dl-magnet")]/@href', 0, None)
continue if torrentfile is None or magnet is None:
title = extract_text(a) continue # ignore anime results that which aren't actually torrents
url = eval_xpath_getindex(a, '@href', 0, None) title = eval_xpath_getindex(result, './/h5[contains(@class, "title")]', 0, None)
categ = eval_xpath(result, './div//a[contains(@class, "category")]') url = eval_xpath_getindex(result, './/h5[contains(@class, "title")]/a/@href', 0, None)
metadata = extract_text(categ) categ = eval_xpath(result, './/a[contains(@class, "category")]')
stats = eval_xpath_list(result, './div//div[contains(@class, "stats")]/div', min_len=5) stats = eval_xpath_list(result, './/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)
params = { params = {
'seed': seed, 'seed': extract_text(stats[3]),
'leech': leech, 'leech': extract_text(stats[2]),
'title': title, 'title': extract_text(title),
'url': resp.search_params['base_url'] + url, 'url': resp.search_params['base_url'] + url,
'filesize': filesize, 'filesize': get_torrent_size(*extract_text(stats[1]).split()),
'magnetlink': magnet, 'magnetlink': magnet,
'torrentfile': torrentfile, 'torrentfile': torrentfile,
'metadata': metadata, 'metadata': extract_text(categ),
'template': "torrent.html", 'template': "torrent.html",
} }
date_str = extract_text(stats[4])
try: try:
params['publishedDate'] = datetime.strptime(date_str, '%b %d, %Y') params['publishedDate'] = datetime.strptime(extract_text(stats[4]), '%b %d, %Y')
except ValueError: except ValueError:
pass pass