Skip to content

Commit

Permalink
Merge legacy sab parsing with 0.7.17+
Browse files Browse the repository at this point in the history
  • Loading branch information
labrys committed Nov 29, 2022
1 parent 528cbd0 commit 637020d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 48 deletions.
4 changes: 0 additions & 4 deletions core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
NZB_CLIENTS = ['sabnzbd', 'nzbget', 'manual']
TORRENT_CLIENTS = ['transmission', 'deluge', 'utorrent', 'rtorrent', 'qbittorrent', 'other', 'manual']

# sabnzbd constants
SABNZB_NO_OF_ARGUMENTS = 8
SABNZB_0717_NO_OF_ARGUMENTS = 9

# sickbeard fork/branch constants
FORK_DEFAULT = 'default'
FORK_FAILED = 'failed'
Expand Down
62 changes: 23 additions & 39 deletions core/processor/sab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from core import logger
from core.processor import nzb

# Constants
MINIMUM_ARGUMENTS = 8


def process_script():
client_agent = 'sabnzbd'
Expand All @@ -19,49 +22,30 @@ def process_script():
)


def process_legacy(args):
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# 3 Clean version of the job name (no path info and '.nzb' removed)
# 4 Indexer's report number (if supported)
# 5 User-defined category
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing.
# 0 = OK
# 1 = failed verification
# 2 = failed unpack
# 3 = 1+2
client_agent = 'sabnzbd'
logger.info('Script triggered from SABnzbd')
def process(args):
"""
SABnzbd arguments:
1. The final directory of the job (full path)
2. The original name of the NZB file
3. Clean version of the job name (no path info and '.nzb' removed)
4. Indexer's report number (if supported)
5. User-defined category
6. Group that the NZB was posted in e.g. alt.binaries.x
7. Status of post processing:
0 = OK
1 = failed verification
2 = failed unpack
3 = 1+2
8. Failure URL
"""
version = '0.7.17+' if len(args) > MINIMUM_ARGUMENTS else ''
logger.info('Script triggered from SABnzbd {}'.format(version))
return nzb.process(
args[1],
input_directory=args[1],
input_name=args[2],
status=int(args[7]),
input_category=args[5],
client_agent=client_agent,
download_id='',
)


def process_0717(args):
# SABnzbd argv:
# 1 The final directory of the job (full path)
# 2 The original name of the NZB file
# 3 Clean version of the job name (no path info and '.nzb' removed)
# 4 Indexer's report number (if supported)
# 5 User-defined category
# 6 Group that the NZB was posted in e.g. alt.binaries.x
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
# 8 Failure URL
client_agent = 'sabnzbd'
logger.info('Script triggered from SABnzbd 0.7.17+')
return nzb.process(
args[1],
input_name=args[2],
status=int(args[7]),
input_category=args[5],
client_agent=client_agent,
client_agent='sabnzbd',
download_id='',
failure_link=''.join(args[8:]),
)
7 changes: 2 additions & 5 deletions nzbToMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,8 @@ def main(args, section=None):
elif 'SAB_SCRIPT' in os.environ:
result = sab.process_script()
# SABnzbd Pre 0.7.17
elif len(args) == core.SABNZB_NO_OF_ARGUMENTS:
result = sab.process_legacy(args)
# SABnzbd 0.7.17+
elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS:
result = sab.process_0717(args)
elif len(args) >= sab.MINIMUM_ARGUMENTS:
result = sab.process(args)
# Generic program
elif len(args) > 5 and args[5] == 'generic':
logger.info('Script triggered from generic program')
Expand Down

0 comments on commit 637020d

Please sign in to comment.