diff --git a/nova3/engines/jackett.py b/nova3/engines/jackett.py index 3e0ba75..b614de8 100644 --- a/nova3/engines/jackett.py +++ b/nova3/engines/jackett.py @@ -1,8 +1,9 @@ -# VERSION: 4.0 +# VERSION: 4.1 # AUTHORS: Diego de las Heras (ngosang@hotmail.es) # CONTRIBUTORS: ukharley # hannsen (github.com/hannsen) # Alexander Georgievskiy +# Ryan Meyers (github.com/sreyemnayr) import json import os @@ -21,12 +22,17 @@ # load configuration from file CONFIG_FILE = 'jackett.json' CONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), CONFIG_FILE) -CONFIG_DATA = { +CONFIG_DATA_DEFAULT = { 'api_key': 'YOUR_API_KEY_HERE', # jackett api 'url': 'http://127.0.0.1:9117', # jackett url + 'tracker': True, # (False/True) enable tracker name 'tracker_first': False, # (False/True) add tracker name to beginning of search result 'thread_count': 20, # number of threads to use for http requests + 'freeleech': False, # (False/True) enable freeleech flag + 'freeleech_flag': '🆓', # string to display for freeleech torrents + 'freeleech_first': True, # (False/True) add freeleech flag to beginning of search result } +CONFIG_DATA = CONFIG_DATA_DEFAULT.copy() PRINTER_THREAD_LOCK = Lock() @@ -34,7 +40,7 @@ def load_configuration(): global CONFIG_PATH, CONFIG_DATA try: # try to load user data from file - with open(CONFIG_PATH) as f: + with open(CONFIG_PATH, 'r', encoding='utf-8') as f: CONFIG_DATA = json.load(f) except ValueError: # if file exists, but it's malformed we load add a flag @@ -48,15 +54,22 @@ def load_configuration(): CONFIG_DATA['malformed'] = True # add missing keys - if 'thread_count' not in CONFIG_DATA: - CONFIG_DATA['thread_count'] = 20 + updated_config = [] + for key in CONFIG_DATA_DEFAULT.keys(): + if key not in CONFIG_DATA: + CONFIG_DATA[key] = CONFIG_DATA_DEFAULT[key] + updated_config.append(key) + + if updated_config: + print("Updated configuration file with default values for missing keys: " + ", ".join(updated_config)) save_configuration() + def save_configuration(): global CONFIG_PATH, CONFIG_DATA - with open(CONFIG_PATH, 'w') as f: - f.write(json.dumps(CONFIG_DATA, indent=4, sort_keys=True)) + with open(CONFIG_PATH, 'w', encoding='utf-8') as f: + f.write(json.dumps(CONFIG_DATA, indent=4, sort_keys=True, ensure_ascii=False)) load_configuration() @@ -160,10 +173,29 @@ def search_jackett_indexer(self, what, category, indexer_id): tracker = result.find('jackettindexer') tracker = '' if tracker is None else tracker.text - if CONFIG_DATA['tracker_first']: - res['name'] = '[%s] %s' % (tracker, title) + if CONFIG_DATA['tracker']: + if CONFIG_DATA['tracker_first']: + res['name'] = '[%s] %s' % (tracker, title) + else: + res['name'] = '%s [%s]' % (title, tracker) else: - res['name'] = '%s [%s]' % (title, tracker) + res['name'] = title + + if CONFIG_DATA['freeleech']: + downloadVolumeFactor = 1.0 + downloadVolumeFactorElement = result.find(self.generate_xpath('downloadvolumefactor')) + if downloadVolumeFactorElement is not None: + downloadVolumeFactor = float(downloadVolumeFactorElement.attrib['value']) + else: + downloadVolumeFactorElement = result.find('downloadvolumefactor') + if downloadVolumeFactorElement is not None: + downloadVolumeFactor = float(downloadVolumeFactorElement.text) + + if downloadVolumeFactor <= 0: + if CONFIG_DATA['freeleech_first']: + res['name'] = '%s %s' % (CONFIG_DATA['freeleech_flag'], res['name']) + else: + res['name'] = '%s %s' % (res['name'], CONFIG_DATA['freeleech_flag']) res['link'] = result.find(self.generate_xpath('magneturl')) if res['link'] is not None: diff --git a/wiki/How-to-configure-Jackett-plugin.md b/wiki/How-to-configure-Jackett-plugin.md index db99f27..155c0e0 100644 --- a/wiki/How-to-configure-Jackett-plugin.md +++ b/wiki/How-to-configure-Jackett-plugin.md @@ -110,10 +110,14 @@ following contents: ```json { - "api_key": "YOUR_API_KEY_HERE", - "url": "http://127.0.0.1:9117", - "tracker_first": false, - "thread_count": 20 + "api_key": "YOUR_API_KEY_HERE", + "url": "http://127.0.0.1:9117", + "tracker": true, + "tracker_first": false, + "thread_count": 20, + "freeleech": false, + "freeleech_first": true, + "freeleech_flag": "🆓" } ``` @@ -123,7 +127,7 @@ following contents: > (127.0.0.1) must be replaced with a routable address (for instance, using DDNS > or an IPv6 Global Unicast Address) to allow traffic to pass between it and > qBittorrent. Additional firewall rules or port forwarding may also be needed. -> +> > The change must be made in both the Jackett UI and the plugin configuration > file, specifically its `url` key. For example: @@ -139,12 +143,16 @@ following contents: ### Configuration file properties -| Property name | Initial value | Description | -|:----------------|:------------------------|:----------------------------------------------------------------------------------------------------| -| `api_key` | `YOUR_API_KEY_HERE` | Jackett API Key, shown in the upper-right corner of the Jackett UI ([screenshot below][api-key-ss]) | -| `url` | `http://127.0.0.1:9117` | Jackett service address (without a terminating forward slash) | -| `tracker_first` | `false` | Prepend indexer site name to each search result (takes Boolean value) | -| `thread_count` | `20` | Maximum number of concurrent requests to Jackett (to disable concurrent requests, set value to `1`) | +| Property name | Initial value | Description | +| :---------------- | :---------------------- | :----------------------------------------------------------------------------------------------------------------- | +| `api_key` | `YOUR_API_KEY_HERE` | Jackett API Key, shown in the upper-right corner of the Jackett UI ([screenshot below][api-key-ss]) | +| `url` | `http://127.0.0.1:9117` | Jackett service address (without a terminating forward slash) | +| `tracker` | `true` | Include tracker name in each search result (takes Boolean value) | +| `tracker_first` | `false` | If `tracker` is `true`, prepend (rather than append) indexer site name to each search result (takes Boolean value) | +| `thread_count` | `20` | Maximum number of concurrent requests to Jackett (to disable concurrent requests, set value to `1`) | +| `freeleech` | `false` | Enable freeleech flag (takes Boolean value) | +| `freeleech_first` | `true` | If `freeleech` is `true`, prepend (rather than append) freeleech flag to each search result (takes Boolean value) | +| `freeleech_flag` | `🆓` | String to display for freeleech torrents (takes string value) | ## Disabling/Removing the Jackett plugin @@ -155,10 +163,13 @@ disable it or removing it entirely at any time by following these steps: bottom-right corner. 1. Locate the entry named **Jackett** in the list. 1. To disable the plugin: + - Right-click the entry and clear the checkmark from the **Enabled** option. Or to uninstall the plugin: + - Right-click the entry and select **Uninstall**. + 1. Click the **Close** button. ## Screenshots