From 9aa29f144555fc7b7758ebb9f2627075c18227a0 Mon Sep 17 00:00:00 2001 From: Mizaki Date: Fri, 14 Oct 2022 01:10:46 +0100 Subject: [PATCH] Merge fetch_issue_data and fetch_volume_data to fetch_comic_data. --- comictaggerlib/cli.py | 2 +- comictaggerlib/taggerwindow.py | 11 ++--------- comictalker/comictalker.py | 25 ++++++------------------- comictalker/talkerbase.py | 8 ++------ comictalker/talkers/comicvine.py | 11 +++++++++++ 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index c575a2a..57eb7dd 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -43,7 +43,7 @@ def actual_issue_data_fetch( ) -> GenericMetadata: # now get the particular issue data try: - ct_md = talker_api.fetch_issue_data(match["volume_id"], match["issue_number"]) + ct_md = talker_api.fetch_comic_data(match["volume_id"], match["issue_number"]) except TalkerError as e: logger.exception(f"Error retrieving issue details. Save aborted.\n{e}") return GenericMetadata() diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index 8ec1d23..4eb2f35 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -1070,11 +1070,7 @@ Have fun! self.form_to_metadata() try: - # Does the source support issue level data? - if self.talker_api.static_options.has_issues: - new_metadata = self.talker_api.fetch_issue_data(selector.volume_id, selector.issue_number) - else: - new_metadata = self.talker_api.fetch_volume_data(selector.volume_id) + new_metadata = self.talker_api.fetch_comic_data(selector.volume_id, selector.issue_number) except TalkerError as e: QtWidgets.QApplication.restoreOverrideCursor() QtWidgets.QMessageBox.critical( @@ -1674,10 +1670,7 @@ Have fun! QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CursorShape.WaitCursor)) try: - if self.talker_api.static_options.has_issues: - ct_md = self.talker_api.fetch_issue_data(match["volume_id"], match["issue_number"]) - else: - ct_md = self.talker_api.fetch_volume_data(match["volume_id"]) + ct_md = self.talker_api.fetch_comic_data(match["volume_id"], match["issue_number"]) except TalkerError as e: logger.exception(f"Save aborted.\n{e}") diff --git a/comictalker/comictalker.py b/comictalker/comictalker.py index 82b86be..4b0fb40 100644 --- a/comictalker/comictalker.py +++ b/comictalker/comictalker.py @@ -92,17 +92,17 @@ class ComicTalker: "The source has not implemented: 'search_for_series'", ) - # Master function to fetch series data (i.e for sources without issue level details) - def fetch_volume_data(self, series_id: int) -> GenericMetadata: + # Get issue or volume information + def fetch_comic_data(self, series_id: int, issue_number: str = "") -> GenericMetadata: try: - series_result = self.talker.fetch_volume_data(series_id) - return series_result + comic_data = self.talker.fetch_comic_data(series_id, issue_number) + return comic_data except NotImplementedError: - logger.warning(f"{self.talker.source_details.name} has not implemented: 'fetch_volume_data'") + logger.warning(f"{self.talker.source_details.name} has not implemented: 'fetch_comic_data'") raise TalkerError( self.talker.source_details.name, 4, - "The source has not implemented: 'fetch_volume_data'", + "The source has not implemented: 'fetch_comic_data'", ) # Master function to get issues in a series/volume @@ -118,19 +118,6 @@ class ComicTalker: "The source has not implemented: 'fetch_issues_by_volume'", ) - # Master function to get issue information - def fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadata: - try: - issue_result = self.talker.fetch_issue_data(series_id, issue_number) - return issue_result - except NotImplementedError: - logger.warning(f"{self.talker.source_details.name} has not implemented: 'fetch_issue_data'") - raise TalkerError( - self.talker.source_details.name, - 4, - "The source has not implemented: 'fetch_issue_data'", - ) - # For CLI def fetch_issue_data_by_issue_id(self, issue_id: int) -> GenericMetadata: try: diff --git a/comictalker/talkerbase.py b/comictalker/talkerbase.py index 2a5036e..50e2cd9 100644 --- a/comictalker/talkerbase.py +++ b/comictalker/talkerbase.py @@ -187,16 +187,12 @@ class TalkerBase: ) -> list[ComicVolume]: raise NotImplementedError - # Get volume/series information - def fetch_volume_data(self, series_id: int) -> GenericMetadata: - raise NotImplementedError - # Get issues in a series/volume def fetch_issues_by_volume(self, series_id: int) -> list[ComicIssue]: raise NotImplementedError - # Get issue information - def fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadata: + # Get issue or volume information + def fetch_comic_data(self, series_id: int, issue_number: str = "") -> GenericMetadata: raise NotImplementedError # For CLI diff --git a/comictalker/talkers/comicvine.py b/comictalker/talkers/comicvine.py index e2c0738..148baea 100644 --- a/comictalker/talkers/comicvine.py +++ b/comictalker/talkers/comicvine.py @@ -553,6 +553,17 @@ class ComicVineTalker(TalkerBase): return self.map_cv_volume_data_to_metadata(volume_results) + # Get issue or volume information + def fetch_comic_data(self, series_id: int, issue_number: str = "") -> GenericMetadata: + comic_data = GenericMetadata() + if self.source_details.static_options.has_issues and issue_number: + comic_data = self.fetch_issue_data(series_id, issue_number) + else: + # Only retrieve the volume data + comic_data = self.fetch_volume_data(series_id) + + return comic_data + def fetch_partial_volume_data(self, series_id: int) -> ComicVolume: # before we search online, look in our cache, since we might already have this info