After second merge.

This commit is contained in:
Mizaki 2022-10-06 00:34:32 +01:00
parent 21873d3830
commit 6a98afb89c
5 changed files with 35 additions and 18 deletions

View File

@ -167,7 +167,7 @@ def post_process_matches(
display_match_set_for_choice(label, match_set, opts, settings, talker_api)
def cli_mode(opts: argparse.Namespace, settings: ComicTaggerSettings) -> None:
def cli_mode(opts: argparse.Namespace, settings: ComicTaggerSettings, talker_api: ComicTalker) -> None:
if len(opts.file_list) < 1:
logger.error("You must specify at least one filename. Use the -h option for more info")
return
@ -175,7 +175,7 @@ def cli_mode(opts: argparse.Namespace, settings: ComicTaggerSettings) -> None:
match_results = OnlineMatchResults()
for f in opts.file_list:
process_file_cli(f, opts, settings, match_results)
process_file_cli(f, opts, settings, talker_api, match_results)
sys.stdout.flush()
post_process_matches(match_results, opts, settings, talker_api)

View File

@ -18,7 +18,7 @@ from __future__ import annotations
import logging
from typing import Any, Callable
from typing_extensions import Required, Type, TypedDict
from typing_extensions import Required, TypedDict
from comicapi.genericmetadata import GenericMetadata
from comictalker.resulttypes import ComicIssue, ComicVolume
@ -66,7 +66,7 @@ class SourceSettingsOptions(TypedDict):
text: Required[str] # Display text i.e "Remove HTML tables"
help_text: str # Tooltip text i.e "Enabling this will remove HTML tables from the description."
hidden: Required[bool] # To hide an option from the settings menu.
type: Required[Type]
type: Required[type[bool] | type[int] | type[str]]
value: Any

View File

@ -40,6 +40,7 @@ from comictalker.talkerbase import (
SourceSettingsOptions,
SourceStaticOptions,
TalkerBase,
TalkerDataError,
TalkerNetworkError,
)
@ -58,7 +59,6 @@ class CVTypeID:
Issue = "4000"
class CVImage(TypedDict, total=False):
icon_url: str
medium_url: str
@ -91,6 +91,7 @@ class CVCredits(TypedDict):
name: str
site_detail_url: str
class CVPersonCredits(TypedDict):
api_detail_url: str
id: int
@ -190,6 +191,7 @@ class CVIssueDetailResults(TypedDict):
class ComicVineTalker(TalkerBase):
def __init__(self, series_match_thresh: int = 90) -> None:
super().__init__()
self.source_details = source_details = SourceDetails(
name="Comic Vine",
ident="comicvine",
@ -258,16 +260,20 @@ class ComicVineTalker(TalkerBase):
),
},
)
# Identity name for the information source
self.source_name = self.source_details.id
self.source_name_friendly = self.source_details.name
# Overwrite any source_details.options that have saved settings
source_settings = ComicTaggerSettings.get_source_settings(
self.source_name, self.source_details.settings_options
)
if not source_settings:
# No saved settings, do something?
...
self.wait_for_rate_limit = source_details.settings_options["wait_on_ratelimit"]["value"]
self.wait_for_rate_limit_time = source_details.settings_options["ratelimit_waittime"]["value"]
@ -276,6 +282,14 @@ class ComicVineTalker(TalkerBase):
self.api_key = source_details.settings_options["api_key"]["value"]
self.api_base_url = source_details.settings_options["url_root"]["value"]
tmp_url = urlsplit(self.api_base_url)
# joinurl only works properly if there is a trailing slash
if tmp_url.path and tmp_url.path[-1] != "/":
tmp_url = tmp_url._replace(path=tmp_url.path + "/")
self.api_base_url = tmp_url.geturl()
self.series_match_thresh = series_match_thresh
# Used for async cover loading etc.
@ -359,8 +373,11 @@ class ComicVineTalker(TalkerBase):
self.write_log("Connection to " + self.source_name_friendly + " timed out.\n")
raise TalkerNetworkError(self.source_name_friendly, 4)
except requests.exceptions.RequestException as e:
self.write_log(str(e) + "\n")
self.write_log(f"{e}\n")
raise TalkerNetworkError(self.source_name_friendly, 0, str(e)) from e
except json.JSONDecodeError as e:
self.write_log(f"{e}\n")
raise TalkerDataError(self.source_name_friendly, 2, "ComicVine did not provide json")
raise TalkerNetworkError(self.source_name_friendly, 5)

View File

@ -1,29 +1,29 @@
from __future__ import annotations
import comicapi.genericmetadata
import comictaggerlib.resulttypes
import comictalker.resulttypes
from comicapi import utils
search_results = [
comictaggerlib.resulttypes.CVVolumeResults(
comictalker.resulttypes.ComicVolume(
count_of_issues=1,
description="this is a description",
id=1,
image={"super_url": "https://test.org/image/1"},
image="https://test.org/image/1",
name="test",
publisher=comictaggerlib.resulttypes.CVPublisher(name="test"),
publisher="test",
start_year="", # This is currently submitted as a string and returned as an int
aliases=None,
aliases="",
),
comictaggerlib.resulttypes.CVVolumeResults(
comictalker.resulttypes.ComicVolume(
count_of_issues=1,
description="this is a description",
id=1,
image={"super_url": "https://test.org/image/2"},
image="https://test.org/image/2",
name="test 2",
publisher=comictaggerlib.resulttypes.CVPublisher(name="test"),
publisher="test",
start_year="", # This is currently submitted as a string and returned as an int
aliases=None,
aliases="",
),
]

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Any
import comicapi.genericmetadata
import comictaggerlib.comicvinetalker
import comictalker.talkers.comicvine
def filter_field_list(cv_result, kwargs):
@ -156,7 +156,7 @@ cv_not_found = {
"status_code": 101,
"results": [],
}
date = comictaggerlib.comicvinetalker.ComicVineTalker().parse_date_str(cv_issue_result["results"]["cover_date"])
date = comictalker.talkers.comicvine.ComicVineTalker().parse_date_str(cv_issue_result["results"]["cover_date"])
cv_md = comicapi.genericmetadata.GenericMetadata(
is_empty=False,
@ -172,7 +172,7 @@ cv_md = comicapi.genericmetadata.GenericMetadata(
volume=None,
genre=None,
language=None,
comments=comictaggerlib.comicvinetalker.ComicVineTalker().cleanup_html(
comments=comictalker.talkers.comicvine.ComicVineTalker().cleanup_html(
cv_issue_result["results"]["description"], False
),
volume_count=None,