This Python script converts .cbz and .cbr files to PDF format and moves the original files to a folder named old within the same directory.
- Python 3: Ensure that Python 3 is installed on your system.
- Pillow: Python Imaging Library to handle image processing.
- rarfile: Library to handle
.cbrfiles. - tqdm: Library for displaying progress bars.
-
Install Required Libraries:
- Pillow: Install using
pip:pip install pillow
- rarfile: Install using
pip:pip install rarfile
- tqdm: Install using
pip:pip install tqdm
- Pillow: Install using
-
Clone the Repository: Open a terminal and clone the repository from GitHub:
git clone https://github.com/empr0r/CB2PDF.git
If pip is not an option or if you prefer to use system packages, follow these steps:
-
Install Required Libraries:
- Pillow: Install using
pacman:sudo pacman -S python-pillow
- rarfile: Install using
paruor another AUR helper:paru -S python-rarfile
- tqdm: Install using
pacman:sudo pacman -S python-tqdm
- Pillow: Install using
-
Clone the Repository: Open a terminal and clone the repository from GitHub:
git clone https://github.com/empr0r/CB2PDF.git
-
Prepare Your Directory:
- Drop the
cb2pdf.pyscript into the directory containing your.cbzor.cbrfiles.
- Drop the
-
Set Permissions:
- Open a terminal and navigate to the directory where you placed the script.
- Make the script executable by running:
chmod +x cb2pdf.py
-
Run the Script:
- Execute the script by running:
./cb2pdf.py
This will process all
.cbzand.cbrfiles in the directory, convert them to PDF, and move the original files to a folder calledold. - Execute the script by running:
-
Directory Setup:
- The script starts by identifying the current directory and setting up an
olddirectory where the original files will be moved after conversion.
- The script starts by identifying the current directory and setting up an
-
File Processing:
- The script scans the current directory for files with
.cbzor.cbrextensions. - For each file, it identifies whether it is a CBZ (ZIP archive) or CBR (RAR archive).
- The script scans the current directory for files with
-
Conversion:
- For
.cbzfiles, the script extracts images from the ZIP archive and combines them into a single PDF. - For
.cbrfiles, it uses therarfilelibrary to extract images from the RAR archive and then converts them to PDF.
- For
-
Batch Processing:
- The script processes files in batches to manage memory usage and system resources effectively. After processing a batch, it pauses to free up resources before moving on to the next batch.
-
Progress Bar:
- The script uses
tqdmto display a progress bar while processing each file, providing visual feedback on the conversion status.
- The script uses
-
File Management:
- After successfully converting a file, the script moves the original file to the
olddirectory to keep the working directory organized.
- After successfully converting a file, the script moves the original file to the
This project is licensed under the MIT License. See the LICENSE file for details.
-
ModuleNotFoundError: No module named 'PIL': Ensure you have installed the Pillow library. Using
pip, you can install it with:pip install pillow
Alternatively, on Arch Linux, use:
sudo pacman -S python-pillow
-
ModuleNotFoundError: No module named 'rarfile': Ensure you have installed the
rarfilelibrary. Usingpip, you can install it with:pip install rarfile
Alternatively, on Arch Linux, use:
paru -S python-rarfile
-
ModuleNotFoundError: No module named 'tqdm': Ensure you have installed the
tqdmlibrary. Usingpip, you can install it with:pip install tqdm
Alternatively, on Arch Linux, use:
sudo pacman -S python-tqdm
-
Permission Denied: Make sure you have executed the
chmod +x cb2pdf.pycommand before running the script.