def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ assert isinstance(nzo, sabnzbd.nzbstuff.NzbObject) filename = nzo.final_name growler.send_notification(T('Post-processing'), nzo.final_name, 'pp') logging.info('Par2 check starting on %s', filename) ## Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False if repair_sets: for setname in repair_sets: if cfg.ignore_samples() > 0 and 'sample' in setname.lower(): continue if not verified.get(setname, False): logging.info("Running repair on set %s", setname) parfile_nzf = par_table[setname] if not os.path.exists( os.path.join(nzo.downpath, parfile_nzf.filename)): continue need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname) re_add = re_add or need_re_add if not res and not need_re_add and cfg.sfv_check(): res = try_sfv_check(nzo, workdir, setname) verified[setname] = res par_error = par_error or not res else: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check(): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Readded %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Par2 check finished on %s', filename) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ assert isinstance(nzo, sabnzbd.nzbstuff.NzbObject) filename = nzo.final_name growler.send_notification(T('Post-processing'), nzo.final_name, 'pp') logging.info('Par2 check starting on %s', filename) ## Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False single = len(repair_sets) == 1 if repair_sets: for setname in repair_sets: if cfg.ignore_samples() > 0 and 'sample' in setname.lower(): continue if not verified.get(setname, False): logging.info("Running repair on set %s", setname) parfile_nzf = par_table[setname] if os.path.exists(os.path.join(nzo.downpath, parfile_nzf.filename)) or parfile_nzf.extrapars: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) re_add = re_add or need_re_add if not res and not need_re_add and cfg.sfv_check(): res = try_sfv_check(nzo, workdir, setname) verified[setname] = res else: continue par_error = par_error or not res else: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check(): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Readded %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Par2 check finished on %s', filename) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name growler.send_notification(T('Post-processing'), nzo.final_name, 'pp') logging.info('Par2 check starting on %s', filename) ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False if repair_sets: for set_ in repair_sets: logging.info("Running repair on set %s", set_) parfile_nzf = par_table[set_] need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, set_) if need_re_add: re_add = True else: par_error = par_error or not res if re_add: logging.info('Readded %s to queue', filename) nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() logging.info('Par2 check finished on %s', filename) if (par_error and not re_add) or not repair_sets: # See if alternative SFV check is possible if cfg.sfv_check(): sfvs = globber(workdir, '*.sfv') else: sfvs = None if sfvs: par_error = False nzo.set_unpack_info('Repair', T('Trying SFV verification')) for sfv in sfvs: if not sfv_check(sfv): nzo.set_unpack_info('Repair', T('Some files failed to verify against "%s"') % unicoder(os.path.basename(sfv))) par_error = True if not par_error: nzo.set_unpack_info('Repair', T('Verified successfully using SFV files')) elif not repair_sets: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if not par_error: verified_flag_file(workdir, create=True) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name osx.sendGrowlMsg(T('Post-processing'), nzo.final_name, osx.NOTIFICATION['pp']) logging.info('Par2 check starting on %s', filename) ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False if repair_sets: for set_ in repair_sets: logging.info("Running repair on set %s", set_) parfile_nzf = par_table[set_] need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, set_) if need_re_add: re_add = True else: par_error = par_error or not res if re_add: logging.info('Readded %s to queue', filename) nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() logging.info('Par2 check finished on %s', filename) else: # See if alternative SFV check is possible sfv = None if cfg.sfv_check(): for sfv in globber(workdir, '*.sfv'): par_error = par_error or not sfv_check(sfv) if par_error: nzo.set_unpack_info( 'Repair', T('Some files failed to verify against "%s"') % unicoder(os.path.basename(sfv))) if not sfv: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name osx.sendGrowlMsg(T('Post-processing'), nzo.final_name, osx.NOTIFICATION['pp']) logging.info('Par2 check starting on %s', filename) ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False if repair_sets: for set_ in repair_sets: logging.info("Running repair on set %s", set_) parfile_nzf = par_table[set_] need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, set_) if need_re_add: re_add = True else: par_error = par_error or not res if re_add: logging.info('Readded %s to queue', filename) nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() logging.info('Par2 check finished on %s', filename) else: # See if alternative SFV check is possible sfv = None if cfg.sfv_check(): for sfv in globber(workdir, '*.sfv'): par_error = par_error or not sfv_check(sfv) if par_error: nzo.set_unpack_info('Repair', T('Some files failed to verify against "%s"') % unicoder(os.path.basename(sfv))) if not sfv: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ logging.info("Starting verification and repair of %s", nzo.final_name) par_error = False re_add = False # Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} # If all were verified successfully, we skip the rest of the checks if verified and all(verified.values()): logging.info("Skipping repair, all sets previously verified: %s", verified) return par_error, re_add if nzo.extrapars: # Need to make a copy because it can change during iteration single = len(nzo.extrapars) == 1 for setname in list(nzo.extrapars): if cfg.ignore_samples() and RE_SAMPLE.search(setname.lower()): continue # Skip sets that were already tried if not verified.get(setname, False): logging.info("Running verification and repair on set %s", setname) parfile_nzf = nzo.partable[setname] # Check if file maybe wasn't deleted and if we maybe have more files in the parset if os.path.exists( os.path.join( nzo.downpath, parfile_nzf.filename)) or nzo.extrapars[setname]: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) # Was it aborted? if not nzo.pp_active: re_add = False par_error = True break re_add = re_add or need_re_add verified[setname] = res else: continue par_error = par_error or not res elif not verified.get("", False): # No par2-sets found, skipped if already tried before logging.info("No par2 sets for %s", nzo.final_name) nzo.set_unpack_info("Repair", T("[%s] No par2 sets") % nzo.final_name) # Try SFV-based verification and rename sfv_check_result = None if cfg.sfv_check() and not verified.get("", False): sfv_check_result = try_sfv_check(nzo, workdir) par_error = sfv_check_result is False # If no luck with SFV, do RAR-check or RAR-rename if sfv_check_result is None and cfg.enable_unrar(): # Check for RAR's with a sensible extension _, _, rars, _, _ = build_filelists(workdir, check_rar=False) # If there's no RAR's, they might be super-obfuscated if not rars: # Returns number of renamed RAR's if rar_renamer(nzo, workdir): # Re-parse the files so we can do RAR-check _, _, rars, _, _ = build_filelists(workdir) if rars: par_error = not try_rar_check(nzo, rars) # Save that we already tried SFV/RAR-verification verified[""] = not par_error if re_add: logging.info("Re-added %s to queue", nzo.final_name) if nzo.priority != FORCE_PRIORITY: nzo.priority = REPAIR_PRIORITY nzo.status = Status.FETCHING sabnzbd.nzbqueue.NzbQueue.do.add(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info("Verification and repair finished for %s", nzo.final_name) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name notifier.send_notification(T('Post-processing'), filename, 'pp', nzo.cat) logging.info('Starting verification and repair of %s', filename) # Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} repair_sets = nzo.extrapars.keys() re_add = False par_error = False single = len(repair_sets) == 1 if repair_sets: for setname in repair_sets: if cfg.ignore_samples() and RE_SAMPLE.search(setname.lower()): continue if not verified.get(setname, False): logging.info("Running verification and repair on set %s", setname) parfile_nzf = nzo.partable[setname] # Check if file maybe wasn't deleted and if we maybe have more files in the parset if os.path.exists( os.path.join( nzo.downpath, parfile_nzf.filename)) or nzo.extrapars[setname]: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) # Was it aborted? if not nzo.pp_active: re_add = False par_error = True break re_add = re_add or need_re_add verified[setname] = res else: continue par_error = par_error or not res else: # We must not have found any par2.. logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check() and not verified.get('', False): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error # If still no success, do RAR-check if not par_error and cfg.enable_unrar(): par_error = not try_rar_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Re-added %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY nzo.status = Status.FETCHING sabnzbd.nzbqueue.NzbQueue.do.add(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Verification and repair finished for %s', filename) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name notifier.send_notification(T('Post-processing'), filename, 'pp', nzo.cat) logging.info('Starting verification and repair of %s', filename) # Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} repair_sets = nzo.extrapars.keys() re_add = False par_error = False single = len(repair_sets) == 1 if repair_sets: for setname in repair_sets: if cfg.ignore_samples() and RE_SAMPLE.search(setname.lower()): continue if not verified.get(setname, False): logging.info("Running verification and repair on set %s", setname) parfile_nzf = nzo.partable[setname] # Check if file maybe wasn't deleted and if we maybe have more files in the parset if os.path.exists(os.path.join(nzo.downpath, parfile_nzf.filename)) or nzo.extrapars[setname]: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) # Was it aborted? if not nzo.pp_active: re_add = False par_error = True break re_add = re_add or need_re_add verified[setname] = res else: continue par_error = par_error or not res else: # We must not have found any par2.. logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check() and not verified.get('', False): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error # If still no success, do RAR-check if not par_error and cfg.enable_unrar(): par_error = not try_rar_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Re-added %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY nzo.status = Status.FETCHING sabnzbd.nzbqueue.NzbQueue.do.add(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Verification and repair finished for %s', filename) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ assert isinstance(nzo, sabnzbd.nzbstuff.NzbObject) filename = nzo.final_name growler.send_notification(T('Post-processing'), nzo.final_name, 'pp') logging.info('Par2 check starting on %s', filename) ## Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False if repair_sets: for set_ in repair_sets: logging.info("Running repair on set %s", set_) parfile_nzf = par_table[set_] need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, set_) if need_re_add: re_add = True par_error = par_error or not res if re_add: logging.info('Readded %s to queue', filename) nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() logging.info('Par2 check finished on %s', filename) if (par_error and not re_add) or not repair_sets: # See if alternative SFV check is possible if cfg.sfv_check(): sfvs = globber(workdir, '*.sfv') else: sfvs = None if sfvs: par_error = False nzo.set_unpack_info('Repair', T('Trying SFV verification')) for sfv in sfvs: failed = sfv_check(sfv) if failed: msg = T('Some files failed to verify against "%s"' ) % unicoder(os.path.basename(sfv)) msg += '; ' msg += '; '.join(failed) nzo.set_unpack_info('Repair', msg) par_error = True if not par_error: nzo.set_unpack_info('Repair', T('Verified successfully using SFV files')) elif not repair_sets: logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if not par_error: flag_file(workdir, VERIFIED_FILE, create=True) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ if 0: assert isinstance( nzo, sabnzbd.nzbstuff.NzbObject) # Assert only for debug purposes filename = nzo.final_name notifier.send_notification(T('Post-processing'), filename, 'pp') logging.info('Starting verification and repair of %s', filename) # Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} # Collect the par files if nzo.partable: par_table = nzo.partable.copy() else: par_table = {} repair_sets = par_table.keys() re_add = False par_error = False single = len(repair_sets) == 1 if repair_sets: for setname in repair_sets: if cfg.ignore_samples() and 'sample' in setname.lower(): continue if not verified.get(setname, False): logging.info("Running verification and repair on set %s", setname) parfile_nzf = par_table[setname] if os.path.exists( os.path.join( nzo.downpath, parfile_nzf.filename)) or parfile_nzf.extrapars: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) # Was it aborted? if not nzo.pp_active: re_add = False par_error = True break re_add = re_add or need_re_add if not res and not need_re_add and cfg.sfv_check(): res = try_sfv_check(nzo, workdir, setname) if not res and not need_re_add and cfg.enable_unrar(): res = try_rar_check(nzo, workdir, setname) verified[setname] = res else: continue par_error = par_error or not res else: # Obfuscated par2 check logging.info('No par2 sets found, running obfuscated check on %s', filename) # Get the NZF's and sort them based on size nzfs_sorted = sorted(nzo.finished_files, key=lambda x: x.bytes) # We will have to make 'fake' par files that are recognized par2_vol = 0 par2_filename = None for nzf_try in nzfs_sorted: # run through list of files, looking for par2 signature.. logging.debug("Checking par2 signature of %s", nzf_try.filename) try: nzf_path = os.path.join(workdir, nzf_try.filename) if (is_parfile(nzf_path)): # We need 1 base-name so they are recognized as 1 set if not par2_filename: par2_filename = nzf_path # Rename so handle_par2() picks it up newpath = '%s.vol%d+%d.par2' % (par2_filename, par2_vol, par2_vol + 1) renamer(nzf_path, newpath) nzf_try.filename = os.path.split(newpath)[1] # Let the magic happen nzo.handle_par2(nzf_try, file_done=True) par2_vol += 1 except: pass if par2_vol > 0: # Pars found, we do it again par_error, re_add = parring(nzo, workdir) else: # We must not have found any par2.. logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check() and not verified.get('', False): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error # If still no success, do RAR-check if not par_error and cfg.enable_unrar(): par_error = not try_rar_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Re-added %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Verification and repair finished for %s', filename) return par_error, re_add
def parring(nzo, workdir): """ Perform par processing. Returns: (par_error, re_add) """ filename = nzo.final_name notifier.send_notification(T('Post-processing'), filename, 'pp') logging.info('Starting verification and repair of %s', filename) # Get verification status of sets verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {} repair_sets = nzo.partable.keys() re_add = False par_error = False single = len(repair_sets) == 1 if repair_sets: for setname in repair_sets: if cfg.ignore_samples() and RE_SAMPLE.search(setname.lower()): continue if not verified.get(setname, False): logging.info("Running verification and repair on set %s", setname) parfile_nzf = nzo.partable[setname] if os.path.exists(os.path.join(nzo.downpath, parfile_nzf.filename)) or parfile_nzf.extrapars: need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single) # Was it aborted? if not nzo.pp_active: re_add = False par_error = True break re_add = re_add or need_re_add verified[setname] = res else: continue par_error = par_error or not res else: # Obfuscated par2 check logging.info('No par2 sets found, running obfuscated check on %s', filename) # Get the NZF's and sort them based on size nzfs_sorted = sorted(nzo.finished_files, key=lambda x: x.bytes) # We will have to make 'fake' par files that are recognized par2_vol = 0 par2_filename = None for nzf_try in nzfs_sorted: # run through list of files, looking for par2 signature.. logging.debug("Checking par2 signature of %s", nzf_try.filename) try: nzf_path = os.path.join(workdir, nzf_try.filename) if(is_parfile(nzf_path)): # We need 1 base-name so they are recognized as 1 set if not par2_filename: par2_filename = nzf_path # Rename so handle_par2() picks it up newpath = '%s.vol%d+%d.par2' % (par2_filename, par2_vol, par2_vol + 1) renamer(nzf_path, newpath) nzf_try.filename = os.path.split(newpath)[1] # Let the magic happen nzo.handle_par2(nzf_try, file_done=True) par2_vol += 1 except: pass if par2_vol > 0: # Pars found, we do it again par_error, re_add = parring(nzo, workdir) else: # We must not have found any par2.. logging.info("No par2 sets for %s", filename) nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename)) if cfg.sfv_check() and not verified.get('', False): par_error = not try_sfv_check(nzo, workdir, '') verified[''] = not par_error # If still no success, do RAR-check if not par_error and cfg.enable_unrar(): par_error = not try_rar_check(nzo, workdir, '') verified[''] = not par_error if re_add: logging.info('Re-added %s to queue', filename) if nzo.priority != TOP_PRIORITY: nzo.priority = REPAIR_PRIORITY sabnzbd.nzbqueue.add_nzo(nzo) sabnzbd.downloader.Downloader.do.resume_from_postproc() sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath) logging.info('Verification and repair finished for %s', filename) return par_error, re_add