"-d", "--delete", dest="delete", action="store_true", help="Delete audio and video file and rename after merge") args = parser.parse_args() # Sanity checks common.ensure_exist(["mkvmerge"]) if args.input.exists() is False or args.input.is_dir() is False: common.abort(parser.format_help()) if len(args.audio_lang) != 3: common.abort(parser.format_help()) # list audios audio_files = common.list_directory( args.input, lambda x: x.suffix in av.AUDIO_EXTENSIONS, True) # list vids video_files = common.list_directory( args.input, lambda x: x.suffix in av.VIDEO_EXTENSIONS, True) if len(audio_files) != len(video_files): common.abort( f"{common.COLOR_RED}[!] ERROR: Number of files mismatch, audio={len(audio_files)} video={len(video_files)}{common.COLOR_WHITE}" ) # Merge merge_subs(audio_files, video_files, args.audio_lang, args.audio_name, args.delete)
parser.add_argument("-z", "--video-lang", dest="video_lang", type=str, default="und", help="Lang of the video track") parser.add_argument("-r", "--repl", dest="repl", type=str, default="", help="Pattern to replace for the Title") args = parser.parse_args() # Get a list of files files = common.list_directory(args.input.resolve(), lambda x: x.suffix == ".mkv", True) for f in files: mkv = mkvfile.MkvFile(f) cmd = f'mkvpropedit {quote(str(f))}' # Handle subtitles tracks stracks = list(filter(lambda x: x.type == "subtitles", mkv.tracks)) sub_langs = args.sub_lang.split(",") sub_names = args.sub_name.split(",") if args.sub_name else [] tid = 1 for track in stracks: if tid <= len(sub_langs): sl = sub_langs[tid - 1] else: sl = "und"
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, ))
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("input", type=Path, help="Path to directory") parser.add_argument("-d", "--delete", dest="delete", action="store_true", help="Delete chapters file after merge") args = parser.parse_args() # Sanity checks common.ensure_exist(["mkvmerge"]) if args.input.exists() is False or args.input.is_dir() is False: common.abort(parser.format_help()) # list chapters chaps_files = common.list_directory( args.input, lambda x: x.suffix == ".xml" or x.suffix == ".txt", True) # list vids video_files = common.list_directory(args.input, lambda x: x.suffix == ".mkv", True) if len(chaps_files) != len(video_files): common.abort( f"{common.COLOR_RED}[!] ERROR: Number of files mismatch, chapters={len(chaps_files)} video={len(video_files)}{common.COLOR_WHITE}" ) # Merge merge_chapters(chaps_files, video_files, args.delete)
p_queue.task_done() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("input", type=Path, help="Path to manga directory") args = parser.parse_args() # Sanity checks path = args.input.resolve() if path.exists() is False or path.is_dir() is False: common.abort(parser.format_help()) # Get files list all_files = common.list_directory( path, lambda x: x.suffix in [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".tiff"]) print(f"{common.COLOR_WHITE}[+] {len(all_files)} file(s) to analyze…") # Analyze files q_grey_conv = Queue() q_color_conv = Queue() t_start = time.time() cl_ctx = cl.create_some_context() cl_queue = cl.CommandQueue(cl_ctx) cl_program = cl.Program(cl_ctx, CL_KERNEL).build() for f in all_files: img = Image.open(f).convert('RGBA') is_grey = cl_is_grey(img, cl_ctx, cl_queue, cl_program) if is_grey is True and imghdr.what(f) != "png": q_grey_conv.put(f)
programs.append(O_SUBSAMPLE) if args.use_guetzli is True and common.which("guetzli") is not None: programs.append(O_GUETZLI) if args.use_jpegtran is True and common.which("jpegtran") is not None: programs.append(O_JPEGTRAN) # 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.list_directory( args.input.resolve(), 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
#!/usr/bin/env python3 # coding: utf-8 """ Replace invalid characters from a filename """ import os import argparse from pathlib import Path from utils import common if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("input", type=Path, help="Path to directory or single file") args = parser.parse_args() # Sanity check if args.input is None: common.abort(parser.format_help()) # If path is a directory, get a list of files files = common.list_directory(args.input.resolve(), None, True) for f in files: a = str(f).encode('utf-8', "ignore") os.rename(str(f), a)
cmd = f'mkvpropedit {quote(str(mkv))} --add-attachment {quote(str(attachment))}' os.system(cmd) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("attachments_path", type=Path, help="Path to directory of attachments or single file") parser.add_argument( "videos_path", type=Path, help="Path to directory or single video file (all files must be .mkv)") args = parser.parse_args() # Sanity checks common.ensure_exist(["mkvmerge", "mkvpropedit"]) if args.videos_path.exists() is False or args.attachments_path.exists( ) is False: common.abort(parser.format_help()) # Get a list of files video_files = common.list_directory(args.videos_path.resolve(), lambda x: x.suffix == ".mkv", True) attachments = common.list_directory(args.attachments_path.resolve()) # Add all attachments for video in video_files: for attachment in attachments: add_attachment(video, attachment)
"--delete", dest="delete", action="store_true", help="Delete subtitle and video file and rename after merge") args = parser.parse_args() # Sanity checks common.ensure_exist(["mkvmerge"]) if args.input.exists() is False or args.input.is_dir() is False: common.abort(parser.format_help()) if len(args.sub_lang) != 3: common.abort(parser.format_help()) # list subs subs_files = common.list_directory( args.input, lambda x: x.suffix in av.SUBTITLE_EXTENSIONS, True) # list vids video_files = common.list_directory( args.input, lambda x: x.suffix in av.VIDEO_EXTENSIONS, True) if len(subs_files) != len(video_files): common.abort( f"{common.COLOR_RED}[!] ERROR: Number of files mismatch, subtitles={len(subs_files)} video={len(video_files)}{common.COLOR_WHITE}" ) # Merge merge_subs(subs_files, video_files, args.sub_lang, args.sub_name, args.delete)
def map_names(src: List[Path], dst: List[Path], real=False): """rename `dst` to match `src`""" for idx, val in enumerate(src): src_filename = val.name target_file = dst[idx] new_file = target_file.with_name(src_filename) print(f"{common.COLOR_WHITE}{target_file}\n ↳ {common.COLOR_YELLOW}{new_file}{common.COLOR_WHITE}") if real is True: shutil.move(target_file, new_file) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("src", type=Path, help="Path to directory or file") parser.add_argument("dst", type=Path, help="Path to directory or file") args = parser.parse_args() # Sanity check if args.src.exists() is False or args.dst.exists() is False: common.abort(parser.format_help()) # If path is a directory, get a list of files src_files = common.list_directory(args.src.resolve(), sort=True) dst_files = common.list_directory(args.dst.resolve(), sort=True) if len(src_files) != len(dst_files): common.abort(f"{common.COLOR_RED}[!] ERROR: Number of files mismatch, src={len(src_files)} dst={len(dst_files)}{common.COLOR_WHITE}") map_names(src_files, dst_files, False) ok = input("Proceed (y/n) ? ") if common.str2bool(str(ok)) is True: map_names(src_files, dst_files, True)