.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
39from datetime import datetime
40from urllib.parse import quote
41
42from lxml import etree
43
44# about
45about = {
46 "website": 'https://bt4gprx.com',
47 "use_official_api": False,
48 "require_api_key": False,
49 "results": 'XML',
50}
51
52# engine dependent config
53categories = ['files']
54paging = True
55time_range_support = True
56
57# search-url
58url = 'https://bt4gprx.com'
59search_url = url + '/search?q={search_term}&orderby={order_by}&category={category}&p={pageno}&page=rss'
60bt4g_order_by = 'relevance'
61"""Result list can be ordered by ``relevance`` (default), ``size``, ``seeders``
62or ``time``.
63
64.. hint::
65
66 When *time_range* is activate, the results always ordered by ``time``.
67"""
68
69bt4g_category = 'all'
70"""BT$G offers categories: ``all`` (default), ``audio``, ``movie``, ``doc``,
71``app`` and `` other``.
72"""
73
74
75def request(query, params):
76
77 order_by = bt4g_order_by
78 if params['time_range']:
79 order_by = 'time'
80
81 params['url'] = search_url.format(
82 search_term=quote(query),
83 order_by=order_by,
84 category=bt4g_category,
85 pageno=params['pageno'],
86 )
87 return params
88
89
90def response(resp):
91 results = []
92
93 search_results = etree.XML(resp.content)
94
95 # return empty array if nothing is found
96 if len(search_results) == 0:
97 return []
98
99 for entry in search_results.xpath('./channel/item'):
100 title = entry.find("title").text
101 link = entry.find("guid").text
102 fullDescription = entry.find("description").text.split('<br>')
103 magnetlink = entry.find("link").text
104 pubDate = entry.find("pubDate").text
105 results.append(
106 {
107 'url': link,
108 'title': title,
109 'magnetlink': magnetlink,
110 'seed': 'N/A',
111 'leech': 'N/A',
112 'filesize': fullDescription[1],
113 'publishedDate': datetime.strptime(pubDate, '%a,%d %b %Y %H:%M:%S %z'),
114 'template': 'torrent.html',
115 }
116 )
117
118 return results
request(query, params)
Definition bt4g.py:75
response(resp)
Definition bt4g.py:90