Skip to content

Commit

Permalink
Fix jackett. Begin to add title support for jackett.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spoked authored and Spoked committed Jan 14, 2024
1 parent b264d5e commit 7f982b2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
11 changes: 11 additions & 0 deletions backend/program/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from utils.service_manager import ServiceManager
from utils.settings import settings_manager as settings
from utils.logger import logger
from utils.parser import parser
from .torrentio import Torrentio
from .orionoid import Orionoid
from .jackett import Jackett
Expand Down Expand Up @@ -55,3 +56,13 @@ def _needs_new_scrape(self, item) -> bool:
> scrape_time
or item.scraped_times == 0
)
def _check_for_title_match(self, item, string) -> bool:
"""Check if the title matches PTN title"""
parsed_title = parser.get_title(string)
if item.type == "movie":
return parsed_title == item.title
if item.type == "season":
return parsed_title == item.parent.title
if item.type == "episode":
return parsed_title == item.parent.parent.title
return False
35 changes: 15 additions & 20 deletions backend/program/scrapers/jackett.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, _):
if not self.initialized or not self.api_key:
return
self.minute_limiter = RateLimiter(max_calls=60, period=60, raise_on_limit=True)
self.second_limiter = RateLimiter(max_calls=1, period=1)
self.second_limiter = RateLimiter(max_calls=1, period=3)
logger.info("Jackett initialized!")

def validate_settings(self) -> bool:
Expand All @@ -35,7 +35,7 @@ def validate_settings(self) -> bool:
try:
url = f"{self.settings.url}/api/v2.0/server/config"
response = get(url=url, retry_if_failed=False, timeout=60)
if response.is_ok:
if response.is_ok and response.data.api_key is not None:
self.api_key = response.data.api_key
return True
except ReadTimeout:
Expand Down Expand Up @@ -79,22 +79,17 @@ def api_scrape(self, item):
url = (
f"{self.settings.url}/api/v2.0/indexers/all/results/torznab?apikey={self.api_key}{query}"
)
try:
with self.second_limiter:
response = get(url=url, retry_if_failed=False, timeout=60)
if response.is_ok:
data = {}
if not hasattr(response.data['rss']['channel'], "item"):
return {}
for stream in response.data['rss']['channel']['item']:
title = stream.get('title')
for attr in stream.get('torznab:attr', []):
if attr.get('@name') == 'infohash':
infohash = attr.get('@value')
if parser.parse(title) and infohash:
data[infohash] = {"name": title}
if len(data) > 0:
return parser.sort_streams(data)
return {}
except ReadTimeout:
logger.debug("Jackett timed out for %s", item.log_string)
return
if response.is_ok:
data = {}
for stream in response.data['rss']['channel']['item']:
title = stream.get('title')
for attr in stream.get('torznab:attr', []):
if attr.get('@name') == 'infohash':
infohash = attr.get('@value')
if parser.parse(title) and infohash:
data[infohash] = {"name": title}
if len(data) > 0:
return parser.sort_streams(data)
return {}
2 changes: 1 addition & 1 deletion backend/utils/default_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
"highest_quality": false,
"repack_proper": true,
"dual_audio": true,
"av1_audio": false
"av1_audio": true
}
}
9 changes: 8 additions & 1 deletion backend/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _parse(self, string):
else:
episodes.append(int(episode))

title = parse.get("title")
season = parse.get("season")
audio = parse.get("audio")
codec = parse.get("codec")
Expand All @@ -85,6 +86,7 @@ def _parse(self, string):
extended = parse.get("extended")

return {
"title": title,
"resolution": resolution or [],
"quality": quality or [],
"season": season,
Expand All @@ -96,7 +98,7 @@ def _parse(self, string):
"remastered": remastered or False,
"proper": proper or False,
"repack": repack or False,
"subtitles": subtitles or [],
"subtitles": True if subtitles == "Available" else False,
"language": language or [],
"remux": remux or False,
"extended": extended,
Expand Down Expand Up @@ -177,4 +179,9 @@ def parse(self, string) -> bool:
and not parse["codec"] in self.unwanted_codec
)

def get_title(self, string) -> str:
"""Get the `title` from the given string."""
parse = self._parse(string)
return parse["title"]

parser = Parser()

0 comments on commit 7f982b2

Please sign in to comment.