From 11db74eb7afea398c0267d28c58c76e5ed1142bd Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sat, 3 Sep 2022 15:21:02 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D`=E5=8E=9F=E7=A5=9E?= =?UTF-8?q?=E8=AF=AD=E9=9F=B3`=E8=AF=AD=E8=A8=80=E5=92=8C=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E8=AF=AD=E9=9F=B3=E8=AF=AD=E8=A8=80=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Genshin_Voice/resources.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/LittlePaimon/plugins/Genshin_Voice/resources.py b/LittlePaimon/plugins/Genshin_Voice/resources.py index e6588ac..2bf3e28 100644 --- a/LittlePaimon/plugins/Genshin_Voice/resources.py +++ b/LittlePaimon/plugins/Genshin_Voice/resources.py @@ -39,19 +39,21 @@ async def get_voice(character_name: str, content_id: int): return None data = data['data']['content']['contents'][2] html = etree.HTML(data['text']) - lang = ['中', '英', '日', '韩'] for i in range(1, 5): + voice_type = html.xpath(f'//*[@class="obc-tmpl__part obc-tmpl-character obc-tmpl__part--voiceTab obc-tmpl__part--align-banner"]/ul[1]/li[{i}]/text()')[0] + voice_type = voice_type[0] if voice_type[0] != '汉' else '中' voice_list = html.xpath(f'//*[@class="obc-tmpl__part obc-tmpl-character obc-tmpl__part--voiceTab obc-tmpl__part--align-banner"]/ul[2]/li[{i}]/table[2]/tbody/tr') for voice in voice_list: with contextlib.suppress(IndexError): voice_name = voice.xpath('./td/text()')[0] voice_url = voice.xpath('./td/div/div/audio/source/@src')[0] voice_content = voice.xpath('./td/div/span/text()')[0].strip() - await GenshinVoice.update_or_create(character=character_name, voice_name=voice_name, language=lang[i - 1], defaults={'voice_content': voice_content, 'voice_url': voice_url}) + character_name = character_name.replace('旅行者(', '').replace(')', '') + await GenshinVoice.update_or_create(character=character_name, voice_name=voice_name, language=voice_type, defaults={'voice_content': voice_content, 'voice_url': voice_url}) if voice_list: - logger.info('原神猜语音', f'➤➤角色{character_name}{lang[i - 1]}文语音获取成功') + logger.info('原神猜语音', f'➤➤角色{character_name}{voice_type}文语音获取成功') else: - logger.info('原神猜语音', f'➤➤角色{character_name}{lang[i - 1]}文语音获取失败') + logger.info('原神猜语音', f'➤➤角色{character_name}{voice_type}文语音获取失败') except Exception as e: logger.warning('原神猜语音', f'➤➤获取{character_name}的语音资源时出错:', str(e))