diff --git a/nova3/engines/jackett.py b/nova3/engines/jackett.py index 291ac7d..1c9d4a7 100644 --- a/nova3/engines/jackett.py +++ b/nova3/engines/jackett.py @@ -1,4 +1,4 @@ -#VERSION: 4.0 +#VERSION: 4.1 # AUTHORS: Diego de las Heras (ngosang@hotmail.es) # CONTRIBUTORS: ukharley # hannsen (github.com/hannsen) @@ -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'), # 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 } @@ -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) @@ -120,13 +122,22 @@ 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 + if self.name == 'Prowlarr': + jacket_url = self.url + "/api/v1/indexer?%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'): @@ -134,15 +145,17 @@ def get_jackett_indexers(self, what): 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) @@ -158,7 +171,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) @@ -227,7 +240,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): diff --git a/nova3/engines/prowlarr.py b/nova3/engines/prowlarr.py new file mode 100644 index 0000000..3a63d9e --- /dev/null +++ b/nova3/engines/prowlarr.py @@ -0,0 +1,26 @@ +#VERSION: 1.0 +# AUTHORS: Alexander Georgievskiy (galeksandrp@gmail.com) +# 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')