Skip to content

Commit

Permalink
Merge pull request #297 from lardbit/disaac/fixes-issue-292-add-jacke…
Browse files Browse the repository at this point in the history
…tt-filter-index-support

feat: Support scoping jackett searches with filter
  • Loading branch information
lardbit authored Jul 11, 2024
2 parents 330ff26 + 6567daa commit 9670822
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libatlas-base-dev libhdf5-dev libavutil-dev libswresample-dev libavcodec-dev libavformat-dev libswscale-dev \
&& mkdir -p /nefarious-db \
&& python -m venv /env \
&& /env/bin/pip install -U pip \
&& /env/bin/pip install --no-cache-dir --only-binary :all: --extra-index-url https://www.piwheels.org/simple -r requirements.txt \
&& /env/bin/pip install -U pip==24 \
&& /env/bin/pip install --no-cache-dir -r requirements.txt \
&& /env/bin/python manage.py collectstatic --no-input \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<label>API Token</label>
<input type="text" class="form-control" placeholder="" formControlName="jackett_token" required>
</div>
<div class="my-2">
<label>Filter-Index</label>
<input type="text" class="form-control" formControlName="jackett_filter_index">
<small class="form-text text-muted">
Optionally define a <a target="_blank" href="https://github.com/Jackett/Jackett#filter-indexers">filter-index</a> for jackett. Leave blank for default search.
</small>
</div>
<div class="my-2 d-flex justify-content-between">
<button type="button" class="btn btn-sm btn-outline-primary position-relative" (click)="saveAndVerifyJackettIndexers()">
<ngx-loading [show]="isVeryingJackettIndexers"></ngx-loading>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class SettingsComponent implements OnInit, AfterContentChecked {
'jackett_host': [settings['jackett_host'], Validators.required],
'jackett_port': [settings['jackett_port'], Validators.required],
'jackett_token': [settings['jackett_token'], Validators.required],
'jackett_filter_index': [settings['jackett_filter_index']],
'transmission_host': [settings['transmission_host'], Validators.required],
'transmission_port': [settings['transmission_port'], Validators.required],
'transmission_user': [settings['transmission_user']],
Expand Down
8 changes: 6 additions & 2 deletions src/nefarious/jackett.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@


def get_jackett_search_url(nefarious_settings: NefariousSettings):
return 'http://{}:{}/api/v2.0/indexers/all/results'.format(
nefarious_settings.jackett_host, nefarious_settings.jackett_port)
return "http://{}:{}/api/v2.0/indexers/{}/results".format(
nefarious_settings.jackett_host,
nefarious_settings.jackett_port,
# https://github.com/Jackett/Jackett#filter-indexers
nefarious_settings.jackett_filter_index or 'all',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2024-07-01 15:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0077_watchtvseasonrequest_date_updated'),
]

operations = [
migrations.AddField(
model_name='nefarioussettings',
name='jackett_filter_index',
field=models.CharField(blank=True, null=True, help_text='Optional Jackett index filter to use for searches', max_length=500),
),
]
2 changes: 2 additions & 0 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NefariousSettings(models.Model):
jackett_host = models.CharField(max_length=500, default='jackett')
jackett_port = models.IntegerField(default=9117)
jackett_token = models.CharField(max_length=500, default=JACKETT_TOKEN_DEFAULT)
jackett_filter_index = models.CharField( # https://github.com/Jackett/Jackett#filter-indexers
max_length=500, null=True, blank=True, help_text='Optional Jackett index filter to use for searches')

# transmission
transmission_host = models.CharField(max_length=500, default='transmission')
Expand Down
2 changes: 2 additions & 0 deletions src/nefarious/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List
from nefarious.jackett import get_jackett_search_url
from nefarious.models import NefariousSettings
from nefarious.utils import logger_background

SEARCH_MEDIA_TYPE_TV = 'tv'
SEARCH_MEDIA_TYPE_MOVIE = 'movie'
Expand All @@ -24,6 +25,7 @@ def __init__(self, media_type: str, query: str):
}

res = requests.get(get_jackett_search_url(self.nefarious_settings), params, timeout=90)
logger_background.info(f'jackett search: query={query}, url={res.url}')

if res.ok:
response = res.json()
Expand Down
12 changes: 8 additions & 4 deletions src/nefarious/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from urllib.parse import urlparse
from transmissionrpc import TransmissionError

from nefarious.jackett import get_jackett_search_url
from nefarious.models import NefariousSettings, WatchMovie, WatchTVSeason, WatchTVEpisode, WatchMediaBase, TorrentBlacklist
from nefarious.tmdb import get_tmdb_client
from nefarious.transmission import get_transmission_client
Expand Down Expand Up @@ -66,13 +67,16 @@ def verify_settings_transmission(nefarious_settings: NefariousSettings):

def verify_settings_jackett(nefarious_settings: NefariousSettings):
"""
A special "all" indexer is available at /api/v2.0/indexers/all/results/torznab/api. It will query all configured indexers and return the combined results.
A special "all" indexer or filter-index is available at /api/v2.0/indexers/all/results/torznab/api. It will query all configured indexers and return the combined results.
NOTE: /api/v2.0/indexers/all/results will return json results vs torznab's xml response
"""
try:
# make an unspecified query to the "all" indexer results endpoint and see if it's successful
response = requests.get('http://{}:{}/api/v2.0/indexers/all/results'.format(
nefarious_settings.jackett_host, nefarious_settings.jackett_port), params={'apikey': nefarious_settings.jackett_token}, timeout=60)
# make an unspecified query to the indexer results endpoint and see if it's successful
response = requests.get(
get_jackett_search_url(nefarious_settings),
params={"apikey": nefarious_settings.jackett_token},
timeout=60,
)
response.raise_for_status()
return response.json()
except Exception as e:
Expand Down

0 comments on commit 9670822

Please sign in to comment.