if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("arch", type=str, help="Arch to remove (arm64, i386, x86_64...)") 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)
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, ))
parser = argparse.ArgumentParser() parser.add_argument("input", type=Path, help="Directory containing emails") parser.add_argument("-o", "--output", dest="output", type=str, default=None, help="Output file (csv)") parser.add_argument("-t", "--terms", dest="terms", type=str, default=None, help="Words to look for, comma separated (ex: work,car)") args = parser.parse_args() # Sanity checks if args.input.exists() is False: common.abort(parser.format_help()) terms: List[str] = [] if args.terms: terms = args.terms.strip().split(',') # Get a list of files (.msg) and queue it emails = common.walk_directory(os.path.abspath(args.input), lambda x: x.endswith(".msg")) queue = queue.Queue() for mail in emails: queue.put(mail) # Launch threads results: List[Dict[str, str]] = [] errors: List[str] = [] ignored_days: List[str] = [] ignored_hours: List[str] = [] for i in range(multiprocessing.cpu_count()): th = Thread(target=th_filter, args=(queue, results, errors, ignored_days, ignored_hours, terms,)) th.daemon = True th.start() queue.join()
if args.use_pngquant is True and common.which("pngquant") is not None: programs.append(F_PNGQUANT) if args.use_zopfli is True and common.which("zopflipng") is not None: programs.append(F_ZOPFLI) if args.use_optipng is True and common.which("optipng") is not None: 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, ))
help="Only remove PADDING, PICTURE and SEEKTABLE blocks") parser.add_argument("-l", "--list-tags", dest="list_tags", action="store_true", help="Get a list of all tags across all files") args = parser.parse_args() 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()