Пример #1
0
def check_nfos(srr_file):
    for block in RarReader(srr_file):
        nfo_count = 0
        if (block.rawtype == BlockType.SrrStoredFile
                and block.file_name[-4:].lower() == ".nfo"):
            nfo_count += 1
    return False if nfo_count <= 1 else True
Пример #2
0
def check_duplicates(srr_file):
    found = []
    for block in RarReader(srr_file):
        if (block.rawtype == BlockType.SrrStoredFile):
            if found.count(block.file_name):
                return True
            found.append(block.file_name)
    return False
Пример #3
0
def check_repack(srr_file):
    tmatch = ("rpk", "repack", "-r.part01.rar", "-r.rar")
    for block in RarReader(srr_file):
        if block.rawtype == BlockType.SrrRarFile:
            matchf = lambda keyword: keyword in block.file_name
            if any(map(matchf, tmatch)):
                return True
    return False
Пример #4
0
def check_image(srr_file, noproof):
    images = (".jpg", ".png", ".bmp", ".gif", "jpeg")
    for block in RarReader(srr_file):
        if (block.rawtype == BlockType.SrrStoredFile
                and os.path.splitext(block.file_name)[1] in images):
            if noproof and "proof" in block.file_name.lower():
                return False
            return True
    return False
Пример #5
0
def get_rar_date_name(file_name):
    if file_name.endswith((".exe", ".sfx")):
        for block in RarReader(file_name, enable_sfx=True):
            try:
                if block.file_name in ("Rar.exe", "Rar.Exe", "rar\\rar",
                                       "rar"):
                    t = block.file_datetime
                    return ("%d-%02d-%02d" % (t[0], t[1], t[2]),
                            block.os_file_name())
            except Exception:
                pass
    elif tarfile.is_tarfile(file_name):
        with closing(tarfile.open(file_name)) as tf:
            mtime = tf.getmember("rar/rar").mtime
            return (datetime.fromtimestamp(mtime).strftime("%Y-%m-%d"),
                    "rar/rar")
    return None, None
Пример #6
0
def fix(srr_file):
    print("Fixing %s" % srr_file)
    blocks = RarReader(srr_file).read_all()

    # directory for the fixed files
    fixeddir = os.path.join(os.path.dirname(srr_file), "fixed")
    try:
        os.makedirs(fixeddir)
    except:
        pass  # Path already exists

    # create a temporarily file
    tmpfd, tmpname = mkstemp(prefix="remove_", suffix=".srr", dir=fixeddir)
    tmpfile = os.fdopen(tmpfd, "wb")

    try:
        for block in blocks:
            if block.rawtype == BlockType.SrrHeader:
                #                tmpfile.write(block.bytes())
                tmpfile.write(
                    SrrHeaderBlock(appname="FireScene Cleanup").bytes())
            if block.rawtype == BlockType.SrrStoredFile:
                # insert block and data after the SRR header
                tmpfile.write(block.bytes())
                tmpfile.write(block.srr_data())
        for block in blocks:
            if block.rawtype != BlockType.SrrHeader and  \
                block.rawtype != BlockType.SrrStoredFile:
                # copy block and data
                tmpfile.write(block.bytes())
        tmpfile.close()
        # os.remove(srr_file)
        os.rename(tmpname, os.path.join(fixeddir, os.path.basename(srr_file)))
    except:
        os.unlink(tmpname)
        raise
Пример #7
0
def show_stored_files_flags(srr_file):
    blocks = RarReader(srr_file).read_all()

    for block in blocks:
        if block.rawtype == BlockType.SrrStoredFile:
            print(hex(block.flags))
Пример #8
0
def check_for_possible_nonscene(srr_file):
    for block in RarReader(srr_file):
        if (block.rawtype == BlockType.SrrRarFile
                and block.file_name != block.file_name.lower()):
            return True
    return False
Пример #9
0
def check_empty(srr_file):
    for block in RarReader(srr_file):
        if block.rawtype == BlockType.RarPackedFile:
            return False
    return True
Пример #10
0
def check_compression(srr_file):
    for block in RarReader(srr_file):
        if block.rawtype == BlockType.RarPackedFile:
            if block.compression_method != COMPR_STORING:
                return True
    return False
Пример #11
0
def check_for_ext(srr_file, extension):
    for block in RarReader(srr_file):
        if (block.rawtype == BlockType.SrrStoredFile
                and block.file_name.lower().endswith(extension)):
            return True
    return False
Пример #12
0
def check_availability_stored_files(srr_file):
    for block in RarReader(srr_file):
        if block.rawtype == BlockType.SrrStoredFile:
            return False
    return True