def filelist(self): srrinfo = rescene.info(self.filename) srrlist = [] if len(srrinfo['stored_files']) > 0: srrlist.append(list(srrinfo['stored_files'])) else: srrlist.append(None) if len(srrinfo['rar_files']) > 0: srrlist.append([]) for k, v in (srrinfo['rar_files']).items(): srrlist[1].append(v.file_name) else: srrlist.append(None) if srrlist[1] is not None: srrlist.append([]) for f in srrlist[1]: srrlist[2].append(f.split('/')[-1]) else: srrlist.append(None) if srrlist[2] is not None: srrlist[2] = list(set(srrlist[2])) else: srrlist.append(None) if len(srrinfo['archived_files']) > 0: srrlist.append(list(srrinfo['archived_files'])) else: srrlist.append(None) return srrlist
def filelist(self): srrinfo = rescene.info(self.filename) srrlist = [] if len(srrinfo['stored_files']) > 0: srrlist.append(list(srrinfo['stored_files'])) else: srrlist.append(None) if len(srrinfo['rar_files']) > 0: srrlist.append([]) for k, v in (srrinfo['rar_files']).items(): srrlist[1].append(v.file_name) else: srrlist.append(None) if srrlist[1] is not None: srrlist.append([]) for f in srrlist[1]: srrlist[2].append(f.split('/')[-1]) else: srrlist.append(None) if srrlist[2] is not None: srrlist[2] = list(set(srrlist[2])) else: srrlist.append(None) if len(srrinfo['archived_files']) > 0: srrlist.append(list(srrinfo['archived_files'])) else: srrlist.append(None) return srrlist
def get_archived_crc_by_fname(self, fname): matches = [] for key, value in info(self.filename)['archived_files'].items(): if fname == key: matches.append(value) return matches
def get_archived_fname_by_crc(self, crc): matches = [] for _, value in info(self.filename)['archived_files'].items(): if crc == value.crc32.zfill(8): matches.append(value) return matches
def fix_tracks(srr_file, input_dir, output_dir, always_yes=False): if not srr_file.endswith(".srr"): raise AttributeError("The first parameter must be an SRR file.") if not os.path.isdir(input_dir): raise AttributeError("The input location must be a directory.") if not os.path.isdir(output_dir): try: os.makedirs(output_dir) except: pass if not os.path.isdir(output_dir): raise AttributeError("Could not create output location.") stored_files = rescene.info(srr_file)['stored_files'] # extract non SRS files successes = 0 failures = 0 skips = 0 srs_files = [] for sfile in stored_files.keys(): if sfile.endswith(".srs"): srs_files.append(sfile) else: print("Extracting %s" % sfile) rescene.extract_files(srr_file, output_dir, True, sfile) # fix music files that can be found for srs in srs_files: print("Using %s" % srs) (out, ok) = rescene.extract_files(srr_file, output_dir, True, srs)[0] if not ok: # file extraction failed or existing .srs not overwritten print("Attempt to fix track aborted.") continue try: success = fix_tagging(out, output_dir, input_dir, always_yes) if success: successes += 1 else: # .srs is not a music file skips += 1 except ValueError: # pexit() srs.py only throws ValueError failures += 1 except Exception as e: print("Unexpected error!") print(str(e)) failures += 1 finally: os.remove(out) print("\n\n%d/%d files succeeded. %d failure%s. %s" % (successes, failures + successes, failures, "" if failures == 1 else "s", "" if not skips else "%s skip%s." % (skips, "" if skips == 1 else "s")))
def get_srs(self, path): if not os.path.isdir(path): raise AttributeError("path must be a valid directory") matches = [] for sfile in info(self.filename)['stored_files'].keys(): if sfile.endswith(".srs"): result = extract_files(self.filename, path, extract_paths=True, packed_name=sfile) matches += result return matches
def verify_extracted_files(srr, in_folder, auto_locate): """return codes: 0: everything verified successfully 1: corrupt file detected 2: the file was not found 10: it was a music release; nothing to verify """ status = 0 archived_files = rescene.info(srr)["archived_files"].values() if len(archived_files) == 0: status = 10 # it's a music release for afile in archived_files: # skip the directories and empty files if afile.crc32 != "00000000" and afile.crc32 != "0": name = os.path.join(in_folder, afile.file_name) if not os.path.exists(name): if not auto_locate: print("File %s not found. Skipping." % afile.file_name) status = 2 else: # look for possible renames same_size_list = [] for root, _dirnames, filenames in os.walk(in_folder): for fn in fnmatch.filter( filenames, "*" + os.path.splitext(name)[1]): f = os.path.join(root, fn) if os.path.getsize(f) == afile.file_size: same_size_list.append(f) # TODO: see if we can use OSO hash here to speed things up # it happens that multiple episodes have the same size found = False for f in same_size_list: crc = calculate_crc32(f) if afile.crc32 == "%0.8X" % crc: found = True print("File OK: %s matches %s." % (f, afile.file_name)) break else: print("%s does not match." % f) if not found: print("File %s not found. Skipping." % name) status = 2 else: crc = calculate_crc32(name) if afile.crc32 == "%0.8X" % crc: print("File OK: %s." % afile.file_name) else: print("File CORRUPT: %s!" % afile.file_name) status = 1 return status
def display_info(srr_file): """Print out different sections with SRR info.""" info = rescene.info(srr_file) print("Creating Application:") if info["appname"] == "": info["appname"] = "Unknown" print("\t%s\n" % info["appname"]) if info["compression"]: print("SRR for compressed RARs.\n") if len(info["stored_files"]): print("Stored files:") for sfile in info["stored_files"].values(): print("\t{0: >9} {1}".format( sep(sfile.file_size), encodeerrors(sfile.file_name, sys.stdout))) print() if len(info["rar_files"]): print("RAR files:") for sfile in info["rar_files"].values(): try: print("\t%s %s %d" % (sfile.file_name, sfile.crc32, sfile.file_size)) except AttributeError: # No SFV file is used print("\t%s %d" % (encodeerrors(sfile.file_name, sys.stdout), sfile.file_size)) print() if len(info["archived_files"]): print("Archived files:") for sfile in info["archived_files"].values(): print("\t%s %s %d" % (encodeerrors( sfile.file_name, sys.stdout), sfile.crc32, sfile.file_size)) print() if len(info["oso_hashes"]): print("ISDb hashes:") for (name, ohash, size) in info["oso_hashes"]: print("\t%s %s %d" % (encodeerrors(name, sys.stdout), ohash, size)) print() if len(info["sfv_comments"]): print("SFV comments:") for sfvline in info["sfv_comments"]: print("\t%s" % encodeerrors(sfvline, sys.stdout)) print()
def extract_stored_files_regex(self, path, regex=".*"): if not os.path.isdir(path): raise AttributeError("path must be a valid directory") matches = [] for key in info(self.filename)["stored_files"].keys(): if re.search(regex, key): result = extract_files(self.filename, path, extract_paths=True, packed_name=key) matches += result return matches
def main(options, args): for lfile in os.listdir(args[0]): if not lfile.endswith(".srr"): continue srr = info(lfile) has_nfo = False for sfile in srr['stored_files']: if sfile.endswith(".nfo"): has_nfo = True if not options.nonfo: has_nfo = False # for each stored lfile: max 3 comment lines if (len(srr['sfv_comments']) > 3 * len(srr['archived_files']) and not has_nfo): print(lfile)
def main(options, args): if len(args) < 2: raise AttributeError("Not enough parameters.") srr = args[0] output_folder = args[1] if not srr.endswith(".srr"): raise AttributeError("The first parameter must be an SRR file.") if not os.path.isdir(output_folder): raise AttributeError("The second attribute must be a directory.") srs_files = [] for sfile in rescene.info(srr)["stored_files"].keys(): if sfile.endswith(".srs"): srs_files.append(sfile) for srs in srs_files: print(srs) rescene.extract_files(srr, output_folder, extract_paths=True, packed_name=srs)
import rescene import os import glob dir = "D:/srrdb.com_2011-10-27/new/" for file in glob.glob(dir + "*.srr"): print("Reading %s" % file) try: rescene.info(os.path.join(dir, file)) except EnvironmentError as e: print(e) os.rename(os.path.join(dir, file), os.path.join(dir, "incomplete", file)) # except: # pass
def check(srr_file): try: result = False if options.verify or options.multiple: info = rescene.info(srr_file) global rar_sizes rar_sizes += sum( [info['rar_files'][f].file_size for f in info['rar_files']]) if options.multiple: sets = [] for f in info["rar_files"]: ms = "^(.*?)(.part\d+.rar|(.[rstuv]\d\d|.rar))$" base = re.match(ms, f, re.IGNORECASE).group(1) if not base in sets: sets.append(base) result |= len(info["archived_files"]) > len(sets) # print(sets) # useful to check ordering if options.dirfix: if "dirfix" in srr_file.lower() or "nfofix" in srr_file.lower(): print(srr_file) if options.lowercase: group = srr_file[:-4].rsplit("-")[-1] if group == group.lower(): result |= True if "." in group: # does not have a group name result |= True fn = os.path.split(srr_file)[1] if fn == fn.lower(): result |= True if options.compressed: result |= check_compression(srr_file) if options.empty: result |= check_empty(srr_file) if options.image or options.noproof: result |= check_image(srr_file, options.noproof) if options.repack: result |= check_repack(srr_file) if options.nfos: result |= check_nfos(srr_file) if options.duplicates: result |= check_duplicates(srr_file) if options.peer2peer: result |= check_for_possible_nonscene(srr_file) if options.nofiles: result |= check_availability_stored_files(srr_file) if options.nosfv: result |= check_for_no_ext(srr_file, ".sfv") if options.nonfo: result |= check_for_no_ext(srr_file, ".nfo") if options.txt: result |= check_for_ext(srr_file, ".txt") if result and options.output_dir: print("Moving %s." % srr_file) srr_name = os.path.basename(srr_file) # move the SRR to the given directory os.renames(srr_file, os.path.join(options.output_dir, srr_name)) if result: print(os.path.basename(srr_file)) except (EnvironmentError, Exception) as err: # the storing of a srr_file failed -> corrupt SRR print("Something wrong with reading %s" % srr_file) print(err)
# Deletes a lot of badly named nfo files import rescene srr = "Beauty.and.the.Beast.2012.S01E02.720p.HDTV.x264-IMMERSE.srr" good = "beauty.and.the.beast.2012.s01e02.720p.hdtv.x264-immerse.nfo" i = rescene.info(srr) i["stored_files"].pop(good) for sfile in list(i["stored_files"].keys()): if not sfile.endswith(".nfo"): i["stored_files"].pop(sfile) rescene.remove_stored_files(srr, i["stored_files"]) print("Done!")
def list_srr(sfile): for stored_file in info(sfile)['stored_files']: if stored_file[-4:] == ".srs": # print out the release name print(os.path.basename(sfile)[:-4])
import rescene import os folder = "D:/srrdb/bbachive_srrs/srrs0d-150d/iffy/good" for srr_file in os.listdir(folder): srrf = os.path.join(folder, srr_file) sf = rescene.info(srrf)['stored_files'] for sfile in sf: if sf[sfile].file_size == 592451 and sf[sfile].file_name.endswith( ".png"): print(sf[sfile].file_name) rescene.remove_stored_files(srrf, sf[sfile].file_name) break
def list_srr(sfile): for key, value in info(sfile)['archived_files'].items(): # print(os.path.basename(sfile)[:-4]), print("%s\t%s" % (key, value.crc32))