2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-09-24 16:20:12 +00:00
|
|
|
# lint: pylint
|
|
|
|
"""Kickass Torrent (Videos, Music, Files)"""
|
2014-12-09 18:19:39 +00:00
|
|
|
|
2023-09-24 16:20:12 +00:00
|
|
|
import random
|
2014-12-09 18:19:39 +00:00
|
|
|
from operator import itemgetter
|
2023-09-24 16:20:12 +00:00
|
|
|
from urllib.parse import quote
|
|
|
|
|
|
|
|
from lxml import html
|
|
|
|
from searx.utils import (
|
|
|
|
eval_xpath,
|
|
|
|
eval_xpath_getindex,
|
|
|
|
eval_xpath_list,
|
|
|
|
extract_text,
|
|
|
|
get_torrent_size,
|
|
|
|
int_or_zero,
|
|
|
|
)
|
2014-12-09 18:19:39 +00:00
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
about = {
|
2023-09-24 16:20:12 +00:00
|
|
|
"website": 'https://kickasstorrents.to',
|
2021-01-13 10:31:25 +00:00
|
|
|
"wikidata_id": 'Q17062285',
|
|
|
|
"official_api_documentation": None,
|
|
|
|
"use_official_api": False,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'HTML',
|
|
|
|
}
|
|
|
|
|
2021-05-29 14:14:19 +00:00
|
|
|
categories = ['files']
|
2014-12-09 18:19:39 +00:00
|
|
|
paging = True
|
|
|
|
|
2023-09-24 16:20:12 +00:00
|
|
|
# base_url can be overwritten by a list of URLs in the settings.yml
|
|
|
|
base_url = 'https://kickasstorrents.to'
|
2014-12-09 18:19:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def request(query, params):
|
2023-09-24 16:20:12 +00:00
|
|
|
params['base_url'] = random.choice(base_url) if isinstance(base_url, list) else base_url
|
|
|
|
params['url'] = params['base_url'] + f'/usearch/{quote(query)}/{params["pageno"]}/'
|
2014-12-09 18:19:39 +00:00
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
dom = html.fromstring(resp.text)
|
|
|
|
|
2023-10-07 08:53:49 +00:00
|
|
|
search_res = eval_xpath_list(dom, '//table[contains(@class, "data")]//tr[descendant::a]', None)
|
2023-09-24 16:20:12 +00:00
|
|
|
if search_res is None:
|
2014-12-09 18:19:39 +00:00
|
|
|
return []
|
|
|
|
|
2023-09-24 16:20:12 +00:00
|
|
|
for tag in search_res[1:]:
|
|
|
|
result = {'template': 'torrent.html'}
|
|
|
|
url = eval_xpath_getindex(tag, './/a[contains(@class, "cellMainLink")]/@href', 0, None)
|
|
|
|
result['url'] = resp.search_params['base_url'] + url
|
|
|
|
result['title'] = extract_text(eval_xpath(tag, './/a[contains(@class, "cellMainLink")]'))
|
|
|
|
result['content'] = extract_text(eval_xpath(tag, './/span[@class="font11px lightgrey block"]'))
|
|
|
|
result['seed'] = int_or_zero(extract_text(eval_xpath(tag, './/td[contains(@class, "green")]')))
|
|
|
|
result['leech'] = int_or_zero(extract_text(eval_xpath(tag, './/td[contains(@class, "red")]')))
|
|
|
|
result['filesize'] = get_torrent_size(*extract_text(eval_xpath(tag, './/td[contains(@class, "nobr")]')).split())
|
2014-12-09 18:19:39 +00:00
|
|
|
|
2023-09-24 16:20:12 +00:00
|
|
|
results.append(result)
|
2014-12-09 18:19:39 +00:00
|
|
|
|
2023-09-24 16:20:12 +00:00
|
|
|
# results sorted by seeder count
|
2014-12-09 18:19:39 +00:00
|
|
|
return sorted(results, key=itemgetter('seed'), reverse=True)
|