anime-collection / decompress.py
v2ray's picture
Added compression and decompression scripts.
20d0351
raw
history blame
1.45 kB
import os
import sys
import argparse
import tarfile
import concurrent.futures
IMAGE_DIR = "images"
COMPRESSED_DIR = "compressed"
def decompress_chunk(chunk_file, output_dir):
with tarfile.open(chunk_file, "r:gz") as tar:
tar.extractall(path=output_dir)
def parse_args():
parser = argparse.ArgumentParser(description="Decompress chunked archives.")
parser.add_argument("-i", "--input-dir", default=COMPRESSED_DIR, help="Input directory containing compressed chunks")
parser.add_argument("-o", "--output-dir", default=IMAGE_DIR, help="Output directory for decompressed files")
args = parser.parse_args()
return args
def main():
args = parse_args()
if not os.path.exists(args.input_dir):
print(f"Input directory \"{args.input_dir}\" does not exist.")
sys.exit(1)
chunk_files = [os.path.join(args.input_dir, f) for f in os.listdir(args.input_dir) if f.endswith(".tar.gz")]
os.makedirs(args.output_dir, exist_ok=True)
with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
futures = []
for chunk_file in chunk_files:
future = executor.submit(decompress_chunk, chunk_file, args.output_dir)
futures.append(future)
concurrent.futures.wait(futures)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nScript interrupted by user, exiting...")
sys.exit(1)