feat: 新增更新提醒
This commit is contained in:
parent
609cb4f10f
commit
6e8830c4e6
@ -25,6 +25,7 @@ from xiaomusic import __version__
|
|||||||
from xiaomusic.utils import (
|
from xiaomusic.utils import (
|
||||||
deepcopy_data_no_sensitive_info,
|
deepcopy_data_no_sensitive_info,
|
||||||
downloadfile,
|
downloadfile,
|
||||||
|
get_latest_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
xiaomusic = None
|
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
|
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 def file_iterator(file_path, start, end):
|
||||||
async with aiofiles.open(file_path, mode="rb") as file:
|
async with aiofiles.open(file_path, mode="rb") as file:
|
||||||
await file.seek(start)
|
await file.seek(start)
|
||||||
|
@ -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) {
|
$.get("/getversion", function(data, status) {
|
||||||
console.log(data, status, data["version"]);
|
console.log(data, status, data["version"]);
|
||||||
$("#version").text(`${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("🆕");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 拉取播放列表
|
// 拉取播放列表
|
||||||
|
@ -26,9 +26,8 @@ var vConsole = new window.VConsole();
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>小爱音箱操控面板
|
<h2>小爱音箱操控面板
|
||||||
(<a id="version" href="https://github.com/hanxi/xiaomusic/blob/main/CHANGELOG.md">
|
(<a id="version" href="https://github.com/hanxi/xiaomusic/blob/main/CHANGELOG.md">版本未知</a>)
|
||||||
版本未知
|
<span id="versionnew" class="blink"></span>
|
||||||
</a>)
|
|
||||||
</h2>
|
</h2>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
@ -90,3 +90,13 @@ footer {
|
|||||||
max-width: 480px;
|
max-width: 480px;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes blink {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.blink {
|
||||||
|
animation: blink 1s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,8 @@ def find_best_match(user_input, collection, cutoff=0.6, n=1, extra_search_index=
|
|||||||
|
|
||||||
# 如果数量不满足,继续搜索
|
# 如果数量不满足,继续搜索
|
||||||
lower_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
|
if v not in cur_matched_collection
|
||||||
}
|
}
|
||||||
matches = real_search(user_input, lower_extra_search_index.keys(), cutoff, n)
|
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)}"
|
return f"{li[:2]} ... {li[-2:]} with len: {len(li)}"
|
||||||
else:
|
else:
|
||||||
return f"{li}"
|
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
|
||||||
|
@ -483,7 +483,7 @@ class XiaoMusic:
|
|||||||
|
|
||||||
def ensure_single_thread_for_tag(self):
|
def ensure_single_thread_for_tag(self):
|
||||||
if self._tag_generation_task:
|
if self._tag_generation_task:
|
||||||
self.log.info(f"tag 更新中,请等待")
|
self.log.info("tag 更新中,请等待")
|
||||||
return not self._tag_generation_task
|
return not self._tag_generation_task
|
||||||
|
|
||||||
def try_gen_all_music_tag(self, only_items: dict = None):
|
def try_gen_all_music_tag(self, only_items: dict = None):
|
||||||
@ -499,7 +499,7 @@ class XiaoMusic:
|
|||||||
self._tag_generation_task = True
|
self._tag_generation_task = True
|
||||||
if only_items is None:
|
if only_items is None:
|
||||||
only_items = self.all_music # 默认更新全部
|
only_items = self.all_music # 默认更新全部
|
||||||
|
|
||||||
all_music_tags = self.try_load_from_tag_cache()
|
all_music_tags = self.try_load_from_tag_cache()
|
||||||
all_music_tags.update(self.all_music_tags) # 保证最新
|
all_music_tags.update(self.all_music_tags) # 保证最新
|
||||||
for name, file_or_url in only_items.items():
|
for name, file_or_url in only_items.items():
|
||||||
@ -520,7 +520,7 @@ class XiaoMusic:
|
|||||||
# 刷新 tag cache
|
# 刷新 tag cache
|
||||||
self.try_save_tag_cache()
|
self.try_save_tag_cache()
|
||||||
self._tag_generation_task = False
|
self._tag_generation_task = False
|
||||||
self.log.info(f"tag 更新完成")
|
self.log.info("tag 更新完成")
|
||||||
|
|
||||||
# 获取目录下所有歌曲,生成随机播放列表
|
# 获取目录下所有歌曲,生成随机播放列表
|
||||||
def _gen_all_music_list(self):
|
def _gen_all_music_list(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user