Browse Source

Only run recover_par2_names if all_ok

tags/3.4.0Beta2
Safihre 4 years ago
parent
commit
fc721f31c5
  1. 87
      sabnzbd/postproc.py

87
sabnzbd/postproc.py

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

Loading…
Cancel
Save