Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor _get_id_from_comic_info #164

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions metrontagger/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Role,
Series,
)
from darkseid.utils import get_issue_id_from_note
from imagehash import ImageHash, hex_to_hash, phash
from mokkari.exceptions import ApiError
from PIL import Image
Expand Down Expand Up @@ -233,36 +234,26 @@ def _get_id_from_metron_info(md: Metadata) -> None | tuple[InfoSource, int]:

@staticmethod
def _get_id_from_comic_info(md: Metadata) -> None | tuple[InfoSource, int]:
def _extract_id_str(notes: str, keyword: str) -> str:
return notes.split(keyword)[1].split("]")[0].strip()
if md.notes is None or not md.notes.comic_rack:
return None

# If `Notes` element doesn't exist let's bail.
if md.notes is None:
res = get_issue_id_from_note(md.notes.comic_rack)
if res is None:
return None

lower_notes = md.notes.comic_rack.lower()

if "metrontagger" in lower_notes:
source = InfoSource.metron
id_str = _extract_id_str(md.notes.comic_rack, "issue_id:")
elif "comictagger" in lower_notes:
if "metron" in lower_notes:
source = InfoSource.metron
elif "comic vine" in lower_notes:
source = InfoSource.comic_vine
else:
source = InfoSource.unknown
id_str = _extract_id_str(md.notes.comic_rack, "Issue ID")
else:
source_map = {"Metron": InfoSource.metron, "Comic Vine": InfoSource.comic_vine}

src = source_map.get(res["source"])
if src is None:
return None

try:
id_ = int(id_str)
id_ = int(res["id"])
except ValueError:
LOGGER.exception("Comic has invalid id: %s #%s", md.series.name, md.issue)
return None

return source, id_
return src, id_

def _process_file(self: Talker, fn: Path, interactive: bool) -> tuple[int | None, bool]: # noqa: PLR0912 PLR0911
"""Process a comic file for metadata.
Expand Down
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ imagehash = "^4.3.1"
pandas = "^2.2.1"
comicfn2dict = "^0.2.4"
tqdm = "^4.66.4"
darkseid = "^5.1.0"
darkseid = "^5.1.1"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.6.2"
Expand Down
Loading