|
|
@ -65,7 +65,7 @@ from sabnzbd.filesystem import ( |
|
|
|
get_filename, |
|
|
|
) |
|
|
|
from sabnzbd.nzbstuff import NzbObject |
|
|
|
from sabnzbd.sorting import Sorter, is_sample, move_to_parent_directory |
|
|
|
from sabnzbd.sorting import Sorter, is_sample |
|
|
|
from sabnzbd.constants import ( |
|
|
|
REPAIR_PRIORITY, |
|
|
|
FORCE_PRIORITY, |
|
|
@ -80,7 +80,6 @@ import sabnzbd.emailer as emailer |
|
|
|
import sabnzbd.downloader |
|
|
|
import sabnzbd.config as config |
|
|
|
import sabnzbd.cfg as cfg |
|
|
|
import sabnzbd.encoding as encoding |
|
|
|
import sabnzbd.nzbqueue |
|
|
|
import sabnzbd.database as database |
|
|
|
import sabnzbd.notifier as notifier |
|
|
@ -317,6 +316,8 @@ def process_job(nzo: NzbObject): |
|
|
|
# Signal empty download, for when 'empty_postproc' is enabled |
|
|
|
empty = False |
|
|
|
nzb_list = [] |
|
|
|
one_folder = False |
|
|
|
newfiles = [] |
|
|
|
# These need to be initialized in case of a crash |
|
|
|
workdir_complete = "" |
|
|
|
script_log = "" |
|
|
@ -419,7 +420,6 @@ def process_job(nzo: NzbObject): |
|
|
|
nzo |
|
|
|
) |
|
|
|
|
|
|
|
newfiles = [] |
|
|
|
# Run Stage 2: Unpack |
|
|
|
if flag_unpack: |
|
|
|
# Set the current nzo status to "Extracting...". Used in History |
|
|
@ -480,6 +480,7 @@ def process_job(nzo: NzbObject): |
|
|
|
|
|
|
|
script_output = "" |
|
|
|
script_ret = 0 |
|
|
|
script_error = False |
|
|
|
if not nzb_list: |
|
|
|
# Give destination its final name |
|
|
|
if cfg.folder_rename() and tmp_workdir_complete and not one_folder: |
|
|
@ -513,52 +514,47 @@ def process_job(nzo: NzbObject): |
|
|
|
if newfiles: |
|
|
|
workdir_complete, ok = file_sorter.rename(newfiles, workdir_complete) |
|
|
|
if not ok: |
|
|
|
workdir_complete, ok = move_to_parent_directory(workdir_complete) |
|
|
|
nzo.set_unpack_info("Unpack", T("Failed to move files")) |
|
|
|
all_ok = False |
|
|
|
|
|
|
|
# Use par2 files to deobfuscate unpacked file names |
|
|
|
if cfg.process_unpacked_par2(): |
|
|
|
newfiles = deobfuscate.recover_par2_names(newfiles) |
|
|
|
|
|
|
|
if cfg.deobfuscate_final_filenames() and all_ok and not nzb_list: |
|
|
|
# Deobfuscate the filenames |
|
|
|
logging.info("Running deobfuscate") |
|
|
|
deobfuscate.deobfuscate_list(newfiles, nzo.final_name) |
|
|
|
|
|
|
|
# Run the user script |
|
|
|
script_path = make_script_path(script) |
|
|
|
if (all_ok or not cfg.safe_postproc()) and (not nzb_list) and script_path: |
|
|
|
# Set the current nzo status to "Ext Script...". Used in History |
|
|
|
nzo.status = Status.RUNNING |
|
|
|
nzo.set_action_line(T("Running script"), script) |
|
|
|
nzo.set_unpack_info("Script", T("Running user script %s") % script, unique=True) |
|
|
|
script_log, script_ret = external_processing( |
|
|
|
script_path, nzo, clip_path(workdir_complete), nzo.final_name, job_result |
|
|
|
) |
|
|
|
script_line = get_last_line(script_log) |
|
|
|
if script_log: |
|
|
|
script_output = nzo.nzo_id |
|
|
|
if script_line: |
|
|
|
nzo.set_unpack_info("Script", script_line, unique=True) |
|
|
|
else: |
|
|
|
nzo.set_unpack_info("Script", T("Ran %s") % script, unique=True) |
|
|
|
else: |
|
|
|
script = "" |
|
|
|
script_line = "" |
|
|
|
script_ret = 0 |
|
|
|
|
|
|
|
# Maybe bad script result should fail job |
|
|
|
if script_ret and cfg.script_can_fail(): |
|
|
|
script_error = True |
|
|
|
all_ok = False |
|
|
|
nzo.fail_msg = T("Script exit code is %s") % script_ret |
|
|
|
else: |
|
|
|
script_error = False |
|
|
|
# Run further post-processing |
|
|
|
if (all_ok or not cfg.safe_postproc()) and not nzb_list: |
|
|
|
# Use par2 files to deobfuscate unpacked file names |
|
|
|
if cfg.process_unpacked_par2(): |
|
|
|
newfiles = deobfuscate.recover_par2_names(newfiles) |
|
|
|
|
|
|
|
if cfg.deobfuscate_final_filenames(): |
|
|
|
# Deobfuscate the filenames |
|
|
|
logging.info("Running deobfuscate") |
|
|
|
deobfuscate.deobfuscate_list(newfiles, nzo.final_name) |
|
|
|
|
|
|
|
# Run the user script |
|
|
|
script_path = make_script_path(script) |
|
|
|
if script_path: |
|
|
|
# Set the current nzo status to "Ext Script...". Used in History |
|
|
|
nzo.status = Status.RUNNING |
|
|
|
nzo.set_action_line(T("Running script"), script) |
|
|
|
nzo.set_unpack_info("Script", T("Running user script %s") % script, unique=True) |
|
|
|
script_log, script_ret = external_processing( |
|
|
|
script_path, nzo, clip_path(workdir_complete), nzo.final_name, job_result |
|
|
|
) |
|
|
|
script_line = get_last_line(script_log) |
|
|
|
if script_log: |
|
|
|
script_output = nzo.nzo_id |
|
|
|
if script_line: |
|
|
|
nzo.set_unpack_info("Script", script_line, unique=True) |
|
|
|
else: |
|
|
|
nzo.set_unpack_info("Script", T("Ran %s") % script, unique=True) |
|
|
|
|
|
|
|
# Maybe bad script result should fail job |
|
|
|
if script_ret and cfg.script_can_fail(): |
|
|
|
script_error = True |
|
|
|
all_ok = False |
|
|
|
nzo.fail_msg = T("Script exit code is %s") % script_ret |
|
|
|
|
|
|
|
# Email the results |
|
|
|
if (not nzb_list) and cfg.email_endjob(): |
|
|
|
if (cfg.email_endjob() == 1) or (cfg.email_endjob() == 2 and (unpack_error or par_error or script_error)): |
|
|
|
if not nzb_list and cfg.email_endjob(): |
|
|
|
if cfg.email_endjob() == 1 or (cfg.email_endjob() == 2 and (unpack_error or par_error or script_error)): |
|
|
|
emailer.endjob( |
|
|
|
nzo.final_name, |
|
|
|
nzo.cat, |
|
|
@ -581,8 +577,7 @@ def process_job(nzo: NzbObject): |
|
|
|
if len(script_log.rstrip().split("\n")) > 1: |
|
|
|
nzo.set_unpack_info( |
|
|
|
"Script", |
|
|
|
'%s%s <a href="./scriptlog?name=%s">(%s)</a>' |
|
|
|
% (script_ret, script_line, encoding.xml_name(script_output), T("More")), |
|
|
|
'%s%s <a href="./scriptlog?name=%s">(%s)</a>' % (script_ret, script_line, script_output, T("More")), |
|
|
|
unique=True, |
|
|
|
) |
|
|
|
else: |
|
|
|