1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2025-12-07 15:02:55 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
涵曦
b9e1abff6b new version v0.1.22 2024-04-30 12:48:10 +00:00
涵曦
f962fcaa99 新增本地音乐模糊搜索 2024-04-30 12:47:57 +00:00
涵曦
eb35da595f Update README.md 2024-04-29 22:47:54 +08:00
8 changed files with 46 additions and 2 deletions

1
.gitignore vendored
View File

@@ -163,3 +163,4 @@ cython_debug/
ffmpeg ffmpeg
music music
test.sh

View File

@@ -141,6 +141,7 @@ services:
- [MiService](https://github.com/yihong0618/MiService) - [MiService](https://github.com/yihong0618/MiService)
- [yt-dlp](https://github.com/yt-dlp/yt-dlp) - [yt-dlp](https://github.com/yt-dlp/yt-dlp)
- [NAS部署教程](https://post.m.smzdm.com/p/avpe7n99/) - [NAS部署教程](https://post.m.smzdm.com/p/avpe7n99/)
- [群晖部署教程](https://post.m.smzdm.com/p/a7px7dol/)
## Star History ## Star History

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "xiaomusic" name = "xiaomusic"
version = "0.1.21" version = "0.1.22"
description = "Play Music with xiaomi AI speaker" description = "Play Music with xiaomi AI speaker"
authors = [ authors = [
{name = "涵曦", email = "im.hanxi@gmail.com"}, {name = "涵曦", email = "im.hanxi@gmail.com"},

View File

@@ -28,6 +28,10 @@ def getvolume():
"volume": xiaomusic.get_volume(), "volume": xiaomusic.get_volume(),
} }
@app.route("/searchmusic")
def searchmusic():
name = request.args.get('name')
return xiaomusic.searchmusic(name)
@app.route("/", methods=["GET"]) @app.route("/", methods=["GET"])
def redirect_to_index(): def redirect_to_index():

View File

@@ -64,4 +64,26 @@ $(function(){
} }
}); });
} }
// 监听输入框的输入事件
$("#music-name").on('input', function() {
var inputValue = $(this).val();
// 发送Ajax请求
$.ajax({
url: "searchmusic", // 服务器端处理脚本
type: "GET",
dataType: "json",
data: {
name: inputValue
},
success: function(data) {
// 清空datalist
$("#autocomplete-list").empty();
// 添加新的option元素
$.each(data, function(i, item) {
$('<option>').val(item).appendTo("#autocomplete-list");
});
}
});
});
}); });

View File

@@ -44,7 +44,8 @@
</div> </div>
<hr> <hr>
<div> <div>
<input id="music-name" type="text" placeholder="请输入搜索关键词(如:MV高清版 周杰伦 七里香)"></input> <datalist id="autocomplete-list"></datalist>
<input id="music-name" type="text" placeholder="请输入搜索关键词(如:MV高清版 周杰伦 七里香)" list="autocomplete-list"></input>
<input id="music-filename" type="text" placeholder="请输入保存为的文件名称(如:周杰伦七里香)"></input> <input id="music-filename" type="text" placeholder="请输入保存为的文件名称(如:周杰伦七里香)"></input>
<button id="play">播放</button> <button id="play">播放</button>
</div> </div>

View File

@@ -7,6 +7,7 @@ import socket
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from typing import AsyncIterator from typing import AsyncIterator
from urllib.parse import urlparse from urllib.parse import urlparse
import difflib
from requests.utils import cookiejar_from_dict from requests.utils import cookiejar_from_dict
@@ -61,3 +62,6 @@ def validate_proxy(proxy_str: str) -> bool:
return True return True
# 模糊搜索
def fuzzyfinder(user_input, collection):
return difflib.get_close_matches(user_input, collection, 10, cutoff=0.1)

View File

@@ -30,6 +30,7 @@ from xiaomusic.config import (
from xiaomusic.utils import ( from xiaomusic.utils import (
calculate_tts_elapse, calculate_tts_elapse,
parse_cookie_string, parse_cookie_string,
fuzzyfinder,
) )
EOF = object() EOF = object()
@@ -330,6 +331,7 @@ class XiaoMusic:
# 本地是否存在歌曲 # 本地是否存在歌曲
def get_filename(self, name): def get_filename(self, name):
if name not in self._all_music: if name not in self._all_music:
self.log.debug("get_filename not in. name:%s", name)
return "" return ""
filename = self._all_music[name] filename = self._all_music[name]
self.log.debug("try get_filename. filename:%s", filename) self.log.debug("try get_filename. filename:%s", filename)
@@ -490,6 +492,9 @@ class XiaoMusic:
if search_key == "" and name == "": if search_key == "" and name == "":
await self.play_next() await self.play_next()
return return
if name == "":
name = search_key
self.log.debug("play. search_key:%s name:%s", search_key, name)
filename = self.get_filename(name) filename = self.get_filename(name)
if len(filename) <= 0: if len(filename) <= 0:
@@ -569,3 +574,9 @@ class XiaoMusic:
def get_volume(self): def get_volume(self):
return self._volume return self._volume
# 搜索音乐
def searchmusic(self, name):
search_list = fuzzyfinder(name, self._play_list)
self.log.debug("searchmusic. name:%s search_list:%s", name, search_list)
return search_list