Beispiel #1
0
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")))
Beispiel #2
0
    def runTest(self):
        srr = os.path.join(
            os.path.dirname(__file__),
            os.pardir,
            os.pardir,
            "test_files",
            "bug_detected_as_being_different3",
            "Akte.2012.08.01.German.Doku.WS.dTV.XViD-FiXTv_f4n4t.srr",
        )
        srs = os.path.join("sample", "fixtv-akte.2012.08.01.sample.srs")
        ((srs, success), ) = rescene.extract_files(srr,
                                                   self.dir,
                                                   packed_name=srs)
        self.assertTrue(success)

        ftype = file_type_info(srs).file_type
        self.assertEqual(FileType.AVI, ftype)

        sample = sample_class_factory(ftype)
        srs_data, tracks = sample.load_srs(srs)

        self.assertEqual("MKV/AVI ReSample 1.2", srs_data.appname)
        self.assertEqual("fixtv-akte.2012.08.01.sample.avi", srs_data.name)
        self.assertEqual(4375502, srs_data.size)
        self.assertEqual(0xC7FB72A8, srs_data.crc32)

        self.assertEqual(3385806, tracks[0].data_length)
        self.assertFalse(tracks[0].match_offset)
        self.assertEqual(917376, tracks[1].data_length)
        self.assertFalse(tracks[1].match_offset)
Beispiel #3
0
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)
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
def manage_srr(options, in_folder, infiles, working_dir):
    out_folder = working_dir
    if options.output_dir:
        out_folder = options.output_dir
    save_paths = options.paths

    if options.list_info:  # -l
        # no messages. prevents mangled output in case there are any
        # e.g. new style comment block on
        # Friday.the.13th.Part.2.1981.720p.BluRay.x264-CULTHD
        mthread.set_messages([])
        display_info(infiles[0])
    elif options.list_details:  # -e
        mthread.set_messages([])
        rescene.print_details(infiles[0])
    elif options.verify:  # -q
        s = verify_extracted_files(infiles[0], in_folder, options.auto_locate)
        if s == 0:
            print("All files OK!")
        elif s == 10:
            print("No RAR meta data found: nothing to verify.")
        else:
            print("Corrupt and/or missing files!")
        return s
    elif options.extract:  # -x
        status = 0
        mthread.set_messages([])

        # append release name to the output path for all extracted files
        if options.parent:  # -d (additional usage for this option)
            srr = os.path.basename(infiles[0])
            out_folder = os.path.join(out_folder, os.path.splitext(srr)[0])

        # extract ALL possible files
        files = rescene.extract_files(infiles[0], out_folder, save_paths)

        # show which files are extracted + success or not
        for efile, success in files:
            file_name = efile[len(out_folder) + 1:]
            if success:
                print("{0}: extracted.".format(file_name))
            else:
                status = 1
                print("{0}: not extracted!".format(file_name), file=sys.stderr)
        return status
    elif options.extract_regex:
        status = 0  # no unexpected failures, good input
        mthread.set_messages([])

        try:
            to_extract = re.compile(options.extract_regex, re.IGNORECASE)
        except Exception as e:
            print("Unrecognized regular expression: %s" % e)
            print("Some examples:")
            print("\t.*\.nfo$")
            print("\t.*(nfo|sfv)$")
            print("\t^sample/.*")
            return 1

        # append release name to the output path for all extracted files
        if options.parent:  # -d (additional usage for this option)
            srr = os.path.basename(infiles[0])
            out_folder = os.path.join(out_folder, os.path.splitext(srr)[0])

        def decide_extraction(stored_fn):
            return to_extract.match(stored_fn)

        files = rescene.extract_files(infiles[0],
                                      out_folder,
                                      save_paths,
                                      matcher=decide_extraction)

        # show which files are extracted + success or not
        for efile, success in files:
            file_name = efile[len(out_folder) + 1:]
            if success:
                print("{0}: extracted.".format(file_name))
            else:
                status = 1
                print("{0}: not extracted!".format(file_name), file=sys.stderr)

        if not len(files):
            print("No matching files to extract.")

        return status

    elif options.store_files:  # -s
        mthread.set_messages([MsgCode.STORING])
        rescene.add_stored_files(infiles[0], options.store_files, in_folder,
                                 save_paths)
    else:
        # reconstruct (certain) volumes
        mthread.set_messages([
            MsgCode.FILE_NOT_FOUND, MsgCode.UNKNOWN, MsgCode.MSG,
            MsgCode.NO_OVERWRITE, MsgCode.USER_ABORTED, MsgCode.CRC
        ])
        hints = dict()
        if options.hints:
            for hint in options.hints.split(';'):
                try:
                    a, b = hint.split(':')
                    hints[a] = b
                except:
                    parser.exit(1, "Invalid hint (-H) value: %s" % hint)

        rar_mt = rescene.RarMtSettings()
        rar_mt.mt_set = options.mt_set
        rar_mt.mt_min = options.mt_min
        rar_mt.mt_max = options.mt_max

        try:
            rescene.reconstruct(infiles[0], in_folder, out_folder, save_paths,
                                hints, options.no_auto_crc,
                                options.auto_locate, options.fake,
                                options.rar_executable_dir, options.temp_dir,
                                options.volume is None, options.volume, rar_mt)
        except (FileNotFound, RarNotFound) as err:
            mthread.done = True
            mthread.join()
            print(err, file=sys.stderr)
            return 1
        except EmptyRepository:
            mthread.done = True
            mthread.join()
            sys.stderr.write("""\
=> Failure trying to reconstruct compressed RAR archives.
=> Use the -z switch to point to a directory with RAR executables.
=> Create this directory by using the preprardir.py script.
""")
            return 1