mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-05-22 11:25:46 +08:00
* 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
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
def get_html_files(directory):
|
|
"""
|
|
获取指定目录下所有HTML文件的列表。
|
|
|
|
:param directory: 搜索HTML文件的目录。
|
|
:return: 搜索到的HTML文件的路径列表。
|
|
"""
|
|
return list(Path(directory).rglob("*.html"))
|
|
|
|
|
|
def update_html_version(html_files, version):
|
|
"""
|
|
更新HTML文件中所有以 ./ 开头的CSS和JS文件引用的版本号。
|
|
|
|
:param html_files: 需要更新的HTML文件路径的列表。
|
|
:param version: 新的版本号字符串。
|
|
"""
|
|
pattern = re.compile(r'(\./.*(css|js))\?version=[^"]*"')
|
|
|
|
for html_file in html_files:
|
|
if not html_file.exists():
|
|
print(f"文件 {html_file} 不存在。")
|
|
continue
|
|
|
|
html_content = html_file.read_text()
|
|
|
|
# 更新CSS和JS版本号
|
|
html_content = pattern.sub(rf'\g<1>?version={version}"', html_content)
|
|
# html_content = pattern.sub(fr'\g<1>"', html_content)
|
|
|
|
# 保存更改到HTML文件
|
|
html_file.write_text(html_content)
|
|
|
|
print(f"文件 {html_file} 已更新为使用新的版本号: {version}")
|
|
|
|
|
|
# 使用案例
|
|
if __name__ == "__main__":
|
|
import time
|
|
|
|
t = str(int(time.time()))
|
|
|
|
# 指定目录
|
|
html_directory = "xiaomusic/static/default" # 修改为实际的HTML文件目录路径
|
|
|
|
# 获取HTML文件列表
|
|
html_files_to_update = get_html_files(html_directory)
|
|
|
|
# 执行更新
|
|
update_html_version(html_files_to_update, t)
|