diff --git a/xiaomusic/httpserver.py b/xiaomusic/httpserver.py
index fec01d1..fd94d88 100644
--- a/xiaomusic/httpserver.py
+++ b/xiaomusic/httpserver.py
@@ -25,6 +25,7 @@ from xiaomusic import __version__
from xiaomusic.utils import (
deepcopy_data_no_sensitive_info,
downloadfile,
+ get_latest_version,
)
xiaomusic = None
@@ -358,6 +359,15 @@ async def debug_play_by_music_url(request: Request, Verifcation=Depends(verifica
raise HTTPException(status_code=400, detail="Invalid JSON") from err
+@app.get("/latestversion")
+async def latest_version(Verifcation=Depends(verification)):
+ version = await get_latest_version("xiaomusic")
+ if version:
+ return {"ret": "OK", "version": version}
+ else:
+ return {"ret": "Fetch version failed"}
+
+
async def file_iterator(file_path, start, end):
async with aiofiles.open(file_path, mode="rb") as file:
await file.seek(start)
diff --git a/xiaomusic/static/default/app.js b/xiaomusic/static/default/app.js
index 51847b8..aa3f472 100644
--- a/xiaomusic/static/default/app.js
+++ b/xiaomusic/static/default/app.js
@@ -86,10 +86,35 @@ $(function(){
})
});
+ function compareVersion(version1, version2) {
+ const v1 = version1.split('.').map(Number);
+ const v2 = version2.split('.').map(Number);
+ const len = Math.max(v1.length, v2.length);
+
+ for (let i = 0; i < len; i++) {
+ const num1 = v1[i] || 0;
+ const num2 = v2[i] || 0;
+ if (num1 > num2) return 1;
+ if (num1 < num2) return -1;
+ }
+ return 0;
+ }
+
// 拉取版本
$.get("/getversion", function(data, status) {
console.log(data, status, data["version"]);
$("#version").text(`${data.version}`);
+
+ $.get("/latestversion", function(ret, status) {
+ console.log(ret, status);
+ if (ret.ret == "OK") {
+ const result = compareVersion(ret.version, data.version);
+ if (result > 0) {
+ console.log(`${ret.version} is greater than ${data.version}`);
+ $("#versionnew").text("🆕");
+ }
+ }
+ });
});
// 拉取播放列表
diff --git a/xiaomusic/static/default/index.html b/xiaomusic/static/default/index.html
index e98b13f..306762d 100644
--- a/xiaomusic/static/default/index.html
+++ b/xiaomusic/static/default/index.html
@@ -26,9 +26,8 @@ var vConsole = new window.VConsole();
diff --git a/xiaomusic/static/default/style.css b/xiaomusic/static/default/style.css
index dba9238..e9def46 100644
--- a/xiaomusic/static/default/style.css
+++ b/xiaomusic/static/default/style.css
@@ -90,3 +90,13 @@ footer {
max-width: 480px;
height: auto;
}
+
+@keyframes blink {
+ 0%, 100% { opacity: 1; }
+ 50% { opacity: 0; }
+}
+
+.blink {
+ animation: blink 1s infinite;
+}
+
diff --git a/xiaomusic/utils.py b/xiaomusic/utils.py
index da7d8ae..0757157 100644
--- a/xiaomusic/utils.py
+++ b/xiaomusic/utils.py
@@ -137,7 +137,8 @@ def find_best_match(user_input, collection, cutoff=0.6, n=1, extra_search_index=
# 如果数量不满足,继续搜索
lower_extra_search_index = {
- traditional_to_simple(k.lower()): v for k, v in extra_search_index.items()
+ traditional_to_simple(k.lower()): v
+ for k, v in extra_search_index.items()
if v not in cur_matched_collection
}
matches = real_search(user_input, lower_extra_search_index.keys(), cutoff, n)
@@ -639,3 +640,14 @@ def list2str(li, verbose=False):
return f"{li[:2]} ... {li[-2:]} with len: {len(li)}"
else:
return f"{li}"
+
+
+async def get_latest_version(package_name: str) -> str:
+ url = f"https://pypi.org/pypi/{package_name}/json"
+ async with aiohttp.ClientSession() as session:
+ async with session.get(url) as response:
+ if response.status == 200:
+ data = await response.json()
+ return data["info"]["version"]
+ else:
+ return None
diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py
index e9cc1d2..d98312d 100644
--- a/xiaomusic/xiaomusic.py
+++ b/xiaomusic/xiaomusic.py
@@ -483,7 +483,7 @@ class XiaoMusic:
def ensure_single_thread_for_tag(self):
if self._tag_generation_task:
- self.log.info(f"tag 更新中,请等待")
+ self.log.info("tag 更新中,请等待")
return not self._tag_generation_task
def try_gen_all_music_tag(self, only_items: dict = None):
@@ -499,7 +499,7 @@ class XiaoMusic:
self._tag_generation_task = True
if only_items is None:
only_items = self.all_music # 默认更新全部
-
+
all_music_tags = self.try_load_from_tag_cache()
all_music_tags.update(self.all_music_tags) # 保证最新
for name, file_or_url in only_items.items():
@@ -520,7 +520,7 @@ class XiaoMusic:
# 刷新 tag cache
self.try_save_tag_cache()
self._tag_generation_task = False
- self.log.info(f"tag 更新完成")
+ self.log.info("tag 更新完成")
# 获取目录下所有歌曲,生成随机播放列表
def _gen_all_music_list(self):