Skip to content

Instantly share code, notes, and snippets.

@sleeyax
Created July 16, 2024 08:43
Show Gist options
  • Save sleeyax/7bbdd314c8de2adda4c82e4f66ea2f46 to your computer and use it in GitHub Desktop.
Save sleeyax/7bbdd314c8de2adda4c82e4f66ea2f46 to your computer and use it in GitHub Desktop.
Convert CBR (supports media type `application/x-rar-compressed; version=5`) to CBZ
import os
import shutil
import patoolib
input_directory = '/path/to/input/direcotry'
# List of filenames
filenames = [
'01 - Example comic 1 (2020)',
'02 - Example comic 2 (2020)',
'03 - Example comic 3 (2020)'
]
for filename in filenames:
rar_file_path = os.path.join(input_directory, filename + ".cbr")
if os.path.exists(rar_file_path):
# Convert RAR to CBZ (ZIP with .cbz extension)
cbz_file_path = os.path.join(input_directory, filename + '.cbz')
print(f"Processing '{rar_file_path}'")
patoolib.repack_archive(rar_file_path, cbz_file_path)
# Delete the original RAR file from directory A
os.remove(rar_file_path)
else:
print(f"File '{rar_file_path}' not found")
print("Process completed successfully.")
@sleeyax
Copy link
Author

sleeyax commented Jul 16, 2024

Usage:

$ python -m venv .venv
$ source .venv/bin/activate
$ pip install patool
$ python main.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment