.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
kickass.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Kickass Torrent (Videos, Music, Files)"""
3
4import random
5from operator import itemgetter
6from urllib.parse import quote
7
8from lxml import html
9from searx.utils import (
10 eval_xpath,
11 eval_xpath_getindex,
12 eval_xpath_list,
13 extract_text,
14 int_or_zero,
15)
16
17about = {
18 "website": 'https://kickasstorrents.to',
19 "wikidata_id": 'Q17062285',
20 "official_api_documentation": None,
21 "use_official_api": False,
22 "require_api_key": False,
23 "results": 'HTML',
24}
25
26categories = ['files']
27paging = True
28
29# base_url can be overwritten by a list of URLs in the settings.yml
30base_url = 'https://kickasstorrents.to'
31
32
33def request(query, params):
34 params['base_url'] = random.choice(base_url) if isinstance(base_url, list) else base_url
35 params['url'] = params['base_url'] + f'/usearch/{quote(query)}/{params["pageno"]}/'
36
37 return params
38
39
40def response(resp):
41 results = []
42 dom = html.fromstring(resp.text)
43
44 search_res = eval_xpath_list(dom, '//table[contains(@class, "data")]//tr[descendant::a]', None)
45 if search_res is None:
46 return []
47
48 for tag in search_res[1:]:
49 result = {'template': 'torrent.html'}
50 url = eval_xpath_getindex(tag, './/a[contains(@class, "cellMainLink")]/@href', 0, None)
51 result['url'] = resp.search_params['base_url'] + url
52 result['title'] = extract_text(eval_xpath(tag, './/a[contains(@class, "cellMainLink")]'))
53 result['content'] = extract_text(eval_xpath(tag, './/span[@class="font11px lightgrey block"]'))
54 result['seed'] = int_or_zero(extract_text(eval_xpath(tag, './/td[contains(@class, "green")]')))
55 result['leech'] = int_or_zero(extract_text(eval_xpath(tag, './/td[contains(@class, "red")]')))
56 result['filesize'] = extract_text(eval_xpath(tag, './/td[contains(@class, "nobr")]'))
57
58 results.append(result)
59
60 # results sorted by seeder count
61 return sorted(results, key=itemgetter('seed'), reverse=True)
request(query, params)
Definition kickass.py:33