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

comicfn2dict #97

Merged
merged 3 commits into from
Feb 29, 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
28 changes: 16 additions & 12 deletions metrontagger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from urllib.parse import quote_plus

from darkseid.filename import FileNameParser
from comicfn2dict import comicfn2dict


def cleanup_string(path_name: str | None) -> str | None:
Expand All @@ -24,27 +24,31 @@ def cleanup_string(path_name: str | None) -> str | None:

def create_query_params(filename: Path) -> dict[str, str]:
"""Function to create a diction of values based on the provided filename"""
fnp = FileNameParser()
fnp.parse_filename(filename)
metadata: dict[str, str | tuple[str, ...]] = comicfn2dict(filename, verbose=0)

# TODO: Should probably check if there is a 'series' key.
# Remove hyphen when searching for series name
fixed_txt: str = fnp.series.replace(" - ", " ")
series_word_list: list[str] = fixed_txt.split()
series_string: str = " ".join(series_word_list).strip()
series_string: str = metadata["series"].replace(" - ", " ").strip()

# If there isn't an issue number, let's assume it's "1".
number: str = quote_plus(fnp.issue.encode("utf-8")) if fnp.issue else "1"
number: str = quote_plus(metadata["issue"].encode("utf-8")) if "issue" in metadata else "1"

# Strip any leading zeros from the issue number for the API to correctly match.
number = number.lstrip("0")

# Handle issues with #½
if number == "0.5":
if number == ".5":
number = "½"

params = {
"series_name": series_string,
"number": number,
}
if fnp.volume:
params["series_volume"] = fnp.volume
if fnp.year:
params["cover_year"] = fnp.year
# TODO: Probably want to remove these from the API call and use the info instead to find the issue
# from the return results.
if "volume" in metadata:
params["series_volume"] = metadata["volume"]
if "year" in metadata:
params["cover_year"] = metadata["year"]

return params
Loading
Loading