.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
bt4g.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""BT4G_ (bt4g.com) is not a tracker and doesn't store any content and only
3collects torrent metadata (such as file names and file sizes) and a magnet link
4(torrent identifier).
5
6This engine does not parse the HTML page because there is an API in XML (RSS).
7The RSS feed provides fewer data like amount of seeders/leechers and the files
8in the torrent file. It's a tradeoff for a "stable" engine as the XML from RSS
9content will change way less than the HTML page.
10
11.. _BT4G: https://bt4g.com/
12
13Configuration
14=============
15
16The engine has the following additional settings:
17
18- :py:obj:`bt4g_order_by`
19- :py:obj:`bt4g_category`
20
21With this options a SearXNG maintainer is able to configure **additional**
22engines for specific torrent searches. For example a engine to search only for
23Movies and sort the result list by the count of seeders.
24
25.. code:: yaml
26
27 - name: bt4g.movie
28 engine: bt4g
29 shortcut: bt4gv
30 categories: video
31 bt4g_order_by: seeders
32 bt4g_category: 'movie'
33
34Implementations
35===============
36
37"""
38
39import re
40from datetime import datetime
41from urllib.parse import quote
42
43from lxml import etree
44
45from searx.utils import get_torrent_size
46
47# about
48about = {
49 "website": 'https://bt4gprx.com',
50 "use_official_api": False,
51 "require_api_key": False,
52 "results": 'XML',
53}
54
55# engine dependent config
56categories = ['files']
57paging = True
58time_range_support = True
59
60# search-url
61url = 'https://bt4gprx.com'
62search_url = url + '/search?q={search_term}&orderby={order_by}&category={category}&p={pageno}&page=rss'
63bt4g_order_by = 'relevance'
64"""Result list can be ordered by ``relevance`` (default), ``size``, ``seeders``
65or ``time``.
66
67.. hint::
68
69 When *time_range* is activate, the results always ordered by ``time``.
70"""
71
72bt4g_category = 'all'
73"""BT$G offers categories: ``all`` (default), ``audio``, ``movie``, ``doc``,
74``app`` and `` other``.
75"""
76
77
78def request(query, params):
79
80 order_by = bt4g_order_by
81 if params['time_range']:
82 order_by = 'time'
83
84 params['url'] = search_url.format(
85 search_term=quote(query),
86 order_by=order_by,
87 category=bt4g_category,
88 pageno=params['pageno'],
89 )
90 return params
91
92
93def response(resp):
94 results = []
95
96 search_results = etree.XML(resp.content)
97
98 # return empty array if nothing is found
99 if len(search_results) == 0:
100 return []
101
102 for entry in search_results.xpath('./channel/item'):
103 title = entry.find("title").text
104 link = entry.find("guid").text
105 fullDescription = entry.find("description").text.split('<br>')
106 filesize = fullDescription[1]
107 filesizeParsed = re.split(r"([A-Z]+)", filesize)
108 magnetlink = entry.find("link").text
109 pubDate = entry.find("pubDate").text
110 results.append(
111 {
112 'url': link,
113 'title': title,
114 'magnetlink': magnetlink,
115 'seed': 'N/A',
116 'leech': 'N/A',
117 'filesize': get_torrent_size(filesizeParsed[0], filesizeParsed[1]),
118 'publishedDate': datetime.strptime(pubDate, '%a,%d %b %Y %H:%M:%S %z'),
119 'template': 'torrent.html',
120 }
121 )
122
123 return results
request(query, params)
Definition bt4g.py:78
response(resp)
Definition bt4g.py:93