From 4362f515cb6d5ac90978bb011ce4ddabc27231aa Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 20 Nov 2024 13:47:45 +0800 Subject: [PATCH] :bug: Fix RuntimeError in player_card cache images --- plugins/genshin/player_cards.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index a4f54182..1b36cee2 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -739,24 +739,31 @@ class RenderTemplate: return items + async def _download_resource(self, url: str) -> str: + try: + return await download_resource(url) + except Exception: + logger.warning("缓存角色图片资源失败 %s", url) + return url + async def cache_images(self) -> None: """缓存所有图片到本地""" # TODO: 并发下载所有资源 c = self.character # 角色 - c.image.banner.url = await download_resource(c.image.banner.url) + c.image.banner.url = await self._download_resource(c.image.banner.url) # 技能 for item in c.skills: - item.icon.url = await download_resource(item.icon.url) + item.icon.url = await self._download_resource(item.icon.url) # 命座 for item in c.constellations: - item.icon.url = await download_resource(item.icon.url) + item.icon.url = await self._download_resource(item.icon.url) # 装备,包括圣遗物和武器 for item in c.equipments: - item.detail.icon.url = await download_resource(item.detail.icon.url) + item.detail.icon.url = await self._download_resource(item.detail.icon.url) def find_weapon(self) -> Optional[Equipments]: """在 equipments 数组中找到武器,equipments 数组包含圣遗物和武器"""