Skip to content

Commit

Permalink
Add Prowlarr search engine
Browse files Browse the repository at this point in the history
  • Loading branch information
galeksandrp committed Sep 1, 2024
1 parent efe75be commit 6f6dace
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
29 changes: 20 additions & 9 deletions nova3/engines/jackett.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#VERSION: 4.0
#VERSION: 4.1
# AUTHORS: Diego de las Heras ([email protected])
# CONTRIBUTORS: ukharley
# hannsen (github.com/hannsen)
Expand All @@ -20,10 +20,12 @@
###############################################################################
# load configuration from file
CONFIG_FILE = 'jackett.json'
if 'CONFIG_FILE' in os.environ:
CONFIG_FILE = os.environ['CONFIG_FILE']
CONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), CONFIG_FILE)
CONFIG_DATA = {
'api_key': 'YOUR_API_KEY_HERE', # jackett api
'url': 'http://127.0.0.1:9117', # jackett url
'api_key': 'YOUR_API_KEY_HERE', # jackett / prowlarr api
'url': 'http://127.0.0.1:' + ('9696' if CONFIG_FILE == 'prowlarr.json' else '9117'), # jackett / prowlarr url
'tracker_first': False, # (False/True) add tracker name to beginning of search result
'thread_count': 20, # number of threads to use for http requests
}
Expand Down Expand Up @@ -103,7 +105,7 @@ def search(self, what, cat='all'):
self.handle_error("api key error", what)
return

# search in Jackett API
# search in Jackett / Prowlarr API
if self.thread_count > 1:
args = []
indexers = self.get_jackett_indexers(what)
Expand All @@ -120,29 +122,38 @@ def get_jackett_indexers(self, what):
('t', 'indexers'),
('configured', 'true')
]
if self.name == 'Prowlarr':
params = [params[0]]
params = urlencode(params)
jacket_url = self.url + "/api/v2.0/indexers/all/results/torznab/api?%s" % params
jacket_url = self.url + ("/api/v1/indexer?%s" if self.name == 'Prowlarr' else "/api/v2.0/indexers/all/results/torznab/api?%s") % params
response = self.get_response(jacket_url)
if response is None:
self.handle_error("connection error getting indexer list", what)
return
# process results
if self.name == 'Prowlarr':
indexers = []
for indexer in json.loads(response):
indexers.append(str(indexer['id']))
return indexers
response_xml = xml.etree.ElementTree.fromstring(response)
indexers = []
for indexer in response_xml.findall('indexer'):
indexers.append(indexer.attrib['id'])
return indexers

def search_jackett_indexer(self, what, category, indexer_id):
# prepare jackett url
# prepare jackett / prowlarr url
params = [
('apikey', self.api_key),
('q', what)
]
if self.name == 'Prowlarr':
params.append(('t', 'search'))
if category is not None:
params.append(('cat', ','.join(category)))
params = urlencode(params)
jacket_url = self.url + "/api/v2.0/indexers/" + indexer_id + "/results/torznab/api?%s" % params # noqa
jacket_url = self.url + ("/" + indexer_id + "/api?%s" if self.name == 'Prowlarr' else "/api/v2.0/indexers/" + indexer_id + "/results/torznab/api?%s") % params # noqa
response = self.get_response(jacket_url)
if response is None:
self.handle_error("connection error for indexer: " + indexer_id, what)
Expand All @@ -158,7 +169,7 @@ def search_jackett_indexer(self, what, category, indexer_id):
else:
continue

tracker = result.find('jackettindexer')
tracker = result.find(self.name.lower() + 'indexer')
tracker = '' if tracker is None else tracker.text
if CONFIG_DATA['tracker_first']:
res['name'] = '[%s] %s' % (tracker, title)
Expand Down Expand Up @@ -227,7 +238,7 @@ def handle_error(self, error_msg, what):
'engine_url': self.url,
'link': self.url,
'desc_link': 'https://github.com/qbittorrent/search-plugins/wiki/How-to-configure-Jackett-plugin', # noqa
'name': "Jackett: %s! Right-click this row and select 'Open description page' to open help. Configuration file: '%s' Search: '%s'" % (error_msg, CONFIG_PATH, what) # noqa
'name': self.name + ": %s! Right-click this row and select 'Open description page' to open help. Configuration file: '%s' Search: '%s'" % (error_msg, CONFIG_PATH, what) # noqa
})

def pretty_printer_thread_safe(self, dictionary):
Expand Down
26 changes: 26 additions & 0 deletions nova3/engines/prowlarr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#VERSION: 1.0
# AUTHORS: Alexander Georgievskiy ([email protected])
# CONTRIBUTORS:

import sys
import os
from pathlib import Path

os.environ['CONFIG_FILE'] = 'prowlarr.json'

try:
import jackett
except ImportError:
sys.path.insert(0, str(Path(__file__).parent.absolute()))
import jackett

del os.environ['CONFIG_FILE']


class prowlarr(jackett.jackett):
name = 'Prowlarr'


if __name__ == "__main__":
jackett_se = prowlarr()
jackett_se.search("ubuntu server", 'software')

0 comments on commit 6f6dace

Please sign in to comment.