Coder Social home page Coder Social logo

dir2cbar's Introduction

README - dir2cbr

what is this and why is it not important

This Python script is used to create a CBR (Comic Book Archive) file from sorted images and a PDF document. It provides a command-line interface with various options for image and cover selection.

To run the script, you need to have Python installed on your system. Once installed, follow the steps below:

  1. Copy the code into a Python script file, e.g., create_cbr.py.

  2. Install the required dependencies by running the following command in your terminal:

pip install PyPDF2 pillow argparse patool
  1. Open a terminal and navigate to the directory where the script file is located.

  2. Execute the script by running the following command:

python create_cbr.py -S [images_directory] -O [output_cbr_file] -F [cover_image_pattern] -T [title_replace_pattern] -M [mode] -P [prompt_all]

Replace the placeholders ([images_directory], [output_cbr_file], etc.) with the appropriate values for your use case. The command-line arguments are explained below:

  • -S or --source: Specifies the source directory containing sorted images and PDF documents.
  • -O or --out: Specifies the output CBR file path.
  • -F or --front: (Optional) Specifies the cover image selection. It can be a filename, a pattern, a number (n), or a negative number (-n) with an optional background color.
  • -T or --tidytitles: (Optional) Specifies the title tidy up pattern for image titles.
  • -M or --mode: (Optional) Specifies the mode for the script operation. It can be "approve", "preview", or "quiet".
  • -P or --prompt: (Optional) Specifies whether to prompt for all arguments or use the default if empty. It can be "all" or "empty".

Note: All command-line arguments are required except for -F, -T, -M, and -P, which have default values if not provided.

The script utilizes the following Python libraries to perform its operations:

  • os: Provides functions for interacting with the operating system.
  • shutil: Provides functions for file and directory operations.
  • argparse: Facilitates command-line argument parsing.
  • PyPDF2: Allows reading PDF files.
  • PIL: Provides image processing capabilities.
  • patoolib: Enables the creation of archive files.

The script consists of several functions to handle different aspects of creating a CBR file:

  • convert_pdf_to_png: Converts a PDF file into PNG images using the "mutool" command.
  • create_cbr: Orchestrates the process of creating a CBR file by finding the cover image, copying the images, converting PDF to PNG (if necessary), creating the CBR file, and cleaning up temporary files.
  • find_cover_image: Finds the cover image from the list of images based on the specified cover image pattern.
  • copy_images: Copies the image files from the source directory to a temporary directory.
  • pdf_found_in_directory: Checks if a PDF file is present in the images directory.
  • find_pdf_file: Finds the PDF file in the images directory.
  • move_png_pages_to_directory: Moves the PNG images created from the PDF to the temporary directory.
  • create_cbr_file: Creates the CBR file using the patoolib library.

The main function is responsible for parsing the command-line arguments using the argparse library and calling the create_cbr function with the provided arguments.

Once the script finishes executing, you will have a CBR file at the specified output path containing the sorted images and PDF documents.

For more information and usage examples, please refer to the code comments and documentation of the used libraries.

For detailed explanations and examples of manipulating images, PDF files, and creating CBR archives in Python, you can refer to the following resources:

quick use:

usage screenshot

See what this created in the test folder.

dir2cbar's People

Contributors

timmytimj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.