mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-06-01 12:15:48 +08:00
feat: 新增“是否开启多结果选择”功能 (#881)
* style: ruff lint and format fix * fix: 恢复脚本文件的可执行权限属性 * feat: 新增多结果选择开关配置,前端页面支持开启关闭功能
This commit is contained in:
@@ -147,6 +147,12 @@ class Config:
|
||||
fuzzy_match_max_results: int = int(
|
||||
os.getenv("XIAOMUSIC_FUZZY_MATCH_MAX_RESULTS", "100")
|
||||
)
|
||||
# 是否开启多结果选择功能(关闭后按 multi_result_action 配置处理)
|
||||
enable_multi_result_selection: bool = (
|
||||
os.getenv("XIAOMUSIC_ENABLE_MULTI_RESULT_SELECTION", "true").lower() == "true"
|
||||
)
|
||||
# 多结果处理方式: random=随机播放, first=从第一个开始播放
|
||||
multi_result_action: str = os.getenv("XIAOMUSIC_MULTI_RESULT_ACTION", "random")
|
||||
stop_tts_msg: str = os.getenv("XIAOMUSIC_STOP_TTS_MSG", "收到,再见")
|
||||
enable_config_example: bool = False
|
||||
|
||||
|
||||
@@ -361,6 +361,21 @@ class XiaoMusicDevice:
|
||||
await self.handle_selection(auto_index)
|
||||
return
|
||||
|
||||
if not self.config.enable_multi_result_selection:
|
||||
action = self.config.multi_result_action
|
||||
if action == "first":
|
||||
selected_index = 1
|
||||
else:
|
||||
selected_index = random.randint(1, len(names))
|
||||
selected_name = names[selected_index - 1]
|
||||
self.log.info(
|
||||
f"多结果选择已关闭,按'{action}'处理,选择第{selected_index}个: {selected_name}"
|
||||
)
|
||||
self._pending_selection = names
|
||||
self._pending_selection_count = len(names)
|
||||
await self._playmusic(selected_name)
|
||||
return
|
||||
|
||||
self._pending_selection = names
|
||||
self._pending_selection_count = len(names)
|
||||
selection_text = (
|
||||
|
||||
14
xiaomusic/static/default/setting.html
vendored
14
xiaomusic/static/default/setting.html
vendored
@@ -268,6 +268,20 @@
|
||||
<option value="true" selected>true</option>
|
||||
<option value="false">false</option>
|
||||
</select>
|
||||
|
||||
<label for="enable_multi_result_selection">开启多结果选择功能:</label>
|
||||
<select id="enable_multi_result_selection" onchange="toggleMultiResultAction()">
|
||||
<option value="true" selected>开启</option>
|
||||
<option value="false">关闭</option>
|
||||
</select>
|
||||
|
||||
<div id="multi_result_action_row" style="display:none;">
|
||||
<label for="multi_result_action">多结果处理:</label>
|
||||
<select id="multi_result_action">
|
||||
<option value="random" selected>随机播放</option>
|
||||
<option value="first">从第一首开始播放</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
12
xiaomusic/static/default/setting.js
vendored
12
xiaomusic/static/default/setting.js
vendored
@@ -201,6 +201,9 @@ $(function () {
|
||||
}
|
||||
|
||||
autoSelectOne();
|
||||
if (typeof toggleMultiResultAction === "function") {
|
||||
toggleMultiResultAction();
|
||||
}
|
||||
});
|
||||
|
||||
$("#update-devices").on("click", function () {
|
||||
@@ -641,4 +644,13 @@ $(function () {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
window.toggleMultiResultAction = function () {
|
||||
var val = $("#enable_multi_result_selection").val();
|
||||
if (val === "false") {
|
||||
$("#multi_result_action_row").show();
|
||||
} else {
|
||||
$("#multi_result_action_row").hide();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
20
xiaomusic/static/tailwind/setting.html
vendored
20
xiaomusic/static/tailwind/setting.html
vendored
@@ -437,6 +437,26 @@
|
||||
</label>
|
||||
<input id="fuzzy_match_cutoff" type="number" value="0.6" step="0.1" min="0.1" max="0.9" class="mt-1 block w-full rounded-md border border-gray-300 bg-white px-4 py-2.5 text-gray-900 placeholder:text-gray-500 focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 hover:border-gray-400" />
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="enable_multi_result_selection" class="block text-sm font-medium text-gray-700">
|
||||
多结果选择功能
|
||||
</label>
|
||||
<select id="enable_multi_result_selection" onchange="toggleMultiResultAction()"
|
||||
class="mt-1 block w-full rounded-md border border-gray-300 bg-white px-4 py-2.5 text-gray-900 placeholder:text-gray-500 focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 hover:border-gray-400 bg-white py-2 px-3 text-gray-900 cursor-pointer hover:bg-gray-50">
|
||||
<option value="true" selected>开启</option>
|
||||
<option value="false">关闭</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-4" id="multi_result_action_row" style="display:none;">
|
||||
<label for="multi_result_action" class="block text-sm font-medium text-gray-700">
|
||||
多结果处理
|
||||
</label>
|
||||
<select id="multi_result_action"
|
||||
class="mt-1 block w-full rounded-md border border-gray-300 bg-white px-4 py-2.5 text-gray-900 placeholder:text-gray-500 focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 hover:border-gray-400 bg-white py-2 px-3 text-gray-900 cursor-pointer hover:bg-gray-50">
|
||||
<option value="random" selected>随机播放</option>
|
||||
<option value="first">从第一首开始播放</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
12
xiaomusic/static/tailwind/setting.js
vendored
12
xiaomusic/static/tailwind/setting.js
vendored
@@ -88,6 +88,9 @@ $(function () {
|
||||
}
|
||||
|
||||
autoSelectOne();
|
||||
if (typeof toggleMultiResultAction === "function") {
|
||||
toggleMultiResultAction();
|
||||
}
|
||||
});
|
||||
|
||||
$(".save-button").on("click", () => {
|
||||
@@ -119,6 +122,15 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
window.toggleMultiResultAction = function () {
|
||||
var val = $("#enable_multi_result_selection").val();
|
||||
if (val === "false") {
|
||||
$("#multi_result_action_row").show();
|
||||
} else {
|
||||
$("#multi_result_action_row").hide();
|
||||
}
|
||||
};
|
||||
|
||||
$("#get_music_list").on("click", () => {
|
||||
var music_list_url = $("#music_list_url").val();
|
||||
console.log("music_list_url", music_list_url);
|
||||
|
||||
Reference in New Issue
Block a user