Last active
December 13, 2024 11:56
-
-
Save Akczht/50562a695bce7416700150d3ef905934 to your computer and use it in GitHub Desktop.
a script to convert all the folders in a directory to CBZ files using 7-zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
def convert_folders_to_cbz(folder_path=os.getcwd()): | |
# Get all folders in the specified directory | |
dirs = [d for d in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, d))] | |
for dir_name in dirs: | |
folder_to_convert = os.path.join(folder_path, dir_name) | |
zip_file = os.path.join(folder_path, f"{dir_name}.zip") | |
cbz_file = os.path.join(folder_path, f"{dir_name}.cbz") | |
# Include only PNG files in the ZIP archive with highest compression and multithreading | |
command = ["7zz", "a", "-mx9", "-mmt=on", zip_file, os.path.join(folder_to_convert, "*.png")] | |
try: | |
subprocess.run(command, check=True) | |
# Rename ZIP file to CBZ | |
os.rename(zip_file, cbz_file) | |
print(f"Converted folder '{folder_to_convert}' to CBZ file '{cbz_file}'") | |
except subprocess.CalledProcessError as e: | |
print(f"Error converting folder '{folder_to_convert}' to CBZ: {e}") | |
except OSError as e: | |
print(f"Error renaming ZIP to CBZ for folder '{folder_to_convert}': {e}") | |
# Example usage | |
convert_folders_to_cbz() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment