feat: 新增修改tag缓存信息的接口 close #266
This commit is contained in:
parent
df3c4b7fa9
commit
87fb34e5c9
@ -303,6 +303,23 @@ async def musicinfos(
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class MusicInfoObj(BaseModel):
|
||||||
|
musicname: str
|
||||||
|
title: str = ""
|
||||||
|
artist: str = ""
|
||||||
|
album: str = ""
|
||||||
|
year: str = ""
|
||||||
|
genre: str = ""
|
||||||
|
lyrics: str = ""
|
||||||
|
picture: str = "" # base64
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/setmusictag")
|
||||||
|
async def setmusictag(info: MusicInfoObj, Verifcation=Depends(verification)):
|
||||||
|
ret = xiaomusic.set_music_tag(info.musicname, info)
|
||||||
|
return {"ret": ret}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/curplaylist")
|
@app.get("/curplaylist")
|
||||||
async def curplaylist(did: str = "", Verifcation=Depends(verification)):
|
async def curplaylist(did: str = "", Verifcation=Depends(verification)):
|
||||||
if not xiaomusic.did_exist(did):
|
if not xiaomusic.did_exist(did):
|
||||||
|
@ -596,6 +596,15 @@ def _to_utf8(v):
|
|||||||
return str(v)
|
return str(v)
|
||||||
|
|
||||||
|
|
||||||
|
def save_picture_by_base64(picture_base64_data, save_root, file_path):
|
||||||
|
try:
|
||||||
|
picture_data = base64.b64decode(picture_base64_data)
|
||||||
|
except (TypeError, ValueError) as e:
|
||||||
|
log.exception(f"Error decoding base64 data: {e}")
|
||||||
|
return None
|
||||||
|
return _save_picture(picture_data, save_root, file_path)
|
||||||
|
|
||||||
|
|
||||||
def _save_picture(picture_data, save_root, file_path):
|
def _save_picture(picture_data, save_root, file_path):
|
||||||
# 计算文件名的哈希值
|
# 计算文件名的哈希值
|
||||||
file_hash = hashlib.md5(file_path.encode("utf-8")).hexdigest()
|
file_hash = hashlib.md5(file_path.encode("utf-8")).hexdigest()
|
||||||
|
@ -50,6 +50,7 @@ from xiaomusic.utils import (
|
|||||||
list2str,
|
list2str,
|
||||||
parse_cookie_string,
|
parse_cookie_string,
|
||||||
parse_str_to_dict,
|
parse_str_to_dict,
|
||||||
|
save_picture_by_base64,
|
||||||
traverse_music_directory,
|
traverse_music_directory,
|
||||||
try_add_access_control_param,
|
try_add_access_control_param,
|
||||||
)
|
)
|
||||||
@ -463,6 +464,27 @@ class XiaoMusic:
|
|||||||
)
|
)
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
# 修改标签信息
|
||||||
|
def set_music_tag(self, name, info):
|
||||||
|
if self._tag_generation_task:
|
||||||
|
self.log.info("tag 更新中,请等待")
|
||||||
|
return "Tag generation task running"
|
||||||
|
tags = copy.copy(self.all_music_tags.get(name, asdict(Metadata())))
|
||||||
|
tags["title"] = info.title
|
||||||
|
tags["artist"] = info.artist
|
||||||
|
tags["album"] = info.album
|
||||||
|
tags["year"] = info.year
|
||||||
|
tags["genre"] = info.genre
|
||||||
|
tags["lyrics"] = info.lyrics
|
||||||
|
if info.picture:
|
||||||
|
file_path = self.all_music[name]
|
||||||
|
tags["picture"] = save_picture_by_base64(
|
||||||
|
info.picture, self.config.picture_cache_path, file_path
|
||||||
|
)
|
||||||
|
self.all_music_tags[name] = tags
|
||||||
|
self.try_save_tag_cache()
|
||||||
|
return "OK"
|
||||||
|
|
||||||
def get_music_url(self, name):
|
def get_music_url(self, name):
|
||||||
if self.is_web_music(name):
|
if self.is_web_music(name):
|
||||||
url = self.all_music[name]
|
url = self.all_music[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user