Ejemplo n.º 1
0
                f"{common.COLOR_WHITE}[+] Extracting track {sub_stream.id} from {common.COLOR_YELLOW}{infile} with {common.COLOR_PURPLE}{cmd}{common.COLOR_WHITE}"
            )
            os.system(cmd)
        p_queue.task_done()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input",
                        type=Path,
                        help="Path to directory or single video file")
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        action="store_true",
                        help="Verbose mode")
    args = parser.parse_args()
    LOGGER = logger.Logger(args.verbose)

    # Sanity checks
    common.ensure_exist(["ffmpeg"])
    if args.input.exists() is None:
        common.abort(parser.format_help())

    # Get a list of files
    files = common.list_directory(args.input.resolve())
    queue = common.as_queue(files)

    # Extract
    common.parallel(extract_subtitles, (queue, ))
    color_count = q_color_conv.qsize()
    print(f"{common.COLOR_GREEN} ↳ Done in {t_end - t_start:4.2f}s :")
    print(
        f"{common.COLOR_PURPLE}\t→ {grey_count} grayscaled file(s) need to be converted"
    )
    print(
        f"{common.COLOR_PURPLE}\t→ {color_count} colorized file(s) need to be converted"
    )

    # Convert grayscaled images to png
    if grey_count > 0:
        print(
            f"{common.COLOR_WHITE}[+] Converting {grey_count} grayscaled files…"
        )
        t = common.parallel(save_to_format, (
            q_grey_conv,
            ".png",
        ))
        print(f"{common.COLOR_GREEN} ↳ Done in {t:4.2f}s")

    # Convert colorized images to jpg
    if color_count > 0:
        print(
            f"{common.COLOR_WHITE}[+] Converting {color_count} colorized files…"
        )
        t = common.parallel(save_to_format, (
            q_color_conv,
            ".jpg",
        ))
        print(f"{common.COLOR_GREEN} ↳ Done in {t:4.2f}s")

    # Optimize png
Ejemplo n.º 3
0
    parser.add_argument("input", type=Path, help="Path to binary or directory")
    parser.add_argument("-p", "--pretend", dest="pretend", action="store_true", help="Do not trim, just print")
    args = parser.parse_args()

    # Sanity check
    if args.arch not in ARCHS:
        common.abort(f"{common.COLOR_RED}[!] ERROR: Invalid arch {common.COLOR_WHITE}{args.arch}\n{common.COLOR_YELLOW}[+] Available archs:\n- {ARCHS}")

    # Get executable list
    tmp: List[Path] = []
    if args.input.is_dir() is True:
        tmp = common.walk_directory(args.input, common.is_executable)
    elif common.is_executable(args.input):
        tmp.append(args.input)

    paths: List[Path] = []
    q = common.as_queue(tmp)
    common.parallel(fct=th_filter, args=(q, args.arch, paths, ))

    bytes_saved = int(0)
    for path in paths:
        print(f"{common.COLOR_WHITE}[+] Trimming {common.COLOR_YELLOW}{path}{common.COLOR_WHITE}")
        if args.pretend is False:
            osize = path.stat().st_size
            remove_arch(args.arch, path)
            nsize = path.stat().st_size
            bytes_saved += (osize - nsize)

    if args.pretend is False:
        print(f"{common.COLOR_WHITE}[+] {common.COLOR_GREEN if bytes_saved > 0 else common.COLOR_RED}{bytes_saved} bytes saved ({bytes_saved / 1048576:4.2f}Mb)")
Ejemplo n.º 4
0
        lambda x: io.match_signature(x, [
            b"\xFF\xD8\xFF\xE0", b"\xFF\xD8\xFF\xE1", b"\xFF\xD8\xFF\xE2",
            b"\xFF\xD8\xFF\xEE", b"\xFF\xD8\xFF\xDB"
        ]))
    queue = common.as_queue(files)
    total_original_bytes = sum(x.stat().st_size for x in files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {len(files)} file{'s' if len(files) != 1 else ''} to optimize ({total_original_bytes / 1048576:4.2f}Mb)"
    )
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] Using {common.COLOR_BLUE}{', '.join(programs)}"
    )

    # Optimize
    max_threads = multiprocessing.cpu_count(
    ) if args.threads <= 0 or args.threads > multiprocessing.cpu_count(
    ) else args.threads
    if args.use_guetzli is True and args.threads <= 0:
        max_threads = int(max_threads / 2)
    t = common.parallel(fct=th_optimize,
                        args=(
                            queue,
                            programs,
                            args.keep_metadata,
                        ),
                        max_threads=max_threads)
    bytes_saved = total_original_bytes - sum(x.stat().st_size for x in files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {common.COLOR_GREEN if bytes_saved > 0 else common.COLOR_RED}{bytes_saved} bytes saved ({bytes_saved / 1048576:4.2f}Mb) in {t:4.2f}s"
    )
Ejemplo n.º 5
0
        common.abort(
            f"{common.COLOR_RED}[!] ERROR: Invalid samplerate {common.COLOR_WHITE}{args.samplerate}\n{common.COLOR_YELLOW}[+] Available samplerates:\n- {samplerates}"
        )

    if args.bit_depth is not None and args.bit_depth not in SUPPORTED_BIT_DEPTH:
        bds = "\n- ".join(SUPPORTED_BIT_DEPTH)
        common.abort(
            f"{common.COLOR_RED}[!] ERROR: Invalid bit depth {common.COLOR_WHITE}{args.bit_depth}\n{common.COLOR_YELLOW}[+] Available bit depth:\n- {bds}"
        )

    out_format = args.format.lower()
    if is_valid_output_format(out_format) is False:
        formats = "\n- ".join(sorted(SUPPORTED_OUTPUT_TYPES.keys()))
        common.abort(
            f"{common.COLOR_RED}[!] ERROR: Invalid format {common.COLOR_WHITE}{out_format}\n{common.COLOR_YELLOW}[+] Available formats:\n- {formats}"
        )

    # Get a list of files
    files = common.walk_directory(args.input.resolve(), is_valid_audio_file)
    queue = common.as_queue(files)

    # Convert
    common.parallel(convert, (
        queue,
        out_format,
        args.samplerate,
        args.bit_depth,
        args.extension,
        args.delete,
    ))
Ejemplo n.º 6
0
        programs.append(F_OPTIPNG)

    # Sanity checks
    if len(programs) == 0:
        common.abort(
            f"{common.COLOR_WHITE}[!] {common.COLOR_RED}ERROR: No optimization programs specified or found, aborting…"
        )

    # Get files list
    files = common.walk_directory(
        args.input.resolve(),
        lambda x: io.match_signature(x, [b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"]))
    queue = common.as_queue(files)
    total_original_bytes = sum(x.stat().st_size for x in files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {len(files)} file{'s' if len(files) != 1 else ''} to optimize ({total_original_bytes / 1048576:4.2f}Mb)"
    )
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] Using {common.COLOR_BLUE}{', '.join(programs)}"
    )

    # Optimize
    t = common.parallel(th_optimize, (
        queue,
        programs,
    ))
    bytes_saved = total_original_bytes - sum(x.stat().st_size for x in files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {common.COLOR_GREEN if bytes_saved > 0 else common.COLOR_RED}{bytes_saved} bytes saved ({bytes_saved / 1048576:4.2f}Mb) in {t:4.2f}s"
    )
Ejemplo n.º 7
0
    """Extract thread"""
    while p_queue.empty() is False:
        infile: Path = p_queue.get()
        infos = av.get_file_infos(infile)
        streams = get_audio_streams(infos)
        for audio_stream in streams:
            outfile = f"{str(infile)}.{audio_stream.id}{extension_for_audio_info(audio_stream.infos)}"
            cmd = f"ffmpeg -i {quote(str(infile))} -v quiet -map 0:{audio_stream.id} -c copy {quote(outfile)}"
            LOGGER.log(f"{common.COLOR_WHITE}[+] Extracting track {audio_stream.id} from {common.COLOR_YELLOW}{infile} with {common.COLOR_PURPLE}{cmd}{common.COLOR_WHITE}")
            os.system(cmd)
        p_queue.task_done()

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input", type=Path, help="Path to directory or single video file")
    parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    args = parser.parse_args()
    LOGGER = logger.Logger(args.verbose)

    # Sanity checks
    common.ensure_exist(["ffmpeg"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    # Get a list of files
    files = common.list_directory(args.input.resolve())
    queue = common.as_queue(files)

    # Extract
    common.parallel(extract_audio, (queue,))
Ejemplo n.º 8
0
    """check"""
    while p_queue.empty() is False:
        original_file: Path = p_queue.get()
        try:
            mkv = mkvfile.MkvFile(original_file)
            for track in mkv.tracks:
                if track.codec == "substationalpha":
                    print(f"{original_file}")
        except:
            print(f"ERROR PARSING :::: {original_file}")
        p_queue.task_done()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input",
                        type=Path,
                        help="Path to directory or single MKV file")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvmerge"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    files = common.list_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".mkv", True)
    queue = common.as_queue(files)

    common.parallel(check_subs, (queue, ))
Ejemplo n.º 9
0
    LOGGER = logger.Logger(args.verbose)

    # Sanity checks
    common.ensure_exist(["metaflac"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    # Get files list
    files = common.walk_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".flac")
    queue = common.as_queue(files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {len(files)} file{'s' if len(files) != 1 else ''} to consider"
    )

    if args.list_tags is True:
        all_tags = []
        common.parallel(list_tags, (
            queue,
            all_tags,
        ))
        print(f"----\n{sorted(set(all_tags))}\n----")
    else:
        # Clean
        metaflac = remove_tags_cmd()
        common.parallel(clean_flac, (
            queue,
            metaflac,
            args.only_blocks,
        ))
Ejemplo n.º 10
0
def check_chaptered(p_queue: Queue):
    """check"""
    while p_queue.empty() is False:
        original_file: Path = p_queue.get()
        try:
            mkv = mkvfile.MkvFile(original_file)
            if mkv.chaptered is False:
                print(f"{original_file}")
        except:
            print(f"ERROR PARSING :::: {original_file}")
        p_queue.task_done()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input",
                        type=Path,
                        help="Path to directory or single MKV file")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvmerge"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    files = common.list_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".mkv", True)
    queue = common.as_queue(files)

    common.parallel(check_chaptered, (queue, ))