Add supports_credit_role to metadata plugins

This commit is contained in:
Timmy Welch 2023-12-17 21:36:02 -08:00
parent ae5e246180
commit fd868d9596
5 changed files with 38 additions and 0 deletions

View File

@ -72,6 +72,9 @@ class CoMet(Metadata):
"year",
}
def supports_credit_role(self, role: str) -> bool:
return role.casefold() in self._get_parseable_credits()
def supports_metadata(self, archive: Archiver) -> bool:
return archive.supports_files()
@ -123,6 +126,18 @@ class CoMet(Metadata):
def name(self) -> str:
return "Comic Metadata (CoMet)"
@classmethod
def _get_parseable_credits(cls) -> list[str]:
parsable_credits: list[str] = []
parsable_credits.extend(cls._writer_synonyms)
parsable_credits.extend(cls._penciller_synonyms)
parsable_credits.extend(cls._inker_synonyms)
parsable_credits.extend(cls._colorist_synonyms)
parsable_credits.extend(cls._letterer_synonyms)
parsable_credits.extend(cls._cover_synonyms)
parsable_credits.extend(cls._editor_synonyms)
return parsable_credits
def _metadata_from_bytes(self, string: bytes) -> GenericMetadata:
tree = ET.ElementTree(ET.fromstring(string))
return self._convert_xml_to_metadata(tree)

View File

@ -104,6 +104,9 @@ class ComicBookInfo(Metadata):
"year",
}
def supports_credit_role(self, role: str) -> bool:
return True
def supports_metadata(self, archive: Archiver) -> bool:
return archive.supports_comment()

View File

@ -88,6 +88,9 @@ class ComicRack(Metadata):
"year",
}
def supports_credit_role(self, role: str) -> bool:
return role.casefold() in self._get_parseable_credits()
def supports_metadata(self, archive: Archiver) -> bool:
return True
@ -123,6 +126,18 @@ class ComicRack(Metadata):
def name(self) -> str:
return "Comic Rack"
@classmethod
def _get_parseable_credits(cls) -> list[str]:
parsable_credits: list[str] = []
parsable_credits.extend(cls._writer_synonyms)
parsable_credits.extend(cls._penciller_synonyms)
parsable_credits.extend(cls._inker_synonyms)
parsable_credits.extend(cls._colorist_synonyms)
parsable_credits.extend(cls._letterer_synonyms)
parsable_credits.extend(cls._cover_synonyms)
parsable_credits.extend(cls._editor_synonyms)
return parsable_credits
def _metadata_from_bytes(self, string: bytes) -> GenericMetadata:
root = ET.fromstring(string)
return self._convert_xml_to_metadata(root)

View File

@ -66,6 +66,9 @@ class Metadata:
"cover_image",
}
def supports_credit_role(self, role: str) -> bool:
return False
def supports_metadata(self, archive: Archiver) -> bool:
"""
Checks the given archive for the ability to save this metadata style.

View File

@ -1208,6 +1208,8 @@ class TaggerWindow(QtWidgets.QMainWindow):
for credit in credit_attributes:
widget_enabled = credit[0] in enabled
widget = self.twCredits.item(r, credit[1])
if credit[0] == "credits.role":
widget_enabled = widget_enabled and style.supports_credit_role(str(widget.text()))
enable_widget(widget, widget_enabled)
def update_metadata_style_tweaks(self) -> None: