Skip to main content

CBZ simplifies creating, managing, and viewing comic book files in CBZ format, offering seamless packaging, metadata handling, and built-in viewing capabilities

Project description

CBZ

CBZ is a Python library designed for creating, manipulating, and viewing comic book files in CBZ format. It offers a straightforward interface to pack comic pages into CBZ archives, extract metadata, and display comics using a built-in player.

Features

  • 🚀 Seamless Installation via pip
  • 📚 Pack images into CBZ format for comics and manga
  • 📝 Extract and manage title, series, format, and more
  • 🖼️ Handle comic pages with attributes like type and format
  • 📦 Unpack CBZ files to retrieve comic information
  • 🛠️ Built-in player for viewing CBZ comics
  • ❤️ Fully Open-Source! Pull Requests Welcome

Installation

Install KeyDive from PyPI using Poetry:

pip install cbz

Quick Start

Here's a quick example of how to create a CBZ file from a series of images:

from pathlib import Path

from cbz.comic import ComicInfo
from cbz.constants import PageType, YesNo, Manga, AgeRating, Format
from cbz.page import PageInfo

PARENT = Path(__file__).parent

if __name__ == '__main__':
    paths = list(Path('path/to/your/images').iterdir())

    # Load each page from the 'images' folder into a list of PageInfo objects
    pages = [
        PageInfo.load(
            path=path,
            type=PageType.FRONT_COVER if i == 0 else PageType.BACK_COVER if i == len(paths) - 1 else PageType.STORY
        )
        for i, path in enumerate(paths)
    ]

    # Create a ComicInfo object using ComicInfo.from_pages() method
    comic = ComicInfo.from_pages(
        pages=pages,
        title='Your Comic Title',
        series='Your Comic Series',
        number=1,
        language_iso='en',
        format=Format.WEB_COMIC,
        black_white=YesNo.NO,
        manga=Manga.NO,
        age_rating=AgeRating.PENDING
    )

    # Show the comic using the show()
    comic.show()

    # Pack the comic book content into a CBZ file format
    cbz_content = comic.pack()

    # Define the path where the CBZ file will be saved
    cbz_path = PARENT / 'your_comic.cbz'

    # Write the CBZ content to the specified path
    cbz_path.write_bytes(cbz_content)

Player

CBZ includes a command-line player for viewing CBZ comic book files. Simply run cbzplayer to launch the player with the specified CBZ file.

usage: cbzplayer [-h] <file>

Launch CBZ player with a comic book file

positional arguments:
  <file>      Path to the CBZ comic book file.

options:
  -h, --help  show this help message and exit

Detailed Usage

Creating a ComicInfo Object

The ComicInfo class represents a comic book with metadata and pages. It supports initialization from a list of PageInfo objects:

from cbz.comic import ComicInfo
from cbz.page import PageInfo

# Example usage:
pages = [
    PageInfo.load(path='/path/to/page1.jpg', type=PageType.FRONT_COVER),
    PageInfo.load(path='/path/to/page2.jpg', type=PageType.STORY),
    PageInfo.load(path='/path/to/page3.jpg', type=PageType.BACK_COVER),
]

comic = ComicInfo.from_pages(
    pages=pages,
    title='My Comic',
    series='Comic Series',
    number=1,
    language_iso='en',
    format=Format.WEB_COMIC,
    black_white=YesNo.NO,
    manga=Manga.NO,
    age_rating=AgeRating.PENDING
)

Extracting Metadata

Retrieve comic information as a dictionary using get_info():

info = comic.get_info()
print(info)

Packing into CBZ Format

Pack the comic into a CBZ file format:

cbz_content = comic.pack()

Unpacking from CBZ

Load a comic from an existing CBZ file:

comic_from_cbz = ComicInfo.from_cbz('/path/to/your_comic.cbz')

Contributors

hyugogirubato piskunqa OleskiiPyskun domenicoblanco RivMt flolep2607 gokender

Licensing

This software is licensed under the terms of MIT License.
You can find a copy of the license in the LICENSE file in the root folder.


© hyugogirubato 2024

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cbz-3.3.3.tar.gz (66.7 kB view details)

Uploaded Source

Built Distribution

cbz-3.3.3-py3-none-any.whl (66.8 kB view details)

Uploaded Python 3

File details

Details for the file cbz-3.3.3.tar.gz.

File metadata

  • Download URL: cbz-3.3.3.tar.gz
  • Upload date:
  • Size: 66.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.11 Windows/10

File hashes

Hashes for cbz-3.3.3.tar.gz
Algorithm Hash digest
SHA256 6c708078b9cbc8cc7cb9b1bef3a2be9aa41bcd1448bbb626d82afe3f552a2d7b
MD5 ad9f76ee203e5586d8233097b7572659
BLAKE2b-256 362d39a73e39cf1700108e0a498591715180fb4df4b1392ccdcf6d6dc4ff3dbb

See more details on using hashes here.

Provenance

File details

Details for the file cbz-3.3.3-py3-none-any.whl.

File metadata

  • Download URL: cbz-3.3.3-py3-none-any.whl
  • Upload date:
  • Size: 66.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.11 Windows/10

File hashes

Hashes for cbz-3.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e00177aaa6feeb67cb8ea7c27a7642c2515c766c4ab4c2826a8f7d1c7bf699ac
MD5 ba809eee42d28c7a57208ef8392953e8
BLAKE2b-256 641be1ba5f72f5cc0dc27965881c4205b63181f1b25a324866d113aaa7e4167d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page