From 1edcee9ce32565462c34604d49b042d4b7f83402 Mon Sep 17 00:00:00 2001 From: newton_miku <1316561519@qq.com> Date: Sun, 25 Dec 2022 14:33:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Depic=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E7=9A=84=E7=AE=80=E4=BB=8B=E4=B8=8D=E6=98=AF=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因为epic的api获取免费游戏时简介始终是英文,故更换为使用游戏销售页面的简介 --- plugins/epic/data_source.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/epic/data_source.py b/plugins/epic/data_source.py index cbdc48c1..9c7f03ee 100755 --- a/plugins/epic/data_source.py +++ b/plugins/epic/data_source.py @@ -24,6 +24,22 @@ async def get_epic_game(): logger.error(f"Epic 访问接口错误 {type(e)}:{e}") return None +# 此处用于获取游戏简介 +async def get_epic_game_desp(name): + desp_url = "https://store-content-ipv4.ak.epicgames.com/api/zh-CN/content/products/" + str(name) + headers = { + "Referer": "https://store.epicgames.com/zh-CN/p/" + str(name), + "Content-Type": "application/json; charset=utf-8", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36", + } + try: + res = await AsyncHttpx.get(desp_url, headers=headers, timeout=10) + res_json = res.json() + gamesDesp = res_json["pages"][0]["data"]["about"] + return gamesDesp + except Exception as e: + logger.error(f"Epic 访问接口错误 {type(e)}:{e}") + return None # 获取 Epic Game Store 免费游戏信息 # 处理免费游戏的信息方法借鉴 pip 包 epicstore_api 示例 @@ -95,7 +111,10 @@ async def get_epic_free(bot: Bot, type_event: str): game_dev = pair["value"] if pair["key"] == "publisherName": game_pub = pair["value"] - game_desp = game["description"] + if game.get("productSlug"): + gamesDesp = await get_epic_game_desp(game["productSlug"]) + #game_desp = game["description"] + game_desp = gamesDesp["description"] try: end_date_iso = game["promotions"]["promotionalOffers"][0][ "promotionalOffers"