From 497d0d70de750c69e2fcb8ca761a7135ba88dc11 Mon Sep 17 00:00:00 2001 From: jokinas <89495587+jokinas@users.noreply.github.com> Date: Thu, 14 May 2026 22:59:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E5=92=8C=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=89=8D=E5=85=88=E5=81=9C=E6=AD=A2=E5=B0=8F?= =?UTF-8?q?=E7=88=B1=E9=81=BF=E5=85=8D=E6=92=AD=E6=94=BE=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8F=90=E7=A4=BA=20(#871)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 增加搜索多结果选择功能 新增功能: - 搜索结果多条记录时通过TTS告知用户匹配数量 - 支持用户重新呼叫'第X个'来选择并播放指定歌曲 - 实现记忆机制:选择后保留待选列表,支持持续多次选择 - 新增配置项 fuzzy_match_max_results 控制最大返回数量(默认100) 优化改进: - 搜索结果排序:从随机排序改为按文件名自然排序(custom_sort_key) - 日志输出优化:多结果时每个歌曲分行显示,带序号便于查看 修改文件: - command_handler.py: 添加待选择状态检查逻辑,优先匹配'第X个'指令 - config.py: 新增 fuzzy_match_max_results 配置项 - device_player.py: 添加 _pending_selection 属性、多结果处理逻辑、handle_selection 方法、优化日志格式 - music_library.py: 将 random.shuffle 改为 sort(key=custom_sort_key) 自然排序 - xiaomusic.py: 新增 select_index 命令处理方法 * fix: 优化登录异常处理和设备发现逻辑,执行命令前先停止小爱避免播放不支持提示 * style: ruff lint and format fix --- newpatch.sh | 0 newversion.sh | 0 update-holiday.sh | 0 update-static-version.py | 0 xiaomusic/auth.py | 24 +++++++++++++++--------- xiaomusic/command_handler.py | 3 +++ 6 files changed, 18 insertions(+), 9 deletions(-) mode change 100755 => 100644 newpatch.sh mode change 100755 => 100644 newversion.sh mode change 100755 => 100644 update-holiday.sh mode change 100755 => 100644 update-static-version.py diff --git a/newpatch.sh b/newpatch.sh old mode 100755 new mode 100644 diff --git a/newversion.sh b/newversion.sh old mode 100755 new mode 100644 diff --git a/update-holiday.sh b/update-holiday.sh old mode 100755 new mode 100644 diff --git a/update-static-version.py b/update-static-version.py old mode 100755 new mode 100644 diff --git a/xiaomusic/auth.py b/xiaomusic/auth.py index 0822238..9c425c7 100644 --- a/xiaomusic/auth.py +++ b/xiaomusic/auth.py @@ -124,6 +124,12 @@ class AuthManager: self.login_acount = self.config.account self.login_password = self.config.password self.log.info(f"登录完成. {self.login_acount}") + except KeyError as e: + self.mina_service = None + self.miio_service = None + self.log.warning( + f"登录失败,API响应格式错误: {e}。建议使用Cookie登录或访问小米官网验证" + ) except Exception as e: self.mina_service = None self.miio_service = None @@ -148,15 +154,15 @@ class AuthManager: name = h.get("alias", "") if not name: name = h.get("name", "未知名字") - if device_id and hardware and did and (did in mi_dids): - device = self.config.devices.get(did, Device()) - device.did = did - # 将did存一下 方便其他地方调用 - self._cur_did = did - device.device_id = device_id - device.hardware = hardware - device.name = name - devices[did] = device + if device_id and hardware and did: + if not mi_dids or not mi_dids[0] or (did in mi_dids): + device = self.config.devices.get(did, Device()) + device.did = did + self._cur_did = did + device.device_id = device_id + device.hardware = hardware + device.name = name + devices[did] = device self.config.devices = devices self.log.info(f"选中的设备: {devices}") return devices diff --git a/xiaomusic/command_handler.py b/xiaomusic/command_handler.py index cabdd01..d613580 100644 --- a/xiaomusic/command_handler.py +++ b/xiaomusic/command_handler.py @@ -63,6 +63,9 @@ class CommandHandler: await device.check_replay() return + # 执行命令前先停止小爱,避免播放"不支持"提示 + await device.group_force_stop_xiaoai() + # 执行命令 func = getattr(self.xiaomusic, opvalue) await func(did=did, arg1=oparg)