Skip to content

Commit

Permalink
fix problem when selecting jackett results from manual snatch list
Browse files Browse the repository at this point in the history
since torznab/jackett is newznab api, they were treated as newznab results so they used newznab settings for client.
this means users would have "black hole" set for newznab, the result would be downloaded to your blackhole (default: data dir)
the newznab download function would set the correct extension for it because the logic checks there if it was an nzb or torrent, and a .torrent file would be downloaded.
for users with neznab settings for a newznab client, SC would try to send the jackett result to nzbget/ds/sab and an error would occur

now, we check if it is newznab before sending and set the correct result type, so it uses the correct client configuration.

changed search_mode possible values from eponly/sponly to episode/season. readability is paramount
also fix some method and variable names to pep8 compliant names, and make code more readable.

Signed-off-by: miigotu <[email protected]>
  • Loading branch information
miigotu committed Oct 2, 2023
1 parent 0db899f commit 135602d
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 303 deletions.
12 changes: 6 additions & 6 deletions sickchill/gui/slick/views/config_providers.mako
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@
<div class="col-md-12">
<input type="radio" name="${curNewznabProvider.get_id("_search_mode")}"
id="${curNewznabProvider.get_id("_search_mode_sponly")}"
value="sponly" ${('', 'checked="checked"')[curNewznabProvider.search_mode=="sponly"]}/>
value="season" ${('', 'checked="checked"')[curNewznabProvider.search_mode=="season"]}/>
<label for="${curNewznabProvider.get_id("_search_mode_sponly")}">${_('season packs only.')}</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="radio" name="${curNewznabProvider.get_id("_search_mode")}"
id="${curNewznabProvider.get_id("_search_mode_eponly")}"
value="eponly" ${('', 'checked="checked"')[curNewznabProvider.search_mode=="eponly"]}/>
value="episode" ${('', 'checked="checked"')[curNewznabProvider.search_mode=="episode"]}/>
<label for="${curNewznabProvider.get_id("_search_mode_eponly")}">${_('episodes only.')}</label>
</div>
</div>
Expand Down Expand Up @@ -344,15 +344,15 @@
<div class="col-md-12">
<input type="radio" name="${curNzbProvider.get_id("_search_mode")}"
id="${curNzbProvider.get_id("_search_mode_sponly")}"
value="sponly" ${('', 'checked="checked"')[curNzbProvider.search_mode=="sponly"]}/>
value="season" ${('', 'checked="checked"')[curNzbProvider.search_mode=="season"]}/>
<label for="${curNzbProvider.get_id("_search_mode_sponly")}">season packs only.</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="radio" name="${curNzbProvider.get_id("_search_mode")}"
id="${curNzbProvider.get_id("_search_mode_eponly")}"
value="eponly" ${('', 'checked="checked"')[curNzbProvider.search_mode=="eponly"]}/>
value="episode" ${('', 'checked="checked"')[curNzbProvider.search_mode=="episode"]}/>
<label for="${curNzbProvider.get_id("_search_mode_eponly")}">episodes only.</label>
</div>
</div>
Expand Down Expand Up @@ -704,15 +704,15 @@
<div class="col-md-12">
<input type="radio" name="${curTorrentProvider.get_id("_search_mode")}"
id="${curTorrentProvider.get_id("_search_mode_sponly")}"
value="sponly" ${('', 'checked="checked"')[curTorrentProvider.search_mode=="sponly"]}/>
value="season" ${('', 'checked="checked"')[curTorrentProvider.search_mode=="season"]}/>
<label for="${curTorrentProvider.get_id("_search_mode_sponly")}">season packs only.</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="radio" name="${curTorrentProvider.get_id("_search_mode")}"
id="${curTorrentProvider.get_id("_search_mode_eponly")}"
value="eponly" ${('', 'checked="checked"')[curTorrentProvider.search_mode=="eponly"]}/>
value="episode" ${('', 'checked="checked"')[curTorrentProvider.search_mode=="episode"]}/>
<label for="${curTorrentProvider.get_id("_search_mode_eponly")}">episodes only.</label>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions sickchill/oldbeard/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, episodes):
# content
self.content = None

self.resultType = ""
self.result_type = ""

self.priority = 0

Expand Down Expand Up @@ -103,7 +103,7 @@ class NZBSearchResult(SearchResult):

def __init__(self, episodes):
super().__init__(episodes)
self.resultType = "nzb"
self.result_type = "nzb"


class NZBDataSearchResult(SearchResult):
Expand All @@ -113,7 +113,7 @@ class NZBDataSearchResult(SearchResult):

def __init__(self, episodes):
super().__init__(episodes)
self.resultType = "nzbdata"
self.result_type = "nzbdata"


class TorrentSearchResult(SearchResult):
Expand All @@ -123,7 +123,7 @@ class TorrentSearchResult(SearchResult):

def __init__(self, episodes):
super().__init__(episodes)
self.resultType = "torrent"
self.result_type = "torrent"


class Proper(object):
Expand Down
18 changes: 9 additions & 9 deletions sickchill/oldbeard/clients/download_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ def _get_destination(self, result):
"""
Determines which destination setting to use depending on result type
"""
if result.resultType in (GenericProvider.NZB, GenericProvider.NZBDATA):
if result.result_type in (GenericProvider.NZB, GenericProvider.NZBDATA):
destination = settings.SYNOLOGY_DSM_PATH.strip()
elif result.resultType == GenericProvider.TORRENT:
elif result.result_type == GenericProvider.TORRENT:
destination = settings.TORRENT_PATH.strip()
else:
raise AttributeError("Invalid result passed to client when getting destination: resultType {}".format(result.resultType))
raise AttributeError("Invalid result passed to client when getting destination: result_type {}".format(result.result_type))

return re.sub(r"^/volume\d/", "", destination).lstrip("/")

Expand All @@ -137,9 +137,9 @@ def _set_destination(self, result, destination):
params: :destination: DSM share name
"""
destination = destination.strip()
if result.resultType in (GenericProvider.NZB, GenericProvider.NZBDATA):
if result.result_type in (GenericProvider.NZB, GenericProvider.NZBDATA):
settings.SYNOLOGY_DSM_PATH = destination
elif result.resultType == GenericProvider.TORRENT:
elif result.result_type == GenericProvider.TORRENT:
settings.TORRENT_PATH = destination
else:
raise AttributeError("Invalid result passed to client when setting destination")
Expand All @@ -163,7 +163,7 @@ def _check_destination(self, result):
logger.info("Destination set to %s", self._get_destination(result))
except (ValueError, KeyError, JSONDecodeError) as error:
logger.debug("Get DownloadStation default destination error: {0}".format(error))
logger.warning("Could not get share destination from DownloadStation for {}, please set it in the settings", result.resultType)
logger.warning("Could not get share destination from DownloadStation for {}, please set it in the settings", result.result_type)
raise

def _add_torrent_uri(self, result):
Expand Down Expand Up @@ -197,7 +197,7 @@ def _add_torrent_file(self, result):

data = self._task_post_data

result_type = result.resultType.replace("data", "")
result_type = result.result_type.replace("data", "")
files = {result_type: (".".join([result.name, result_type]), result.content)}

data["type"] = '"file"'
Expand All @@ -220,7 +220,7 @@ def sendNZB(self, result):
logger.warning("{0}: Authentication Failed".format(self.name))
return False

if result.resultType == "nzb":
if result.result_type == "nzb":
return self._add_torrent_uri(result)
elif result.resultType == "nzbdata":
elif result.result_type == "nzbdata":
return self._add_torrent_file(result)
10 changes: 5 additions & 5 deletions sickchill/oldbeard/notifiers/emailnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def notify_snatch(self, ep_name, title="Snatched:"):
title: The title of the notification (optional)
"""
if settings.USE_EMAIL and settings.EMAIL_NOTIFY_ONSNATCH:
show = self._parseEp(ep_name)
show = self.parse_episode(ep_name)
to = self._generate_recipients(show)
if not to:
logger.debug("Skipping email notify because there are no configured recipients")
Expand Down Expand Up @@ -86,7 +86,7 @@ def notify_download(self, ep_name, title="Completed:"):
title: The title of the notification (optional)
"""
if settings.USE_EMAIL and settings.EMAIL_NOTIFY_ONDOWNLOAD:
show = self._parseEp(ep_name)
show = self.parse_episode(ep_name)
to = self._generate_recipients(show)
if not to:
logger.debug("Skipping email notify because there are no configured recipients")
Expand Down Expand Up @@ -140,7 +140,7 @@ def notify_postprocess(self, ep_name, title="Postprocessed:"):
title: The title of the notification (optional)
"""
if settings.USE_EMAIL and settings.EMAIL_NOTIFY_ONPOSTPROCESS:
show = self._parseEp(ep_name)
show = self.parse_episode(ep_name)
to = self._generate_recipients(show)
if not to:
logger.debug("Skipping email notify because there are no configured recipients")
Expand Down Expand Up @@ -194,7 +194,7 @@ def notify_subtitle_download(self, ep_name, lang, title="Downloaded subtitle:"):
lang: Subtitle language wanted
"""
if settings.USE_EMAIL and settings.EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD:
show = self._parseEp(ep_name)
show = self.parse_episode(ep_name)
to = self._generate_recipients(show)
if not to:
logger.debug("Skipping email notify because there are no configured recipients")
Expand Down Expand Up @@ -386,7 +386,7 @@ def _sendmail(self, host, port, smtp_from, use_tls, user, pwd, to, msg, smtpDebu
return False

@staticmethod
def _parseEp(ep_name):
def parse_episode(ep_name):
sep = " - "
titles = ep_name.split(sep)
logger.debug("TITLES: {0}".format(titles))
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/nzbget.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sendNZB(nzb, proper=False):
dupescore += 10

nzbcontent64 = None
if nzb.resultType == "nzbdata":
if nzb.result_type == "nzbdata":
data = nzb.extraInfo[0]
nzbcontent64 = standard_b64encode(data)

Expand All @@ -88,7 +88,7 @@ def sendNZB(nzb, proper=False):
if nzbcontent64:
nzbget_result = nzbGetRPC.append(nzb.name + ".nzb", category, addToTop, nzbcontent64)
else:
if nzb.resultType == "nzb":
if nzb.result_type == "nzb":
if not nzb.provider.login():
return False

Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ def process(self):
# If any notification fails, don't stop postProcessor
try:
# send notifications
notifiers.notify_download(episode_object._format_pattern("%SN - %Sx%0E - %EN - %QN"))
notifiers.notify_download(episode_object.format_pattern("%SN - %Sx%0E - %EN - %QN"))

# do the library update for KODI
notifiers.kodi_notifier.update_library(episode_object.show.name)
Expand Down
6 changes: 3 additions & 3 deletions sickchill/oldbeard/properFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import db, helpers
from .common import cpu_presets, DOWNLOADED, Quality, SNATCHED, SNATCHED_PROPER
from .name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from .search import pickBestResult, snatchEpisode
from .search import pick_best_result, snatch_episode


class ProperFinder(object):
Expand Down Expand Up @@ -127,7 +127,7 @@ def _getProperList(self):
curProper.content = None

# filter release
bestResult = pickBestResult(curProper, parse_result.show)
bestResult = pick_best_result(curProper, parse_result.show)
if not bestResult:
logger.debug("Proper " + curProper.name + " were rejected by our release filters.")
continue
Expand Down Expand Up @@ -234,7 +234,7 @@ def _downloadPropers(self, properList):
result.content = curProper.content

# snatch it
snatchEpisode(result, SNATCHED_PROPER)
snatch_episode(result, SNATCHED_PROPER)
time.sleep(cpu_presets[settings.CPU_PRESET])

@staticmethod
Expand Down
19 changes: 12 additions & 7 deletions sickchill/oldbeard/providers/newznab.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NewznabProvider(NZBProvider, tvcache.RSSTorrentMixin):
Tested with: newznab, nzedb, spotweb, torznab
"""

def __init__(self, name, url, key="0", catIDs="5030,5040", search_mode="eponly", search_fallback=False, enable_daily=True, enable_backlog=False):
def __init__(self, name, url, key="0", catIDs="5030,5040", search_mode="episode", search_fallback=False, enable_daily=True, enable_backlog=False):
super().__init__(name)

self.url = url
Expand Down Expand Up @@ -177,11 +177,11 @@ def get_newznab_categories(self, just_caps=False):
def _get_default_providers():
# name|url|key|catIDs|enabled|search_mode|search_fallback|enable_daily|enable_backlog
return (
"NZB.Cat|https://nzb.cat/||5030,5040,5010|0|eponly|1|1|1!!!"
+ "NZBFinder.ws|https://nzbfinder.ws/||5030,5040,5010,5045|0|eponly|1|1|1!!!"
+ "NZBGeek|https://api.nzbgeek.info/||5030,5040|0|eponly|0|0|0!!!"
+ "Usenet-Crawler|https://www.usenet-crawler.com/||5030,5040|0|eponly|0|0|0!!!"
+ "DOGnzb|https://api.dognzb.cr/||5030,5040,5060,5070|0|eponly|0|1|1"
"NZB.Cat|https://nzb.cat/||5030,5040,5010|0|episode|1|1|1!!!"
+ "NZBFinder.ws|https://nzbfinder.ws/||5030,5040,5010,5045|0|episode|1|1|1!!!"
+ "NZBGeek|https://api.nzbgeek.info/||5030,5040|0|episode|0|0|0!!!"
+ "Usenet-Crawler|https://www.usenet-crawler.com/||5030,5040|0|episode|0|0|0!!!"
+ "DOGnzb|https://api.dognzb.cr/||5030,5040,5060,5070|0|episode|0|1|1"
)

def _check_auth(self):
Expand Down Expand Up @@ -222,7 +222,7 @@ def _make_provider(config):
enable_backlog = 0
enable_daily = 0
search_fallback = 0
search_mode = "eponly"
search_mode = "episode"

try:
values = config.split("|")
Expand All @@ -239,6 +239,11 @@ def _make_provider(config):
logger.exception("Skipping Newznab provider string: '{0}', incorrect format".format(config))
return None

if search_mode == "sponly":
search_mode = "season"
elif search_mode == "eponly":
search_mode = "episode"

new_provider = NewznabProvider(
name,
url,
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/providers/rsstorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class TorrentRssProvider(TorrentProvider):
def __init__(self, name, url, cookies="", titleTAG="title", search_mode="eponly", search_fallback=False, enable_daily=False, enable_backlog=False):
def __init__(self, name, url, cookies="", titleTAG="title", search_mode="episode", search_fallback=False, enable_daily=False, enable_backlog=False):
super().__init__(name)

self.cache = TorrentRssCache(self, min_time=15)
Expand Down Expand Up @@ -85,7 +85,7 @@ def _make_provider(config):
enable_backlog = 0
enable_daily = 0
search_fallback = 0
search_mode = "eponly"
search_mode = "episode"
title_tag = "title"

try:
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/sab.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def sendNZB(nzb): # pylint:disable=too-many-return-statements, too-many-branche
logger.info("Sending NZB to SABnzbd")
url = urljoin(settings.SAB_HOST, "api")

if nzb.resultType == "nzb":
if nzb.result_type == "nzb":
params["mode"] = "addurl"
params["name"] = nzb.url
jdata = helpers.getURL(url, params=params, session=session, returns="json", verify=False)
elif nzb.resultType == "nzbdata":
elif nzb.result_type == "nzbdata":
params["mode"] = "addfile"
multiPartParams = {"nzbfile": (nzb.name + ".nzb", nzb.extraInfo[0])}
jdata = helpers.getURL(url, params=params, files=multiPartParams, session=session, returns="json", verify=False)
Expand Down
Loading

0 comments on commit 135602d

Please sign in to comment.