From 448ded9e24089e4d8e08560bf38a7d59fae21d03 Mon Sep 17 00:00:00 2001 From: seria Date: Fri, 15 Mar 2024 13:59:48 +0800 Subject: [PATCH 1/3] fix: Use Enka as new icon provider --- genshin/models/genshin/character.py | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/genshin/models/genshin/character.py b/genshin/models/genshin/character.py index 065cc14b..b7a8f63e 100644 --- a/genshin/models/genshin/character.py +++ b/genshin/models/genshin/character.py @@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) -ICON_BASE = "https://upload-os-bbs.mihoyo.com/game_record/genshin/" +ICON_BASE = "https://enka.network/ui/" def _parse_icon(icon: typing.Union[str, int]) -> str: @@ -86,14 +86,23 @@ def _get_db_char( constants.CHARACTER_NAMES[lang][char.id] = char return char - return constants.DBChar(id or 0, icon_name, name or icon_name, element or "Anemo", rarity or 5, guessed=True) + return constants.DBChar( + id or 0, + icon_name, + name or icon_name, + element or "Anemo", + rarity or 5, + guessed=True, + ) if name: for char in constants.CHARACTER_NAMES[lang].values(): if char.name == name: return char - return constants.DBChar(id or 0, icon or name, name, element or "Anemo", rarity or 5, guessed=True) + return constants.DBChar( + id or 0, icon or name, name, element or "Anemo", rarity or 5, guessed=True + ) raise ValueError("Character data incomplete") @@ -110,12 +119,16 @@ class BaseCharacter(APIModel, Unique): collab: bool = False @pydantic.root_validator(pre=True) - def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]: + def __autocomplete( + cls, values: typing.Dict[str, typing.Any] + ) -> typing.Dict[str, typing.Any]: """Complete missing data.""" - id, name, icon, element, rarity = (values.get(x) for x in ("id", "name", "icon", "element", "rarity")) + id, name, icon, element, rarity = ( + values.get(x) for x in ("id", "name", "icon", "element", "rarity") + ) char = _get_db_char(id, name, icon, element, rarity, lang=values["lang"]) - icon = _create_icon(char.icon_name, "character_icon/UI_AvatarIcon_{}") + icon = _create_icon(char.icon_name, "UI_AvatarIcon_{}") values["id"] = char.id values["name"] = char.name @@ -144,15 +157,16 @@ def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str @property def image(self) -> str: + # I don't know what this is, so this hasn't been changed to enka's endpoint return _create_icon(self.icon, "character_image/UI_AvatarIcon_{}@2x") @property def side_icon(self) -> str: - return _create_icon(self.icon, "character_side_icon/UI_AvatarIcon_Side_{}") + return _create_icon(self.icon, "UI_AvatarIcon_Side_{}") @property def card_icon(self) -> str: - return _create_icon(self.icon, "character_card_icon/UI_AvatarIcon_{}_Card") + return _create_icon(self.icon, "UI_AvatarIcon_{}_Card") @property def traveler_name(self) -> str: From 37944a385ad07ee55cfa447f0e9b4ad91a3e068d Mon Sep 17 00:00:00 2001 From: seria Date: Fri, 15 Mar 2024 15:34:39 +0800 Subject: [PATCH 2/3] Run nox --- genshin/models/genshin/character.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/genshin/models/genshin/character.py b/genshin/models/genshin/character.py index b7a8f63e..075fc837 100644 --- a/genshin/models/genshin/character.py +++ b/genshin/models/genshin/character.py @@ -100,9 +100,7 @@ def _get_db_char( if char.name == name: return char - return constants.DBChar( - id or 0, icon or name, name, element or "Anemo", rarity or 5, guessed=True - ) + return constants.DBChar(id or 0, icon or name, name, element or "Anemo", rarity or 5, guessed=True) raise ValueError("Character data incomplete") @@ -119,13 +117,9 @@ class BaseCharacter(APIModel, Unique): collab: bool = False @pydantic.root_validator(pre=True) - def __autocomplete( - cls, values: typing.Dict[str, typing.Any] - ) -> typing.Dict[str, typing.Any]: + def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]: """Complete missing data.""" - id, name, icon, element, rarity = ( - values.get(x) for x in ("id", "name", "icon", "element", "rarity") - ) + id, name, icon, element, rarity = (values.get(x) for x in ("id", "name", "icon", "element", "rarity")) char = _get_db_char(id, name, icon, element, rarity, lang=values["lang"]) icon = _create_icon(char.icon_name, "UI_AvatarIcon_{}") From 7db8d38802869437d3ec4032b23236c353ecc170 Mon Sep 17 00:00:00 2001 From: seria Date: Fri, 15 Mar 2024 15:55:41 +0800 Subject: [PATCH 3/3] feat: Add new gacha_art property Add deprecation notice to image property Change image property to return gacha_art instead --- genshin/models/genshin/character.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/genshin/models/genshin/character.py b/genshin/models/genshin/character.py index 075fc837..4720d009 100644 --- a/genshin/models/genshin/character.py +++ b/genshin/models/genshin/character.py @@ -4,6 +4,8 @@ import re import typing +from genshin.utility import deprecation + if typing.TYPE_CHECKING: import pydantic.v1 as pydantic else: @@ -150,9 +152,13 @@ def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str return values @property + @deprecation.deprecated("gacha_art") def image(self) -> str: - # I don't know what this is, so this hasn't been changed to enka's endpoint - return _create_icon(self.icon, "character_image/UI_AvatarIcon_{}@2x") + return _create_icon(self.icon, "UI_Gacha_AvatarImg_{}") + + @property + def gacha_art(self) -> str: + return _create_icon(self.icon, "UI_Gacha_AvatarImg_{}") @property def side_icon(self) -> str: