def repair_job(self, folder, new_nzb=None, password=None): """ Reconstruct admin for a single job folder, optionally with new NZB """ def all_verified(path): """ Return True when all sets have been successfully verified """ verified = sabnzbd.load_data(VERIFIED_FILE, path, remove=False) or {'x': False} return all(verified[x] for x in verified) name = os.path.basename(folder) path = os.path.join(folder, JOB_ADMIN) if hasattr(new_nzb, 'filename'): filename = new_nzb.filename else: filename = '' if not filename: if not all_verified(path): filename = globber_full(path, '*.gz') if len(filename) > 0: logging.debug('Repair job %s by reparsing stored NZB', name) nzo_id = sabnzbd.add_nzbfile(filename[0], pp=None, script=None, cat=None, priority=None, nzbname=name, reuse=True, password=password)[1] else: logging.debug('Repair job %s without stored NZB', name) nzo = NzbObject(name, pp=None, script=None, nzb='', cat=None, priority=None, nzbname=name, reuse=True) nzo.password = password self.add(nzo) nzo_id = nzo.nzo_id else: remove_all(path, '*.gz') logging.debug('Repair job %s with new NZB (%s)', name, filename) nzo_id = sabnzbd.add_nzbfile(new_nzb, pp=None, script=None, cat=None, priority=None, nzbname=name, reuse=True, password=password)[1] return nzo_id
def repair_job(self, folder, new_nzb=None, password=None): """ Reconstruct admin for a single job folder, optionally with new NZB """ def all_verified(path): """ Return True when all sets have been successfully verified """ verified = sabnzbd.load_data(VERIFIED_FILE, path, remove=False) or {'x': False} return all(verified[x] for x in verified) name = os.path.basename(folder) path = os.path.join(folder, JOB_ADMIN) if hasattr(new_nzb, 'filename'): filename = new_nzb.filename else: filename = '' if not filename: if not all_verified(path): filename = globber_full(path, '*.gz') if len(filename) > 0: logging.debug('Repair job %s by reparsing stored NZB', name) nzo_id = sabnzbd.add_nzbfile(filename[0], pp=None, script=None, cat=None, priority=None, nzbname=name, reuse=True, password=password)[1] else: logging.debug('Repair job %s without stored NZB', name) nzo = NzbObject(name, pp=None, script=None, nzb='', cat=None, priority=None, nzbname=name, reuse=True) nzo.password = password self.add(nzo) nzo_id = nzo.nzo_id else: remove_all(path, '*.gz') logging.debug('Repair job %s with new NZB (%s)', name, filename) nzo_id = sabnzbd.add_nzbfile(new_nzb, pp=None, script=None, cat=None, priority=None, nzbname=name, reuse=True, password=password)[1] return nzo_id
def repair_job(self, repair_folder, new_nzb=None, password=None): """ Reconstruct admin for a single job folder, optionally with new NZB """ # Check if folder exists if not repair_folder or not os.path.exists(repair_folder): return None name = os.path.basename(repair_folder) admin_path = os.path.join(repair_folder, JOB_ADMIN) # If Retry was used and a new NZB was uploaded if getattr(new_nzb, "filename", None): remove_all(admin_path, "*.gz", keep_folder=True) logging.debug("Repair job %s with new NZB (%s)", name, new_nzb.filename) _, nzo_ids = sabnzbd.add_nzbfile(new_nzb, nzbname=name, reuse=repair_folder, password=password) nzo_id = nzo_ids[0] else: # Was this file already post-processed? verified = sabnzbd.load_data(VERIFIED_FILE, admin_path, remove=False) filenames = [] if not verified or not all(verified[x] for x in verified): filenames = globber_full(admin_path, "*.gz") if filenames: logging.debug("Repair job %s by re-parsing stored NZB", name) _, nzo_ids = sabnzbd.add_nzbfile(filenames[0], nzbname=name, reuse=repair_folder, password=password) nzo_id = nzo_ids[0] else: logging.debug("Repair job %s without stored NZB", name) nzo = NzbObject(name, nzbname=name, reuse=repair_folder) nzo.password = password self.add(nzo) nzo_id = nzo.nzo_id return nzo_id
def check_encrypted_and_unwanted_files(nzo: NzbObject, filepath: str) -> Tuple[bool, Optional[str]]: """ Combines check for unwanted and encrypted files to save on CPU and IO """ encrypted = False unwanted = None if (cfg.unwanted_extensions() and cfg.action_on_unwanted_extensions()) or ( nzo.encrypted == 0 and cfg.pause_on_pwrar() ): # These checks should not break the assembler try: # Rarfile freezes on Windows special names, so don't try those! if sabnzbd.WIN32 and has_win_device(filepath): return encrypted, unwanted # Is it even a rarfile? if rarfile.is_rarfile(filepath): # Open the rar rarfile.UNRAR_TOOL = sabnzbd.newsunpack.RAR_COMMAND zf = rarfile.RarFile(filepath, single_file_check=True) # Check for encryption if ( nzo.encrypted == 0 and cfg.pause_on_pwrar() and (zf.needs_password() or is_cloaked(nzo, filepath, zf.namelist())) ): # Load all passwords passwords = get_all_passwords(nzo) # Cloaked job? if is_cloaked(nzo, filepath, zf.namelist()): encrypted = True elif not passwords: # Only error when no password was set nzo.encrypted = 1 encrypted = True else: # Lets test if any of the password work password_hit = False for password in passwords: if password: logging.info('Trying password "%s" on job "%s"', password, nzo.final_name) try: zf.setpassword(password) except rarfile.Error: # On weird passwords the setpassword() will fail # but the actual testrar() will work pass try: zf.testrar() password_hit = password break except rarfile.RarWrongPassword: # This one really didn't work pass except rarfile.RarCRCError as e: # CRC errors can be thrown for wrong password or # missing the next volume (with correct password) if "cannot find volume" in str(e).lower(): # We assume this one worked! password_hit = password break # This one didn't work pass except: # All the other errors we skip, they might be fixable in post-proc. # For example starting from the wrong volume, or damaged files # This will cause the check to be performed again for the next rar, might # be disk-intensive! Could be removed later and just accept the password. return encrypted, unwanted # Did any work? if password_hit: # We always trust the user's input if not nzo.password: nzo.password = password_hit # Don't check other files logging.info('Password "%s" matches for job "%s"', password_hit, nzo.final_name) nzo.encrypted = -1 encrypted = False else: # Encrypted and none of them worked nzo.encrypted = 1 encrypted = True # Check for unwanted extensions if cfg.unwanted_extensions() and cfg.action_on_unwanted_extensions(): for somefile in zf.namelist(): logging.debug("File contains: %s", somefile) if get_ext(somefile).replace(".", "").lower() in cfg.unwanted_extensions(): logging.debug("Unwanted file %s", somefile) unwanted = somefile zf.close() del zf except: logging.info("Error during inspection of RAR-file %s", filepath) logging.debug("Traceback: ", exc_info=True) return encrypted, unwanted