Change issue id and series id to strings

This commit is contained in:
Timmy Welch 2022-12-23 00:09:19 -08:00
parent 92fa4a874b
commit 9f00af4bba
No known key found for this signature in database
15 changed files with 55 additions and 65 deletions

View File

@ -78,7 +78,7 @@ class GenericMetadata:
is_empty: bool = True
tag_origin: str | None = None
issue_id: int | None = None
issue_id: str | None = None
series: str | None = None
issue: str | None = None

View File

@ -45,7 +45,7 @@ class CLI:
self.talker_api = talker_api
self.batch_mode = False
def actual_issue_data_fetch(self, issue_id: int) -> GenericMetadata:
def actual_issue_data_fetch(self, issue_id: str) -> GenericMetadata:
# now get the particular issue data
try:
ct_md = self.talker_api.fetch_comic_data(issue_id)

View File

@ -91,7 +91,7 @@ class CoverImageWidget(QtWidgets.QWidget):
self.current_pixmap = QtGui.QPixmap()
self.comic_archive: ComicArchive | None = None
self.issue_id: int | None = None
self.issue_id: str = ""
self.issue_url: str | None = None
self.url_list: list[str] = []
if self.page_loader is not None:
@ -116,7 +116,7 @@ class CoverImageWidget(QtWidgets.QWidget):
def reset_widget(self) -> None:
self.comic_archive = None
self.issue_id = None
self.issue_id = ""
self.issue_url = None
self.url_list = []
if self.page_loader is not None:
@ -160,7 +160,7 @@ class CoverImageWidget(QtWidgets.QWidget):
self.imageCount = 1
self.update_content()
def set_issue_details(self, issue_id: int, url_list: list[str]) -> None:
def set_issue_details(self, issue_id: str, url_list: list[str]) -> None:
if self.mode == CoverImageWidget.AltCoverMode:
self.reset_widget()
self.update_content()

View File

@ -237,7 +237,7 @@ class IssueIdentifier:
def get_issue_cover_match_score(
self,
issue_id: int,
issue_id: str,
primary_img_url: str,
primary_thumb_url: str,
alt_urls: list[str],
@ -254,7 +254,7 @@ class IssueIdentifier:
try:
url_image_data = ImageFetcher(self.options.runtime_config.user_cache_dir).fetch(
primary_thumb_url, blocking=True
primary_img_url, blocking=True
)
except ImageFetcherException as e:
self.log_msg("Network issue while fetching cover image from Comic Vine. Aborting...")
@ -390,13 +390,8 @@ class IssueIdentifier:
date_approved = True
# remove any series that starts after the issue year
if (
keys["year"] is not None
and str(keys["year"]).isdigit()
and item["start_year"] is not None
and str(item["start_year"]).isdigit()
):
if int(keys["year"]) < int(item["start_year"]):
if keys["year"] is not None and item["start_year"] is not None:
if keys["year"] < item["start_year"]:
date_approved = False
for name in [item["name"], *item["aliases"]]:
@ -420,16 +415,13 @@ class IssueIdentifier:
# now sort the list by name length
series_second_round_list.sort(key=lambda x: len(x["name"]), reverse=False)
# build a list of series IDs
series_id_list = []
for series in series_second_round_list:
series_id_list.append(series["id"])
series_by_id = {series["id"]: series for series in series_second_round_list}
issue_list = None
try:
if len(series_id_list) > 0:
if len(series_by_id) > 0:
issue_list = self.talker_api.fetch_issues_by_series_issue_num_and_year(
series_id_list, keys["issue_number"], keys["year"]
list(series_by_id.keys()), keys["issue_number"], keys["year"]
)
except TalkerError as e:
self.log_msg(f"Issue with while searching for series details. Aborting...\n{e}")
@ -440,11 +432,10 @@ class IssueIdentifier:
shortlist = []
# now re-associate the issues and series
# is this really needed?
for issue in issue_list:
for series in series_second_round_list:
if series["id"] == issue["series"]["id"]:
shortlist.append((series, issue))
break
if issue["series"]["id"] in series_by_id:
shortlist.append((series_by_id[issue["series"]["id"]], issue))
if keys["year"] is None:
self.log_msg(f"Found {len(shortlist)} series that have an issue #{keys['issue_number']}")
@ -501,7 +492,6 @@ class IssueIdentifier:
"publisher": None,
"image_url": image_url,
"thumb_url": thumb_url,
# "page_url": page_url,
"alt_image_urls": alt_urls,
"description": issue["description"],
}

View File

@ -44,7 +44,7 @@ class IssueSelectionWindow(QtWidgets.QDialog):
parent: QtWidgets.QWidget,
options: settngs.Namespace,
talker_api: ComicTalker,
series_id: int,
series_id: str,
issue_number: str,
) -> None:
super().__init__(parent)
@ -70,7 +70,7 @@ class IssueSelectionWindow(QtWidgets.QDialog):
)
self.series_id = series_id
self.issue_id: int | None = None
self.issue_id: str = ""
self.options = options
self.talker_api = talker_api
self.url_fetch_thread = None
@ -81,7 +81,7 @@ class IssueSelectionWindow(QtWidgets.QDialog):
else:
self.issue_number = issue_number
self.initial_id: int | None = None
self.initial_id: str = ""
self.perform_query()
self.twList.resizeColumnsToContents()

View File

@ -12,8 +12,8 @@ class IssueResult(TypedDict):
cv_issue_count: int
url_image_hash: int
issue_title: str
issue_id: int # int?
series_id: int # int?
issue_id: str
series_id: str
month: int | None
year: int | None
publisher: str | None

View File

@ -118,7 +118,7 @@ class SeriesSelectionWindow(QtWidgets.QDialog):
) -> None:
super().__init__(parent)
uic.loadUi(ui_path / "serieselectionwindow.ui", self)
uic.loadUi(ui_path / "seriesselectionwindow.ui", self)
self.imageWidget = CoverImageWidget(
self.imageContainer, CoverImageWidget.URLMode, options.runtime_config.user_cache_dir, talker_api
@ -141,10 +141,10 @@ class SeriesSelectionWindow(QtWidgets.QDialog):
self.options = options
self.series_name = series_name
self.issue_number = issue_number
self.issue_id: int | None = None
self.issue_id: str = ""
self.year = year
self.issue_count = issue_count
self.series_id = 0
self.series_id: str = ""
self.comic_archive = comic_archive
self.immediate_autoselect = autoselect
self.cover_index_list = cover_index_list

View File

@ -58,7 +58,7 @@ from comictaggerlib.pagebrowser import PageBrowserWindow
from comictaggerlib.pagelisteditor import PageListEditor
from comictaggerlib.renamewindow import RenameWindow
from comictaggerlib.resulttypes import IssueResult, MultipleMatch, OnlineMatchResults
from comictaggerlib.serieselectionwindow import SeriesSelectionWindow
from comictaggerlib.seriesselectionwindow import SeriesSelectionWindow
from comictaggerlib.settingswindow import SettingsWindow
from comictaggerlib.ui import ui_path
from comictaggerlib.ui.qtutils import center_window_on_parent, reduce_widget_font_size
@ -1073,7 +1073,7 @@ Have fun!
try:
new_metadata = self.talker_api.fetch_comic_data(
issue_id=selector.issue_id or 0, series_id=selector.series_id, issue_number=selector.issue_number
issue_id=selector.issue_id, series_id=selector.series_id, issue_number=selector.issue_number
)
except TalkerError as e:
QtWidgets.QApplication.restoreOverrideCursor()

View File

@ -77,14 +77,14 @@ class ComicCacher:
cur.execute(
"CREATE TABLE SeriesSearchCache("
+ "search_term TEXT,"
+ "id INT NOT NULL,"
+ "id TEXT NOT NULL,"
+ "timestamp DATE DEFAULT (datetime('now','localtime')),"
+ "source_name TEXT NOT NULL)"
)
cur.execute(
"CREATE TABLE Series("
+ "id INT NOT NULL,"
+ "id TEXT NOT NULL,"
+ "name TEXT,"
+ "publisher TEXT,"
+ "count_of_issues INT,"
@ -99,8 +99,8 @@ class ComicCacher:
cur.execute(
"CREATE TABLE Issues("
+ "id INT NOT NULL,"
+ "series_id INT,"
+ "id TEXT NOT NULL,"
+ "series_id TEXT,"
+ "name TEXT,"
+ "issue_number TEXT,"
+ "image_url TEXT,"
@ -248,7 +248,7 @@ class ComicCacher:
}
self.upsert(cur, "issues", data)
def get_series_info(self, series_id: int, source_name: str, purge: bool = True) -> ComicSeries | None:
def get_series_info(self, series_id: str, source_name: str, purge: bool = True) -> ComicSeries | None:
result: ComicSeries | None = None
con = lite.connect(self.db_file)
@ -286,7 +286,7 @@ class ComicCacher:
return result
def get_series_issues_info(self, series_id: int, source_name: str) -> list[ComicIssue]:
def get_series_issues_info(self, series_id: str, source_name: str) -> list[ComicIssue]:
# get_series_info should only fail if someone is doing something weird
series = self.get_series_info(series_id, source_name, False) or ComicSeries(id=series_id, name="")
con = lite.connect(self.db_file)

View File

@ -12,7 +12,7 @@ class ComicSeries(TypedDict, total=False):
aliases: list[str]
count_of_issues: int
description: str
id: Required[int]
id: Required[str]
image_url: str
name: Required[str]
publisher: str
@ -23,7 +23,7 @@ class ComicIssue(TypedDict, total=False):
aliases: list[str]
cover_date: str
description: str
id: int
id: str
image_url: str
image_thumb_url: str
issue_number: Required[str]

View File

@ -186,12 +186,12 @@ class ComicTalker:
"""
raise NotImplementedError
def fetch_issues_by_series(self, series_id: int) -> list[ComicIssue]:
def fetch_issues_by_series(self, series_id: str) -> list[ComicIssue]:
"""Expected to return a list of issues with a given series ID"""
raise NotImplementedError
def fetch_comic_data(
self, issue_id: int | None = None, series_id: int | None = None, issue_number: str = ""
self, issue_id: str | None = None, series_id: str | None = None, issue_number: str = ""
) -> GenericMetadata:
"""
This function should return an instance of GenericMetadata for a single issue.
@ -208,7 +208,7 @@ class ComicTalker:
raise NotImplementedError
def fetch_issues_by_series_issue_num_and_year(
self, series_id_list: list[int], issue_number: str, year: int | None
self, series_id_list: list[str], issue_number: str, year: int | None
) -> list[ComicIssue]:
"""
This function should return a single issue for each series id in

View File

@ -295,7 +295,7 @@ class ComicVineTalker(ComicTalker):
aliases=aliases.splitlines(),
count_of_issues=record.get("count_of_issues", 0),
description=record.get("description", ""),
id=record["id"],
id=str(record["id"]),
image_url=image_url,
name=record["name"],
publisher=pub_name,
@ -350,7 +350,7 @@ class ComicVineTalker(ComicTalker):
aliases=record["aliases"].split("\n") if record["aliases"] else [],
cover_date=record.get("cover_date", ""),
description=record.get("description", ""),
id=record["id"],
id=str(record["id"]),
image_url=image_url,
image_thumb_url=image_thumb_url,
issue_number=record["issue_number"],
@ -464,20 +464,20 @@ class ComicVineTalker(ComicTalker):
# Get issue or series information
def fetch_comic_data(
self, issue_id: int | None = None, series_id: int | None = None, issue_number: str = ""
self, issue_id: str | None = None, series_id: str | None = None, issue_number: str = ""
) -> GenericMetadata:
comic_data = GenericMetadata()
if issue_id:
comic_data = self.fetch_issue_data_by_issue_id(issue_id)
elif issue_number and series_id:
comic_data = self.fetch_issue_data(series_id, issue_number)
comic_data = self.fetch_issue_data(int(series_id), issue_number)
return comic_data
def fetch_series_data(self, series_id: int) -> ComicSeries:
# before we search online, look in our cache, since we might already have this info
cvc = ComicCacher(self.cache_folder, self.version)
cached_series_result = cvc.get_series_info(series_id, self.source_name)
cached_series_result = cvc.get_series_info(str(series_id), self.source_name)
if cached_series_result is not None:
return cached_series_result
@ -498,12 +498,12 @@ class ComicVineTalker(ComicTalker):
return formatted_series_results[0]
def fetch_issues_by_series(self, series_id: int) -> list[ComicIssue]:
def fetch_issues_by_series(self, series_id: str) -> list[ComicIssue]:
# before we search online, look in our cache, since we might already have this info
cvc = ComicCacher(self.cache_folder, self.version)
cached_series_issues_result = cvc.get_series_issues_info(series_id, self.source_name)
series_data = self.fetch_series_data(series_id)
series_data = self.fetch_series_data(int(series_id))
if len(cached_series_issues_result) == series_data["count_of_issues"]:
return cached_series_issues_result
@ -543,7 +543,7 @@ class ComicVineTalker(ComicTalker):
return formatted_series_issues_result
def fetch_issues_by_series_issue_num_and_year(
self, series_id_list: list[int], issue_number: str, year: str | int | None
self, series_id_list: list[str], issue_number: str, year: str | int | None
) -> list[ComicIssue]:
series_filter = ""
for vid in series_id_list:
@ -586,7 +586,7 @@ class ComicVineTalker(ComicTalker):
return formatted_filtered_issues_result
def fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadata:
issues_list_results = self.fetch_issues_by_series(series_id)
issues_list_results = self.fetch_issues_by_series(str(series_id))
# Loop through issue list to find the required issue info
f_record = None
@ -610,10 +610,10 @@ class ComicVineTalker(ComicTalker):
return self.fetch_issue_data_by_issue_id(f_record["id"])
return GenericMetadata()
def fetch_issue_data_by_issue_id(self, issue_id: int) -> GenericMetadata:
def fetch_issue_data_by_issue_id(self, issue_id: str) -> GenericMetadata:
# before we search online, look in our cache, since we might already have this info
cvc = ComicCacher(self.cache_folder, self.version)
cached_issues_result = cvc.get_issue_info(issue_id, self.source_name)
cached_issues_result = cvc.get_issue_info(int(issue_id), self.source_name)
if cached_issues_result and cached_issues_result["complete"]:
return talker_utils.map_comic_issue_to_metadata(
@ -633,7 +633,7 @@ class ComicVineTalker(ComicTalker):
cv_issues = self.format_issue_results([issue_results], True)
# Due to issue not returning publisher, fetch the series.
cv_issues[0]["series"] = self.fetch_series_data(cv_issues[0]["series"]["id"])
cv_issues[0]["series"] = self.fetch_series_data(int(cv_issues[0]["series"]["id"]))
cvc.add_series_issues_info(self.source_name, cv_issues)

View File

@ -8,7 +8,7 @@ search_results = [
comictalker.resulttypes.ComicSeries(
count_of_issues=1,
description="this is a description",
id=1,
id="1",
image_url="https://test.org/image/1",
name="test",
publisher="test",
@ -18,7 +18,7 @@ search_results = [
comictalker.resulttypes.ComicSeries(
count_of_issues=1,
description="this is a description",
id=2,
id="2",
image_url="https://test.org/image/2",
name="test 2",
publisher="test",

View File

@ -162,14 +162,14 @@ comic_issue_result = ComicIssue(
aliases=cv_issue_result["results"]["aliases"] or [],
cover_date=cv_issue_result["results"]["cover_date"],
description=cv_issue_result["results"]["description"],
id=cv_issue_result["results"]["id"],
id=str(cv_issue_result["results"]["id"]),
image_url=cv_issue_result["results"]["image"]["super_url"],
image_thumb_url=cv_issue_result["results"]["image"]["thumb_url"],
issue_number=cv_issue_result["results"]["issue_number"],
name=cv_issue_result["results"]["name"],
site_detail_url=cv_issue_result["results"]["site_detail_url"],
series=ComicSeries(
id=cv_issue_result["results"]["volume"]["id"],
id=str(cv_issue_result["results"]["volume"]["id"]),
name=cv_issue_result["results"]["volume"]["name"],
aliases=[],
count_of_issues=0,
@ -191,7 +191,7 @@ date = utils.parse_date_str(cv_issue_result["results"]["cover_date"])
cv_md = comicapi.genericmetadata.GenericMetadata(
is_empty=False,
tag_origin="Comic Vine",
issue_id=cv_issue_result["results"]["id"],
issue_id=str(cv_issue_result["results"]["id"]),
series=cv_issue_result["results"]["volume"]["name"],
issue=cv_issue_result["results"]["issue_number"],
title=cv_issue_result["results"]["name"],

View File

@ -63,8 +63,8 @@ def test_search(cbz, options, comicvine_api):
"alt_image_urls": [],
"cv_issue_count": testing.comicvine.cv_volume_result["results"]["count_of_issues"],
"issue_title": testing.comicvine.cv_issue_result["results"]["name"],
"issue_id": testing.comicvine.cv_issue_result["results"]["id"],
"series_id": testing.comicvine.cv_volume_result["results"]["id"],
"issue_id": str(testing.comicvine.cv_issue_result["results"]["id"]),
"series_id": str(testing.comicvine.cv_volume_result["results"]["id"]),
"month": testing.comicvine.date[1],
"year": testing.comicvine.date[2],
"publisher": testing.comicvine.cv_volume_result["results"]["publisher"]["name"],