mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-05-09 00:34:25 +08:00
feat(api): 优化音乐信息获取接口,解除TailWind主题下仅支持mp3文件播放的限制 (#852)
* feat: 支持自定义temp_path路径,临时文件不再依赖music_path挂载 以前临时文件需挂载在music_path下才能访问,现在temp/前缀的文件直接从 config.temp_path提供访问,支持自定义任意临时目录路径。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat: 增强OGG封面解析,支持FLAC二进制结构的metadata_block_picture 解析metadata_block_picture标签时,先尝试JSON格式再尝试FLAC二进制结构格式, 兼容更多工具生成的OGG文件封面数据。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(api): 优化音乐信息获取接口 - 将 musicinfos 接口从 GET 请求改为 POST 请求以支持批量查询 - 添加 MusicInfosQuery 模型用于接收音乐信息查询参数 - 在前端 API 调用中使用 JSON 格式传输歌曲名称数组 - 扩展音频文件格式验证,支持 mp3、flac、wav、ogg、aac、m4a、wma、ape 等格式 - 保留 musictag 参数功能以控制是否返回音乐标签信息 --------- Co-authored-by: mwjdot888 <mwjdot888@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: maowenjun <dot888@qq.com>
This commit is contained in:
@@ -72,3 +72,8 @@ class PlayListUpdateObj(BaseModel):
|
||||
class PlayListMusicObj(BaseModel):
|
||||
name: str = "" # 歌单名
|
||||
music_list: list[str] # 歌曲名列表
|
||||
|
||||
|
||||
class MusicInfosQuery(BaseModel):
|
||||
name: list[str]
|
||||
musictag: bool = False
|
||||
|
||||
@@ -21,6 +21,7 @@ from xiaomusic.api.dependencies import (
|
||||
from xiaomusic.api.models import (
|
||||
DidPlayMusic,
|
||||
MusicInfoObj,
|
||||
MusicInfosQuery,
|
||||
MusicItem,
|
||||
)
|
||||
|
||||
@@ -267,6 +268,22 @@ async def musicinfos(
|
||||
return ret
|
||||
|
||||
|
||||
@router.post("/musicinfos")
|
||||
async def musicinfos_post(data: MusicInfosQuery):
|
||||
"""批量音乐信息(POST,避免 URL 过长)"""
|
||||
ret = []
|
||||
for music_name in data.name:
|
||||
url, _ = await xiaomusic.music_library.get_music_url(music_name)
|
||||
info = {
|
||||
"name": music_name,
|
||||
"url": url,
|
||||
}
|
||||
if data.musictag:
|
||||
info["tags"] = await xiaomusic.music_library.get_music_tags(music_name)
|
||||
ret.append(info)
|
||||
return ret
|
||||
|
||||
|
||||
@router.post("/setmusictag")
|
||||
async def setmusictag(info: MusicInfoObj):
|
||||
"""设置音乐标签"""
|
||||
|
||||
14
xiaomusic/static/tailwind/api.js
vendored
14
xiaomusic/static/tailwind/api.js
vendored
@@ -11,12 +11,14 @@ const API = {
|
||||
if (!Array.isArray(songNames)) {
|
||||
throw new Error('songNames must be an array');
|
||||
}
|
||||
|
||||
const queryParams = songNames
|
||||
.map(name => `name=${encodeURIComponent(name)}`)
|
||||
.join('&');
|
||||
|
||||
const response = await fetch(`/musicinfos?${queryParams}&musictag=true`);
|
||||
|
||||
const response = await fetch('/musicinfos', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ name: songNames, musictag: true })
|
||||
});
|
||||
return response.json();
|
||||
},
|
||||
|
||||
|
||||
3
xiaomusic/static/tailwind/index.html
vendored
3
xiaomusic/static/tailwind/index.html
vendored
@@ -927,7 +927,8 @@
|
||||
|
||||
// 验证URL是否有效
|
||||
const validUrl = new URL(musicInfo.url);
|
||||
if (!validUrl.pathname.endsWith('.mp3')) {
|
||||
const audioExts = ['.mp3', '.flac', '.wav', '.ogg', '.aac', '.m4a', '.wma', '.ape'];
|
||||
if (!audioExts.some(ext => validUrl.pathname.endsWith(ext))) {
|
||||
console.error('Invalid music URL format:', validUrl);
|
||||
showMessage('音乐文件格式不支持', 'alert-error');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user