.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
solidtorrents.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""SolidTorrents
3
4"""
5
6from datetime import datetime
7from urllib.parse import urlencode
8import random
9
10from lxml import html
11
12from searx.utils import (
13 extract_text,
14 eval_xpath,
15 eval_xpath_getindex,
16 eval_xpath_list,
17)
18
19about = {
20 "website": 'https://www.solidtorrents.to/',
21 "wikidata_id": None,
22 "official_api_documentation": None,
23 "use_official_api": False,
24 "require_api_key": False,
25 "results": 'HTML',
26}
27
28categories = ['files']
29paging = True
30
31# base_url can be overwritten by a list of URLs in the settings.yml
32base_url = 'https://solidtorrents.to'
33
34
35def request(query, params):
36 if isinstance(base_url, list):
37 params['base_url'] = random.choice(base_url)
38 else:
39 params['base_url'] = base_url
40 search_url = params['base_url'] + '/search?{query}'
41 query = urlencode({'q': query, 'page': params['pageno']})
42 params['url'] = search_url.format(query=query)
43 return params
44
45
46def response(resp):
47 results = []
48 dom = html.fromstring(resp.text)
49
50 for result in eval_xpath(dom, '//li[contains(@class, "search-result")]'):
51 torrentfile = eval_xpath_getindex(result, './/a[contains(@class, "dl-torrent")]/@href', 0, None)
52 magnet = eval_xpath_getindex(result, './/a[contains(@class, "dl-magnet")]/@href', 0, None)
53 if torrentfile is None or magnet is None:
54 continue # ignore anime results that which aren't actually torrents
55 title = eval_xpath_getindex(result, './/h5[contains(@class, "title")]', 0, None)
56 url = eval_xpath_getindex(result, './/h5[contains(@class, "title")]/a/@href', 0, None)
57 categ = eval_xpath(result, './/a[contains(@class, "category")]')
58 stats = eval_xpath_list(result, './/div[contains(@class, "stats")]/div', min_len=5)
59
60 params = {
61 'seed': extract_text(stats[3]),
62 'leech': extract_text(stats[2]),
63 'title': extract_text(title),
64 'url': resp.search_params['base_url'] + url,
65 'filesize': extract_text(stats[1]),
66 'magnetlink': magnet,
67 'torrentfile': torrentfile,
68 'metadata': extract_text(categ),
69 'template': "torrent.html",
70 }
71
72 try:
73 params['publishedDate'] = datetime.strptime(extract_text(stats[4]), '%b %d, %Y')
74 except ValueError:
75 pass
76
77 results.append(params)
78
79 return results