Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: jackett plugin freeleech flags #337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions nova3/engines/jackett.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# VERSION: 4.0
# VERSION: 4.1
# AUTHORS: Diego de las Heras ([email protected])
# CONTRIBUTORS: ukharley
# hannsen (github.com/hannsen)
# Alexander Georgievskiy <[email protected]>
# Ryan Meyers (github.com/sreyemnayr)

import json
import os
Expand All @@ -21,20 +22,25 @@
# 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()


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
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 22 additions & 11 deletions wiki/How-to-configure-Jackett-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "🆓"
}
```

Expand All @@ -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:

Expand All @@ -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

Expand All @@ -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
Expand Down
Loading