diff --git a/comicapi/comet.py b/comicapi/comet.py index 12596df..d3afe3f 100644 --- a/comicapi/comet.py +++ b/comicapi/comet.py @@ -165,12 +165,12 @@ class CoMet: # loop for genre tags for n in root: if n.tag == "genre": - md.genres.append((n.text or "").strip()) + md.genres.add((n.text or "").strip()) # loop for character tags for n in root: if n.tag == "character": - md.characters.append((n.text or "").strip()) + md.characters.add((n.text or "").strip()) # Now extract the credit info for n in root: diff --git a/comicapi/comicbookinfo.py b/comicapi/comicbookinfo.py index 369d731..2a636de 100644 --- a/comicapi/comicbookinfo.py +++ b/comicapi/comicbookinfo.py @@ -89,7 +89,7 @@ class ComicBookInfo: metadata.year = utils.xlate_int(cbi["publicationYear"]) metadata.issue_count = utils.xlate_int(cbi["numberOfIssues"]) metadata.description = utils.xlate(cbi["comments"]) - metadata.genres = utils.split(cbi["genre"], ",") + metadata.genres = set(utils.split(cbi["genre"], ",")) metadata.volume = utils.xlate_int(cbi["volume"]) metadata.volume_count = utils.xlate_int(cbi["numberOfVolumes"]) metadata.language = utils.xlate(cbi["language"]) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index d45cb6e..7c62ebf 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -73,7 +73,7 @@ class ComicInfoXml: text = "" if isinstance(md_entry, str): text = md_entry - elif isinstance(md_entry, list): + elif isinstance(md_entry, (list, set)): text = ",".join(md_entry) else: text = str(md_entry) @@ -208,14 +208,14 @@ class ComicInfoXml: md.day = utils.xlate_int(get("Day")) md.publisher = utils.xlate(get("Publisher")) md.imprint = utils.xlate(get("Imprint")) - md.genres = utils.split(get("Genre"), ",") + md.genres = set(utils.split(get("Genre"), ",")) md.web_link = utils.xlate(get("Web")) md.language = utils.xlate(get("LanguageISO")) md.format = utils.xlate(get("Format")) md.manga = utils.xlate(get("Manga")) - md.characters = utils.split(get("Characters"), ",") - md.teams = utils.split(get("Teams"), ",") - md.locations = utils.split(get("Locations"), ",") + md.characters = set(utils.split(get("Characters"), ",")) + md.teams = set(utils.split(get("Teams"), ",")) + md.locations = set(utils.split(get("Locations"), ",")) md.page_count = utils.xlate_int(get("PageCount")) md.scan_info = utils.xlate(get("ScanInformation")) md.story_arcs = utils.split(get("StoryArc"), ",") diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index a22a5f6..981d5f4 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -72,7 +72,7 @@ class Credit(TypedDict): class ComicSeries: id: str name: str - aliases: list[str] + aliases: set[str] count_of_issues: int | None count_of_volumes: int | None description: str @@ -107,17 +107,17 @@ class GenericMetadata: series_id: str | None = None series: str | None = None - series_aliases: list[str] = dataclasses.field(default_factory=list) + series_aliases: set[str] = dataclasses.field(default_factory=set) issue: str | None = None title: str | None = None - title_aliases: list[str] = dataclasses.field(default_factory=list) + title_aliases: set[str] = dataclasses.field(default_factory=set) publisher: str | None = None month: int | None = None year: int | None = None day: int | None = None issue_count: int | None = None volume: int | None = None - genres: list[str] = dataclasses.field(default_factory=list) + genres: set[str] = dataclasses.field(default_factory=set) language: str | None = None # 2 letter iso code description: str | None = None # use same way as Summary in CIX @@ -141,9 +141,9 @@ class GenericMetadata: series_groups: list[str] = dataclasses.field(default_factory=list) scan_info: str | None = None - characters: list[str] = dataclasses.field(default_factory=list) - teams: list[str] = dataclasses.field(default_factory=list) - locations: list[str] = dataclasses.field(default_factory=list) + characters: set[str] = dataclasses.field(default_factory=set) + teams: set[str] = dataclasses.field(default_factory=set) + locations: set[str] = dataclasses.field(default_factory=set) alternate_images: list[str] = dataclasses.field(default_factory=list) credits: list[Credit] = dataclasses.field(default_factory=list) @@ -183,7 +183,7 @@ class GenericMetadata: if new is not None: if isinstance(new, str) and len(new) == 0: setattr(self, cur, None) - elif isinstance(new, list) and len(new) == 0: + elif isinstance(new, (list, set)) and len(new) == 0: pass else: setattr(self, cur, new) @@ -332,7 +332,7 @@ class GenericMetadata: add_attr_string("day") add_attr_string("volume") add_attr_string("volume_count") - add_attr_string("genres") + add_string("genres", ", ".join(self.genres)) add_attr_string("language") add_attr_string("country") add_attr_string("critical_rating") @@ -356,9 +356,9 @@ class GenericMetadata: add_attr_string("story_arcs") add_attr_string("series_groups") add_attr_string("scan_info") - add_attr_string("characters") - add_attr_string("teams") - add_attr_string("locations") + add_string("characters", ", ".join(self.characters)) + add_string("teams", ", ".join(self.teams)) + add_string("locations", ", ".join(self.locations)) add_attr_string("description") add_attr_string("notes") @@ -417,7 +417,7 @@ md_test: GenericMetadata = GenericMetadata( day=1, issue_count=6, volume=1, - genres=["Sci-Fi"], + genres={"Sci-Fi"}, language="en", description=( "For 12-year-old Anda, getting paid real money to kill the characters of players who were cheating" @@ -441,9 +441,9 @@ md_test: GenericMetadata = GenericMetadata( story_arcs=["Here and Now"], series_groups=["Futuristic Tales"], scan_info="(CC BY-NC-SA 3.0)", - characters=["Anda"], - teams=["Fahrenheit"], - locations=utils.split("lonely cottage ", ","), + characters={"Anda"}, + teams={"Fahrenheit"}, + locations=set(utils.split("lonely cottage ", ",")), credits=[ Credit(primary=False, person="Dara Naraghi", role="Writer"), Credit(primary=False, person="Esteve Polls", role="Penciller"), diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index bf632c9..61a17d2 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -917,7 +917,7 @@ class TaggerWindow(QtWidgets.QMainWindow): md.series = utils.xlate(self.leSeries.text()) md.title = utils.xlate(self.leTitle.text()) md.publisher = utils.xlate(self.lePublisher.text()) - md.genres = utils.split(self.leGenre.text(), ",") + md.genres = set(utils.split(self.leGenre.text(), ",")) md.imprint = utils.xlate(self.leImprint.text()) md.description = utils.xlate(self.teComments.toPlainText()) md.notes = utils.xlate(self.teNotes.toPlainText()) @@ -932,9 +932,9 @@ class TaggerWindow(QtWidgets.QMainWindow): md.series_groups = utils.split(self.leSeriesGroup.text(), ",") md.alternate_series = self.leAltSeries.text() md.web_link = utils.xlate(self.leWebLink.text()) - md.characters = utils.split(self.teCharacters.toPlainText(), "\n") - md.teams = utils.split(self.teTeams.toPlainText(), "\n") - md.locations = utils.split(self.teLocations.toPlainText(), "\n") + md.characters = set(utils.split(self.teCharacters.toPlainText(), "\n")) + md.teams = set(utils.split(self.teTeams.toPlainText(), "\n")) + md.locations = set(utils.split(self.teLocations.toPlainText(), "\n")) md.format = utils.xlate(self.cbFormat.currentText()) md.country = utils.xlate(self.cbCountry.currentText()) diff --git a/comictalker/talkers/comicvine.py b/comictalker/talkers/comicvine.py index f294855..43ef298 100644 --- a/comictalker/talkers/comicvine.py +++ b/comictalker/talkers/comicvine.py @@ -480,8 +480,8 @@ class ComicVineTalker(ComicTalker): aliases = record.get("aliases") or "" return ComicSeries( - aliases=utils.split(aliases, "\n"), - count_of_issues=record.get("count_of_issues", 0), + aliases=set(utils.split(aliases, "\n")), + count_of_issues=record.get("count_of_issues"), count_of_volumes=None, description=record.get("description", ""), id=str(record["id"]), @@ -630,7 +630,7 @@ class ComicVineTalker(ComicTalker): tag_origin=TagOrigin(self.id, self.name), issue_id=utils.xlate(issue.get("id")), series_id=series.id, - title_aliases=utils.split(issue.get("aliases"), "\n"), + title_aliases=set(utils.split(issue.get("aliases"), "\n")), publisher=utils.xlate(series.publisher), description=issue.get("description"), issue=utils.xlate(IssueString(issue.get("issue_number")).as_string()), @@ -647,23 +647,18 @@ class ComicVineTalker(ComicTalker): else: md.cover_image = issue.get("image", {}).get("super_url", "") - md.alternate_images = [] for alt in issue.get("associated_images", []): md.alternate_images.append(alt["original_url"]) - md.characters = [] - for character in issue.get("character_credits", []): - md.characters.append(character["name"]) + for character in issue.get("character_credits", set()): + md.characters.add(character["name"]) - md.locations = [] - for location in issue.get("location_credits", []): - md.locations.append(location["name"]) + for location in issue.get("location_credits", set()): + md.locations.add(location["name"]) - md.teams = [] - for team in issue.get("team_credits", []): - md.teams.append(team["name"]) + for team in issue.get("team_credits", set()): + md.teams.add(team["name"]) - md.story_arcs = [] for arc in issue.get("story_arc_credits", []): md.story_arcs.append(arc["name"]) diff --git a/testing/comicvine.py b/testing/comicvine.py index 239ce7d..9db59b5 100644 --- a/testing/comicvine.py +++ b/testing/comicvine.py @@ -159,7 +159,7 @@ cv_not_found = { comic_series_result = comicapi.genericmetadata.ComicSeries( id=str(cv_issue_result["results"]["volume"]["id"]), name=cv_issue_result["results"]["volume"]["name"], - aliases=[], + aliases=set(), count_of_issues=cv_volume_result["results"]["count_of_issues"], count_of_volumes=None, description=cv_volume_result["results"]["description"], @@ -172,7 +172,7 @@ comic_series_result = comicapi.genericmetadata.ComicSeries( date = utils.parse_date_str(cv_issue_result["results"]["cover_date"]) comic_issue_result = comicapi.genericmetadata.GenericMetadata( tag_origin=comicapi.genericmetadata.TagOrigin("comicvine", "Comic Vine"), - title_aliases=cv_issue_result["results"]["aliases"] or [], + title_aliases=set(), month=date[1], year=date[2], day=date[0], @@ -203,7 +203,7 @@ cv_md = comicapi.genericmetadata.GenericMetadata( day=date[0], issue_count=cv_volume_result["results"]["count_of_issues"], volume=None, - genres=[], + genres=set(), language=None, description=cv_issue_result["results"]["description"], volume_count=None, @@ -223,9 +223,9 @@ cv_md = comicapi.genericmetadata.GenericMetadata( story_arcs=[], series_groups=[], scan_info=None, - characters=[], - teams=[], - locations=[], + characters=set(), + teams=set(), + locations=set(), credits=[ comicapi.genericmetadata.Credit(person=x["name"], role=x["role"].title(), primary=False) for x in cv_issue_result["results"]["person_credits"] diff --git a/tests/comicarchive_test.py b/tests/comicarchive_test.py index d688b23..ecedc04 100644 --- a/tests/comicarchive_test.py +++ b/tests/comicarchive_test.py @@ -98,9 +98,9 @@ def test_save_cbi_rar(tmp_path, md_saved): story_arcs=[], series_groups=[], scan_info=None, - characters=[], - teams=[], - locations=[], + characters=set(), + teams=set(), + locations=set(), ) diff --git a/tests/metadata_test.py b/tests/metadata_test.py index 79a84ab..364bc99 100644 --- a/tests/metadata_test.py +++ b/tests/metadata_test.py @@ -23,9 +23,9 @@ def test_cbi(md_saved): story_arcs=[], series_groups=[], scan_info=None, - characters=[], - teams=[], - locations=[], + characters=set(), + teams=set(), + locations=set(), pages=[], alternate_series=None, alternate_number=None, @@ -48,8 +48,8 @@ def test_comet(md_saved): story_arcs=[], series_groups=[], scan_info=None, - teams=[], - locations=[], + teams=set(), + locations=set(), pages=[], alternate_series=None, alternate_number=None,