Compare commits

...
7 Commits
Author SHA1 Message Date
legonzaur 45da4c11f4 fix: allow comi.number to be a float 2025-12-30 15:25:50 +01:00
legonzaur 1e23fad6b5 fix: allow Comic.number to be a float 2025-12-30 15:25:46 +01:00
legonzaur 4ebee2a6cf chore: formatting 2025-12-30 15:25:19 +01:00
legonzaur ef4eff4868 fix pyproject toml to work with uv 2025-12-30 15:24:47 +01:00
hyugogirubato d37be87c2f Merge pull request #29 from hyugogirubato/dependabot/github_actions/actions/checkout-6
Bump actions/checkout from 5 to 6
2025-11-30 14:59:33 +01:00
dependabot[bot] 0b011a7efc Bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-24 15:58:42 +00:00
hyugogirubato 62b8cf5739 simplify suffix check 2025-11-04 00:00:46 +01:00
5 changed files with 189 additions and 177 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ jobs:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
+1 -1
View File
@@ -176,7 +176,7 @@ class ComicInfo(ComicModel):
# Some archives may contain folders or hidden files (e.g., ".extra/" or "__MACOSX/.DS_Store")
# that could corrupt the suffix detection and cause invalid image handling.
if not suffix or suffix not in IMAGE_FORMAT:
if suffix not in IMAGE_FORMAT:
logging.warning(f'Skipping unsupported or invalid file: {name!r} (suffix={suffix!r})')
continue
+140 -136
View File
@@ -3,191 +3,195 @@ from typing import Union
from langcodes import Language
XML_NAME = 'ComicInfo.xml'
XML_NAME = "ComicInfo.xml"
IMAGE_FORMAT = {
'.jpeg', '.jpg', # JPEG (Joint Photographic Experts Group)
'.png', # PNG (Portable Network Graphics)
'.gif', # GIF (Graphics Interchange Format)
'.bmp', # BMP (Bitmap Image File)
'.tiff', '.tif', # TIFF (Tagged Image File Format)
'.webp', # WebP (Web Picture Format, by Google)
'.jxl', # JPEG XL (Next-generation JPEG format)
'.avif' # AVIF (AV1 Image File Format, based on AV1 codec)
".jpeg",
".jpg", # JPEG (Joint Photographic Experts Group)
".png", # PNG (Portable Network Graphics)
".gif", # GIF (Graphics Interchange Format)
".bmp", # BMP (Bitmap Image File)
".tiff",
".tif", # TIFF (Tagged Image File Format)
".webp", # WebP (Web Picture Format, by Google)
".jxl", # JPEG XL (Next-generation JPEG format)
".avif", # AVIF (AV1 Image File Format, based on AV1 codec)
}
class YesNo(Enum):
UNKNOWN = 'Unknown'
NO = 'No'
YES = 'Yes'
UNKNOWN = "Unknown"
NO = "No"
YES = "Yes"
class Manga(Enum):
UNKNOWN = 'Unknown'
NO = 'No'
YES = 'Yes'
RIGHT_LEFT = 'YesAndRightToLeft'
UNKNOWN = "Unknown"
NO = "No"
YES = "Yes"
RIGHT_LEFT = "YesAndRightToLeft"
class PageType(Enum):
FRONT_COVER = 'FrontCover'
INNER_COVER = 'InnerCover'
ROUNDUP = 'Roundup'
STORY = 'Story'
ADVERTISEMENT = 'Advertisement'
EDITORIAL = 'Editorial'
LETTERS = 'Letters'
PREVIEW = 'Preview'
BACK_COVER = 'BackCover'
OTHER = 'Other'
DELETED = 'Deleted'
FRONT_COVER = "FrontCover"
INNER_COVER = "InnerCover"
ROUNDUP = "Roundup"
STORY = "Story"
ADVERTISEMENT = "Advertisement"
EDITORIAL = "Editorial"
LETTERS = "Letters"
PREVIEW = "Preview"
BACK_COVER = "BackCover"
OTHER = "Other"
DELETED = "Deleted"
class AgeRating(Enum):
UNKNOWN = 'Unknown'
ADULTS18 = 'Adults Only 18+'
CHILDHOOD = 'Early Childhood'
EVERYONE = 'Everyone'
EVERYONE10 = 'Everyone 10+'
G = 'G'
KIDS = 'Kids to Adults'
M = 'M'
MA15 = 'MA15+'
MATURE17 = 'Mature 17+'
PG = 'PG'
R18 = 'R18+'
PENDING = 'Rating Pending'
TEEN = 'Teen'
X18 = 'X18+'
UNKNOWN = "Unknown"
ADULTS18 = "Adults Only 18+"
CHILDHOOD = "Early Childhood"
EVERYONE = "Everyone"
EVERYONE10 = "Everyone 10+"
G = "G"
KIDS = "Kids to Adults"
M = "M"
MA15 = "MA15+"
MATURE17 = "Mature 17+"
PG = "PG"
R18 = "R18+"
PENDING = "Rating Pending"
TEEN = "Teen"
X18 = "X18+"
class Format(Enum):
UNKNOWN = 'Unknown'
UNKNOWN = "Unknown"
# ONE_SHOT = '1 Shot'
# ONE_SHOT = '1/2',
# ONE_SHOT = '1-Shot'
ANNOTATION = 'Annotation'
ANNOTATION = "Annotation"
# ANNOTATIONS = 'Annotations'
ANNUAL = 'Annual'
ANTHOLOGY = 'Anthology'
ANNUAL = "Annual"
ANTHOLOGY = "Anthology"
# BLACK_WHITE = 'B&W'
# BLACK_WHITE = 'B/W'
# BLACK_WHITE = 'B&&W'
BLACK_WHITE = 'Black & White'
BLACK_WHITE = "Black & White"
# BOX_SET = 'Box Set'
BOX_SET = 'Box-Set'
CROSSOVER = 'Crossover'
DIRECTOR_CUT = 'Director\'s Cut'
EPILOGUE = 'Epilogue'
EVENT = 'Event'
FCBD = 'FCBD'
FLYER = 'Flyer'
BOX_SET = "Box-Set"
CROSSOVER = "Crossover"
DIRECTOR_CUT = "Director's Cut"
EPILOGUE = "Epilogue"
EVENT = "Event"
FCBD = "FCBD"
FLYER = "Flyer"
# GIANT_SIZE = 'Giant'
# GIANT_SIZE = 'Giant Size'
GIANT_SIZE = 'Giant-Size'
GRAPHIC_NOVEL = 'Graphic Novel'
GIANT_SIZE = "Giant-Size"
GRAPHIC_NOVEL = "Graphic Novel"
# HARDCOVER = 'Hardcover'
HARDCOVER = 'Hard-Cover'
HARDCOVER = "Hard-Cover"
# KING_SIZE = 'King'
# KING_SIZE = 'King Size'
KING_SIZE = 'King-Size'
LIMITED_SERIES = 'Limited Series'
MAGAZINE = 'Magazine'
NSFW = 'NSFW'
KING_SIZE = "King-Size"
LIMITED_SERIES = "Limited Series"
MAGAZINE = "Magazine"
NSFW = "NSFW"
# ONE_SHOT = 'One Shot'
ONE_SHOT = 'One-Shot'
POINT1 = 'Point 1'
PREVIEW = 'Preview'
PROLOGUE = 'Prologue'
REFERENCE = 'Reference'
REVIEW = 'Review'
REVIEWED = 'Reviewed'
SCANLATION = 'Scanlation'
SCRIPT = 'Script'
SERIES = 'Series'
SKETCH = 'Sketch'
SPECIAL = 'Special'
ONE_SHOT = "One-Shot"
POINT1 = "Point 1"
PREVIEW = "Preview"
PROLOGUE = "Prologue"
REFERENCE = "Reference"
REVIEW = "Review"
REVIEWED = "Reviewed"
SCANLATION = "Scanlation"
SCRIPT = "Script"
SERIES = "Series"
SKETCH = "Sketch"
SPECIAL = "Special"
# TRADE_PAPER_BACK = 'TPB'
TRADE_PAPER_BACK = 'Trade Paper Back'
TRADE_PAPER_BACK = "Trade Paper Back"
# WEB_COMIC = 'WebComic'
WEB_COMIC = 'Web Comic'
WEB_COMIC = "Web Comic"
# YEAR_ONE = 'Year 1'
YEAR_ONE = 'Year One'
YEAR_ONE = "Year One"
class Rating(float):
def __new__(cls, value: Union[int, float] = -1) -> float:
assert -1 <= float(value) <= 5, f'Rating must be between 0 and 5, input {value}'
assert -1 <= float(value) <= 5, f"Rating must be between 0 and 5, input {value}"
return super().__new__(cls, value)
class LanguageISO(str):
def __new__(cls, value: str = '') -> str:
assert not value or Language.get(str(value)).is_valid(), f'Invalid {value} language'
def __new__(cls, value: str = "") -> str:
assert (
not value or Language.get(str(value)).is_valid()
), f"Invalid {value} language"
return super().__new__(cls, value)
COMIC_FIELDS = {
'title': ('Title', str),
'series': ('Series', str),
'number': ('Number', int),
'count': ('Count', int),
'volume': ('Volume', int),
'alternate_series': ('AlternateSeries', str),
'alternate_number': ('AlternateNumber', int),
'alternate_count': ('AlternateCount', int),
'summary': ('Summary', str),
'notes': ('Notes', str),
'year': ('Year', int),
'month': ('Month', int),
'day': ('Day', int),
'writer': ('Writer', str),
'penciller': ('Penciller', str),
'inker': ('Inker', str),
'colorist': ('Colorist', str),
'letterer': ('Letterer', str),
'cover_artist': ('CoverArtist', str),
'editor': ('Editor', str),
'translator': ('Translator', str),
'publisher': ('Publisher', str),
'imprint': ('Imprint', str),
'genre': ('Genre', str),
'tags': ('Tags', str),
'web': ('Web', str),
'format': ('Format', Format),
'ean': ('EAN', str),
'black_white': ('BlackAndWhite', YesNo),
'manga': ('Manga', Manga),
'characters': ('Characters', str),
'teams': ('Teams', str),
'locations': ('Locations', str),
'scan_information': ('ScanInformation', str),
'story_arc': ('StoryArc', str),
'story_arc_number': ('StoryArcNumber', int),
'series_group': ('SeriesGroup', str),
'age_rating': ('AgeRating', AgeRating),
'main_character_or_team': ('MainCharacterOrTeam', str),
'review': ('Review', str),
'language_iso': ('LanguageISO', LanguageISO),
'community_rating': ('CommunityRating', Rating),
'added': ('Added', str),
'released': ('Released', str),
'file_size': ('FileSize', int),
'file_modified_time': ('FileModifiedTime', str),
'file_creation_time': ('FileCreationTime', str),
'book_price': ('BookPrice', str),
'custom_values_store': ('CustomValuesStore', str)
"title": ("Title", str),
"series": ("Series", str),
"number": ("Number", float),
"count": ("Count", int),
"volume": ("Volume", int),
"alternate_series": ("AlternateSeries", str),
"alternate_number": ("AlternateNumber", int),
"alternate_count": ("AlternateCount", int),
"summary": ("Summary", str),
"notes": ("Notes", str),
"year": ("Year", int),
"month": ("Month", int),
"day": ("Day", int),
"writer": ("Writer", str),
"penciller": ("Penciller", str),
"inker": ("Inker", str),
"colorist": ("Colorist", str),
"letterer": ("Letterer", str),
"cover_artist": ("CoverArtist", str),
"editor": ("Editor", str),
"translator": ("Translator", str),
"publisher": ("Publisher", str),
"imprint": ("Imprint", str),
"genre": ("Genre", str),
"tags": ("Tags", str),
"web": ("Web", str),
"format": ("Format", Format),
"ean": ("EAN", str),
"black_white": ("BlackAndWhite", YesNo),
"manga": ("Manga", Manga),
"characters": ("Characters", str),
"teams": ("Teams", str),
"locations": ("Locations", str),
"scan_information": ("ScanInformation", str),
"story_arc": ("StoryArc", str),
"story_arc_number": ("StoryArcNumber", int),
"series_group": ("SeriesGroup", str),
"age_rating": ("AgeRating", AgeRating),
"main_character_or_team": ("MainCharacterOrTeam", str),
"review": ("Review", str),
"language_iso": ("LanguageISO", LanguageISO),
"community_rating": ("CommunityRating", Rating),
"added": ("Added", str),
"released": ("Released", str),
"file_size": ("FileSize", int),
"file_modified_time": ("FileModifiedTime", str),
"file_creation_time": ("FileCreationTime", str),
"book_price": ("BookPrice", str),
"custom_values_store": ("CustomValuesStore", str),
}
PAGE_FIELDS = {
'image': ('@Image', int),
'type': ('@Type', PageType),
'double': ('@DoublePage', bool),
'key': ('@Key', str),
'bookmark': ('@Bookmark', str),
'image_size': ('@ImageSize', int),
'image_width': ('@ImageWidth', int),
'image_height': ('@ImageHeight', int)
"image": ("@Image", int),
"type": ("@Type", PageType),
"double": ("@DoublePage", bool),
"key": ("@Key", str),
"bookmark": ("@Bookmark", str),
"image_size": ("@ImageSize", int),
"image_width": ("@ImageWidth", int),
"image_height": ("@ImageHeight", int),
}
+30 -5
View File
@@ -1,5 +1,19 @@
from cbz.constants import COMIC_FIELDS, PAGE_FIELDS, Format, YesNo, Manga, AgeRating, LanguageISO, Rating, PageType
from cbz.constants import (
COMIC_FIELDS,
PAGE_FIELDS,
Format,
YesNo,
Manga,
AgeRating,
LanguageISO,
Rating,
PageType,
)
from cbz.utils import verify_attr, default_attr
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
class BaseModel:
@@ -21,7 +35,7 @@ class BaseModel:
# Set default values for each attribute based on its type
setattr(self, key, kwargs.get(key, default_attr(field_type)))
def __setattr__(self, key: str, value: any) -> None:
def __setattr__(self, key: str, value: "Any") -> None:
"""
Sets the value of an attribute and verifies its type.
@@ -39,6 +53,9 @@ class BaseModel:
value = field_type(value)
# Verify that the assigned value matches the expected type
verify_attr(field_type, key, value)
if isinstance(value, float):
if value.is_integer():
value = int(value)
except (AttributeError, KeyError):
pass
super().__setattr__(key, value)
@@ -50,9 +67,15 @@ class BaseModel:
Returns:
str: A string representation of the object, displaying its class name and attribute key-value pairs.
"""
return '{name}({items})'.format(
return "{name}({items})".format(
name=self.__class__.__name__,
items=', '.join([f'{k}={repr(v)}' for k, v in self.__dict__.items() if not k.startswith('_')])
items=", ".join(
[
f"{k}={repr(v)}"
for k, v in self.__dict__.items()
if not k.startswith("_")
]
),
)
@@ -60,9 +83,10 @@ class ComicModel(BaseModel):
"""
Model for representing comic book metadata.
"""
title: str
series: str
number: int
number: float
count: int
volume: int
alternate_series: str
@@ -124,6 +148,7 @@ class PageModel(BaseModel):
"""
Model for representing comic book pages.
"""
type: PageType
double: bool
image_size: int
+17 -34
View File
@@ -1,15 +1,10 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
[project]
name = "cbz"
version = "3.4.5"
description = "CBZ simplifies creating, managing, and viewing comic book files in CBZ, CBR, and PDF formats, offering seamless packaging, metadata handling and built-in viewing capabilities."
license = "MIT"
authors = ["hyugogirubato <65763543+hyugogirubato@users.noreply.github.com>"]
authors = [{name="hyugogirubato", email="65763543+hyugogirubato@users.noreply.github.com"}]
readme = "README.md"
repository = "https://github.com/hyugogirubato/cbz"
keywords = [
"python",
"cbz",
@@ -29,41 +24,29 @@ classifiers = [
"Topic :: Utilities",
"Topic :: Software Development :: Libraries :: Python Modules",
]
include = [
{ path = "CHANGELOG.md", format = "sdist" },
{ path = "README.md", format = "sdist" },
{ path = "LICENSE", format = "sdist" },
requires-python = ">=3.8,<4.0"
dependencies= [
"langcodes>=3.4.0",
"Pillow>=10.4.0",
"pypdf >=5.7.0",
"rarfile>=4.2",
"xmltodict>=0.14.2"
]
[tool.poetry.urls]
"Issues" = "https://github.com/hyugogirubato/cbz/issues"
"Changelog" = "https://github.com/hyugogirubato/cbz/blob/main/CHANGELOG.md"
[tool.poetry.dependencies]
python = ">=3.8,<4.0"
langcodes = ">=3.4.0"
Pillow = ">=10.4.0"
pypdf = ">=5.7.0"
rarfile = ">=4.2"
xmltodict = ">=0.14.2"
pillow-avif-plugin = { version = ">=1.5.2", optional = true, markers = "python_version >= '3.9'" }
pillow-jxl-plugin = { version = ">=1.3.4", optional = true, markers = "python_version >= '3.9'" }
[project.optional-dependencies]
pillow = ["pillow-avif-plugin>=1.5.2", "pillow-jxl-plugin>=1.3.4"]
[dependency-groups]
dev = ["pytest>=7.4.0,<9.0.0", "pytest-cov>=5.0.0"]
[tool.poetry.extras]
pillow = ["pillow-avif-plugin", "pillow-jxl-plugin"]
[tool.poetry.scripts]
cbzplayer = "cbz.__main__:main"
[[tool.poetry.source]]
name = "localpypi"
url = "https://pypi.org/simple/"
priority = "primary"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.4.0,<9.0.0"
pytest-cov = ">=5.0.0"
[tool.pytest.ini_options]
testpaths = ["tests"]