DataClasses
Validations()
A base class for data validation in dataclasses.
This class provides initialization and post-initialization hooks for validating dataclass fields.
Initialize the Validations class.
This constructor sets up the initial state for the Validations class, preparing it for use in data validation.
Functions
__post_init__() -> None
Run validation methods if declared.
The validation method can be a simple check that raises ValueError or a transformation
to the field value. The validation is performed by calling a function named:
validate_<field_name>(self, value, field) -> field.type.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the Validations class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Example
validations = Validations()
validations.__post_init__()
PageType
Defines constants for different types of pages.
This class provides a set of predefined page types for categorizing pages in a publication.
ImageMetadata
Bases: TypedDict
Defines the structure of ImageMetadata using TypedDict.
This class represents the metadata associated with an image.
Price(amount: Decimal, currency: str = 'USD')
dataclass
Bases: Validations
A data class representing a price with validations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
amount |
The amount associated with the price.
TYPE:
|
currency |
The ISO 4217 currency code, defaults to "USD".
TYPE:
|
Functions
validate_currency(value: str, **_: object) -> str
staticmethod
Validate an ISO 4217 currency code.
If the value is None, it returns the default currency code "USD". Otherwise, it strips any leading or trailing whitespace and uppercases the value. If the value is empty after stripping, it raises a ValueError. The currency code is validated against pycountry's ISO 4217 currency database.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The currency code to validate.
TYPE:
|
**_
|
Additional keyword arguments (ignored).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The validated ISO 4217 currency code.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
Raised when the currency code is invalid or no value is given. |
Basic(name: str, id_: int | str | None = None)
dataclass
A data class representing basic information.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name associated with the basic information.
TYPE:
|
id_ |
The ID associated with the basic information, defaults to None.
TYPE:
|
Universe(name: str, id_: int | str | None = None, designation: str | None = None)
dataclass
Bases: Basic
A data class representing a universe.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name associated with the basic information.
TYPE:
|
id_ |
The ID associated with the basic information, defaults to None.
TYPE:
|
designation |
The designation of the universe, defaults to None.
TYPE:
|
Role(name: str, id_: int | str | None = None, primary: bool = False)
dataclass
Bases: Basic
A data class representing a role.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name associated with the basic information.
TYPE:
|
id_ |
The ID associated with the basic information, defaults to None.
TYPE:
|
primary |
Indicates if the role is primary, defaults to False.
TYPE:
|
Series(name: str, id_: int | str | None = None, sort_name: str | None = None, volume: int | None = None, format: str | None = None, start_year: int | None = None, issue_count: int | None = None, volume_count: int | None = None, alternative_names: list[AlternativeNames] = list(), language: str | None = None)
dataclass
Bases: Basic, Validations
A data class representing a series with basic information and validations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name associated with the basic information.
TYPE:
|
id_ |
The ID associated with the basic information, defaults to None.
TYPE:
|
sort_name |
The sort name of the series, defaults to None.
TYPE:
|
volume |
The volume of the series, defaults to None.
TYPE:
|
format |
The format of the series, defaults to None.
TYPE:
|
start_year |
The year that the series started in. A 4 digit value.
TYPE:
|
issue_count |
The count of issues.
TYPE:
|
volume_count |
The count of volumes.
TYPE:
|
alternative_names |
list[AlternativeNames]: A list of alternative names for series.
TYPE:
|
language |
The 2-letter ISO code of the language, defaults to None.
TYPE:
|
Static Methods
validate_language(value: str, **_: any) -> str | None: Validates a language value.
Functions
validate_language(value: str, **_: any) -> str | None
staticmethod
Validate a language value.
If the value is empty, it returns None. Otherwise, it strips any leading or trailing whitespace from the value. If the length of the value is 2, it tries to find the language object using the alpha-2 code. Otherwise, it tries to look up the language object using the value. If the language object is not found, it raises a ValueError.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The language value to validate.
TYPE:
|
**_
|
Additional keyword arguments (ignored).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Optional[str]: The validated language code, or None if the value is empty. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
Raised when the language object cannot be found. |
validate_start_year(value: int, **_: any) -> int | None
staticmethod
Validate a start year value.
This method checks if the provided value is a valid four-digit year. If the value is not present, it returns None. If the value is not exactly four digits, it raises a ValueError.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The year value to validate.
TYPE:
|
**_
|
Additional keyword arguments (ignored).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
Optional[int]: The validated year value, or None if the value is not present. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
Raised when the year is not exactly four digits. |
Arc(name: str, id_: int | str | None = None, number: int | None = None)
dataclass
Bases: Basic
A data class representing an arc with basic information.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name associated with the basic information.
TYPE:
|
id_ |
The ID associated with the basic information, defaults to None.
TYPE:
|
number |
The number of the arc, defaults to None.
TYPE:
|
Credit(person: str, role: list[Role], id_: int | None = None)
dataclass
A data class representing a creator credit.
| ATTRIBUTE | DESCRIPTION |
|---|---|
person |
The name of the person associated with the credit.
TYPE:
|
role |
The list of roles associated with the credit.
TYPE:
|
id_ |
The ID associated with the credit, defaults to None.
TYPE:
|
GTIN(upc: int | None = None, isbn: int | None = None)
dataclass
Bases: Validations
A data class representing a GTIN (Global Trade Item Number) with validations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
upc |
The UPC (Universal Product Code) associated with the GTIN, defaults to None.
TYPE:
|
isbn |
The ISBN (International Standard Book Number) associated with the GTIN, defaults to None.
TYPE:
|
Static Methods
validate_upc(value: int, _: any) -> int | None: Validates a UPC (Universal Product Code) value. validate_isbn(value: int, _: any) -> int | None: Validates an ISBN (International Standard Book Number) value.
Functions
validate_isbn(value: int, **_: any) -> int | None
staticmethod
Validate an ISBN (International Standard Book Number) value.
If the value is None or not an instance of int, it returns None. Otherwise, it checks if the length of the ISBN value is greater than the maximum allowed length. If it is, it raises a ValueError.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The ISBN value to validate.
TYPE:
|
**_
|
Additional keyword arguments (ignored).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
Optional[int]: The validated ISBN value, or None if the value is None or not an instance of int. |
validate_upc(value: int, **_: any) -> int | None
staticmethod
Validate a UPC (Universal Product Code) value.
If the value is None or not an instance of int, it returns None. Otherwise, it checks if the length of the UPC value is greater than the maximum allowed length. If it is, it raises a ValueError.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The UPC value to validate.
TYPE:
|
**_
|
Additional keyword arguments (ignored).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
Optional[int]: The validated UPC value, or None if the value is None or not an instance of int. |
Metadata(is_empty: bool = True, info_source: list[InfoSources] | None = None, series: Series | None = None, issue: str | None = None, collection_title: str | None = None, stories: list[Basic] = list(), publisher: Publisher | None = None, cover_date: date | None = None, store_date: date | None = None, prices: list[Price] = list(), gtin: GTIN | None = None, genres: list[Basic] = list(), comments: str | None = None, community_rating: Decimal | None = None, main_character_or_team: str | None = None, review: str | None = None, alternate_series: str | None = None, alternate_number: str | None = None, alternate_count: int | None = None, notes: Notes | None = None, web_link: list[Links] | None = None, manga: str | None = None, black_and_white: bool | None = None, page_count: int | None = None, age_rating: AgeRatings | None = None, story_arcs: list[Arc] = list(), series_group: str | None = None, scan_info: str | None = None, characters: list[Basic] = list(), teams: list[Basic] = list(), locations: list[Basic] = list(), universes: list[Universe] = list(), credits: list[Credit] = list(), reprints: list[Basic] = list(), tags: list[Basic] = list(), pages: list[ImageMetadata] = list(), modified: datetime | None = None)
dataclass
Represents metadata for a comic.
| ATTRIBUTE | DESCRIPTION |
|---|---|
is_empty |
Indicates if the metadata is empty.
TYPE:
|
info_source |
The information source.
TYPE:
|
series |
The series information.
TYPE:
|
issue |
The issue number.
TYPE:
|
collection_title |
The title of the collection.
TYPE:
|
stories |
The list of stories.
TYPE:
|
publisher |
The publisher information.
TYPE:
|
cover_date |
The cover date.
TYPE:
|
store_date |
The store date.
TYPE:
|
prices |
The list of prices.
TYPE:
|
gtin |
The GTIN (Global Trade Item Number).
TYPE:
|
genres |
The list of genres.
TYPE:
|
comments |
The comments.
TYPE:
|
community_rating |
The community rating (0-5, up to 2 decimal places).
TYPE:
|
alternate_series |
The alternate series.
TYPE:
|
alternate_number |
The alternate number.
TYPE:
|
alternate_count |
The count of alternates.
TYPE:
|
notes |
The notes.
TYPE:
|
web_link |
The web link.
TYPE:
|
manga |
The manga information.
TYPE:
|
black_and_white |
Indicates if the comic is black and white.
TYPE:
|
page_count |
The count of pages.
TYPE:
|
age_rating |
The age rating.
TYPE:
|
story_arcs |
The list of story arcs.
TYPE:
|
series_group |
The series group.
TYPE:
|
scan_info |
The scan information.
TYPE:
|
characters |
The list of characters.
TYPE:
|
teams |
The list of teams.
TYPE:
|
locations |
The list of locations.
TYPE:
|
credits |
The list of credits.
TYPE:
|
reprints |
The list of reprints.
TYPE:
|
tags |
The list of tags.
TYPE:
|
pages |
The list of pages.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__post_init__ |
Initializes the metadata object. |
overlay |
Overlays a metadata object on this one. |
overlay_credits |
Overlays the credits from a new metadata object. |
set_default_page_list |
Sets a default page list. |
get_archive_page_index |
Gets the archive page index for a given displayed page number. |
get_cover_page_index_list |
Gets a list of archive page indices of cover pages. |
_existing_credit |
Checks if a credit with the given creator already exists. |
_role_exists |
Checks if a role already exists in the old roles list. |
add_credit |
Adds a new credit to the metadata. |
__str__ |
Returns a string representation of the metadata. |
Example
metadata = Metadata(is_empty=True)
metadata.overlay(new_md)
print(metadata)
Functions
__post_init__() -> None
Execute the post-initialization process for a Metadata instance.
The method iterates over the attributes of the Metadata object and checks if any attribute has a non-empty value, excluding the "is_empty" attribute. If a non-empty value is found, the "is_empty" attribute is set to False and the iteration is stopped.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The Metadata instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Example
metadata = Metadata()
metadata.__post_init__()
print(metadata.is_empty) # Output: False
__str__() -> str
Returns a formatted string representation of the Metadata object.
This improved version provides a more readable and organized display of the metadata, grouping related fields and handling different data types appropriately.
add_credit(new_credit: Credit) -> None
Add a new credit to the Metadata.
If a credit with the same person already exists, the roles from the new credit are added to the existing credit. If the person is new, the new credit is appended to the list of credits.
| PARAMETER | DESCRIPTION |
|---|---|
new_credit
|
The new credit to add to the Metadata.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
get_archive_page_index(pagenum: int) -> int
Convert the displayed page number to the page index of the file in the archive.
The method takes a displayed page number and returns the corresponding page index in the archive. If the displayed page number is within the range of the available pages, the "Image" attribute of the corresponding page in the "pages" attribute of the Metadata object is returned as an integer. If the displayed page number is out of range, 0 is returned.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The Metadata object.
TYPE:
|
pagenum
|
The displayed page number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The page index in the archive.
TYPE:
|
Example
metadata = Metadata()
metadata.pages = [ImageMetadata(Image=0), ImageMetadata(Image=1), ImageMetadata(Image=2)]
index = metadata.get_archive_page_index(1)
print(index) # Output: 1
get_cover_page_index_list() -> list[int]
Return a list of archive page indices of cover pages.
The method iterates over the pages in the Metadata object and checks if a page is marked as a front cover by having a "Type" attribute equal to PageType.FrontCover. If a front cover page is found, its "Image" attribute is added to the coverlist. If no front cover pages are found, the coverlist is initialized with a single element of 0.
| RETURNS | DESCRIPTION |
|---|---|
list[int]
|
list[int]: The list of archive page indices of cover pages. |
Example
metadata = Metadata()
metadata.pages = [ImageMetadata(Image=0, Type=PageType.FrontCover),ImageMetadata(Image=1), ImageMetadata(Image=2)]
cover_indices = metadata.get_cover_page_index_list()
print(cover_indices) # Output: [0]
overlay(new_md: Metadata) -> None
Overlays a metadata object on this one.
The method assigns non-None values from the new metadata object to the corresponding attributes of the current metadata object. If a value is an empty string, it is assigned as None. The "is_empty" attribute of the current metadata object is set to False if the new metadata object is not empty.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The current metadata object.
TYPE:
|
new_md
|
The new metadata object to overlay.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Example
metadata = Metadata()
new_metadata = Metadata(series="Series 1", issue="Issue 1")
metadata.overlay(new_metadata)
print(metadata.series) # Output: "Series 1"
print(metadata.issue) # Output: "Issue 1"
overlay_credits(new_credits: list[Credit]) -> None
Overlays the credits from a new metadata object on the current metadata object.
The method iterates over the new credits and removes any credit role if the person is blank. If the person is not blank, the "primary" attribute of the credit is set based on the presence of the "primary" key in the credit dictionary. The credit is then added to the current metadata object using the "add_credit" method.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The current metadata object.
TYPE:
|
new_credits
|
The list of new credits to overlay.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Example
metadata = Metadata()
new_credits = [Credit(person="John Doe", role="Writer")]
metadata.overlay_credits(new_credits)
print(metadata.credits) # Output: [Credit(person="John Doe", role="Writer")]
set_default_page_list(count: int) -> None
Generate a default page list for the Metadata object.
The method creates a default page list with the specified count. Each page is represented by an ImageMetadata object with the "Image" attribute set to the corresponding index. The first page is marked as the front cover by setting the "Type" attribute to PageType.FrontCover. The generated page list is appended to the "pages" attribute of the Metadata object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The Metadata object.
TYPE:
|
count
|
The count of pages to generate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Example
metadata = Metadata()
metadata.set_default_page_list(5)
print(metadata.pages)
# Output: [ImageMetadata(Image=0, Type=PageType.FrontCover),
# ImageMetadata(Image=1), ImageMetadata(Image=2), ImageMetadata(Image=3),
# ImageMetadata(Image=4)]
validate_community_rating(value: Decimal | None) -> Decimal | None
staticmethod
Validate and normalise a community rating value.
Checks that the value is in the range 0-5 (inclusive) and rounds it to
2 decimal places, matching the Rating type defined in ComicInfo v2.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The rating value to validate, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Decimal | None
|
The validated value quantised to 2 decimal places, or |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the value is outside the range 0-5. |