summaryrefslogtreecommitdiff
path: root/searx/engines/solidtorrents.py
blob: 0501491874572c095f0afa5a095eb1f10ac9adf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Solid Torrents

"""

# pylint: disable=missing-function-docstring

from json import loads
from urllib.parse import urlencode
from searx import logger

logger = logger.getChild('solidtor engine')

about = {
    "website": 'https://www.solidtorrents.net/',
    "wikidata_id": None,
    "official_api_documentation": None,
    "use_official_api": True,
    "require_api_key": False,
    "results": 'JSON',
}

categories = ['files']
paging = True

base_url = 'https://www.solidtorrents.net/'
search_url = base_url + 'api/v1/search?{query}'


def request(query, params):
    skip = (params['pageno'] - 1) * 20
    query = urlencode({'q': query, 'skip': skip})
    params['url'] = search_url.format(query=query)
    logger.debug("query_url --> %s", params['url'])
    return params


def response(resp):
    results = []
    search_results = loads(resp.text)

    for result in search_results["results"]:
        results.append({
            'infohash': result["infohash"],
            'seed': result["swarm"]["seeders"],
            'leech': result["swarm"]["leechers"],
            'title': result["title"],
            'link': "https://solidtorrents.net/view/" + result["_id"],
            'filesize': result["size"],
            'magnetlink': result["magnet"],
            'template': "torrent.html",
        })
    return results