Metadata-Version: 2.4
Name: comic-archive
Version: 0.1.1
Summary: An extensible library to manage comic archives and their embedded files and metadata.
Project-URL: Issues, https://codeberg.org/buriedincode/comic-archive/issues
Project-URL: Source, https://codeberg.org/buriedincode/comic-archive
Author-email: BuriedInCode <buriedincode@duckpond.nz>
Maintainer-email: BuriedInCode <buriedincode@duckpond.nz>
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: msgspec-extras>=0.2.0
Requires-Dist: msgspec-xml>=0.3.0
Requires-Dist: xmlschema>=4.3.0
Requires-Dist: zipremove>=0.10.0
Provides-Extra: cb7
Requires-Dist: py7zr>=1.1.0; extra == 'cb7'
Provides-Extra: cbr
Requires-Dist: rarfile>=4.4; extra == 'cbr'
Provides-Extra: pdf
Requires-Dist: comicbox-pdffile>=0.6.0; extra == 'pdf'
Description-Content-Type: text/markdown

# Comic Archive

[![PyPI - Python](https://img.shields.io/pypi/pyversions/comic-archive.svg?logo=Python&label=Python&style=flat-square)](https://pypi.org/p/comic-archive/)
[![PyPI - Status](https://img.shields.io/pypi/status/comic-archive.svg?logo=Python&label=Status&style=flat-square)](https://pypi.org/p/comic-archive/)
[![PyPI - Version](https://img.shields.io/pypi/v/comic-archive.svg?logo=Python&label=Version&style=flat-square)](https://pypi.org/p/comic-archive/)
[![PyPI - License](https://img.shields.io/pypi/l/comic-archive.svg?logo=Python&label=License&style=flat-square)](https://opensource.org/licenses/MIT)

[![prek](https://img.shields.io/badge/prek-enabled-informational?logo=prek&style=flat-square)](https://github.com/j178/prek)
[![Ruff](https://img.shields.io/badge/Ruff-enabled-informational?logo=ruff&style=flat-square)](https://github.com/astral-sh/ruff)
[![ty](https://img.shields.io/badge/ty-enabled-informational?logo=ruff&style=flat-square)](https://github.com/astral-sh/ty)

[![status-badge](https://ci.codeberg.org/api/badges/17625/status.svg)](https://ci.codeberg.org/repos/17625)

An extensible library to manage comic archives and their embedded files and metadata.

## Supported Formats

More can be added by extending the respective base class and adding to the registry.

### Archives

| Archive    | Extra Required |
| ---------- | -------------- |
| .cbz, .zip | _builtin_      |
| .cbt, .tar | _builtin_      |
| .cbr, .rar | cbr            |
| .cb7, .7z  | cb7            |
| .pdf       | pdf            |

**Compability Table**

| Format | Read | Update | Create |
| ------ | :--: | :----: | :----: |
| cbz    |  ✅  |   ✅   |   ✅   |
| cbt    |  ❌  |   ❌   |   ✅   |
| cbr    |  ✅  |   ❌   |   ❌   |
| cb7    |  ✅  |   ❌   |   ✅   |
| pdf    |  ✅  |   ✅   |   ❌   |

If something is marked as in-compatible the library will try extracting and making the change via the local system and re-archive (if it has the create capability).

### Metadata

- [ComicInfo.xml v2.0](schemas/v2.0/ComicInfo.xsd)
- [MetronInfo.xml v1.1](https://raw.githubusercontent.com/Metron-Project/metroninfo/master/schema/v1.1/MetronInfo.xsd)

## Installation

```sh
pdm add comic-archive
```

Optional extras can be added as needed:

```sh
pdm add comic-archive[cbr,cb7,pdf]
```

## Usage

```python
from pathlib import Path

from comic_archive import Comic
from comic_archive.metadata import MetronInfo

my_comic = Path("MyComic.cbz")
with Comic.open(my_comic) as comic:
    print(comic.list_filenames())
    print(comic.read_file(filename="page-1.jpg").decode("UTF-8"))
    print(comic.metadata)  # Dict of registered metadata in archive

    metron_info = comic.get_metadata(metadata_type=MetronInfo)
    print(metron_info.series)
```

Writing files and metadata (support depends on the archive format, see table above):

```python
with Comic.open(my_comic) as comic:
    comic.write_file(filename="page-99.jpg", data=b"...", override=True)
    comic.remove_file(filename="page-01.jpg")

    metron_info = comic.get_metadata(metadata_type=MetronInfo)
    metron_info.series.name = "Updated Title"
    comic.set_metadata(metron_info)
```

You can also convert between different archives (as long as the destination archive has `create` capability)

```python
from comic_archive.archives import ZipArchive

rar_comic = Path("MyComic.cbr")
with Comic.open(rar_comic) as comic:
    print(comic.file)  # MyComic.cbr
    comic.convert(
        ZipArchive, delete_original=True
    )  # All future comic interactions will be on the new archive
    print(comic.file)  # MyComic.cbz
```

## Socials

[![Social - Matrix](https://img.shields.io/matrix/The-Dev-Environment:matrix.org?label=The-Dev-Environment&logo=matrix&style=for-the-badge)](https://matrix.to/#/#The-Dev-Environment:matrix.org)
