feat: 新增设置项 ignore_tag_dirs 用于忽略读取目录下的标签信息,解决挂载 alist 目录的问题

This commit is contained in:
涵曦 2024-12-11 09:58:16 +08:00
parent 9ed39d0c02
commit 12532b48d6
5 changed files with 34 additions and 1 deletions

View File

@ -106,6 +106,7 @@ class Config:
"play,set_play_type_rnd,playlocal,play_music_list,play_music_list_index,stop_after_minute,stop",
)
exclude_dirs: str = os.getenv("XIAOMUSIC_EXCLUDE_DIRS", "@eaDir,tmp")
ignore_tag_dirs: str = os.getenv("XIAOMUSIC_IGNORE_TAG_DIRS", "")
music_path_depth: int = int(os.getenv("XIAOMUSIC_MUSIC_PATH_DEPTH", "10"))
disable_httpauth: bool = (
os.getenv("XIAOMUSIC_DISABLE_HTTPAUTH", "true").lower() == "true"
@ -330,3 +331,11 @@ class Config:
if play_type == PLAY_TYPE_SEQ:
return self.play_type_seq_tts_msg
return ""
def get_ignore_tag_dirs(self):
ignore_tag_absolute_dirs = []
for ignore_tag_dir in self.ignore_tag_dirs.split(","):
if ignore_tag_dir:
ignore_tag_absolute_path = os.path.abspath(ignore_tag_dir)
ignore_tag_absolute_dirs.append(ignore_tag_absolute_path)
return ignore_tag_absolute_dirs

View File

@ -99,6 +99,9 @@ var vConsole = new window.VConsole();
<label for="exclude_dirs">忽略目录(逗号分割):</label>
<input id="exclude_dirs" type="text" value="@eaDir,tmp" />
<label for="ignore_tag_dirs">不扫码标签信息目录(逗号分割):</label>
<input id="ignore_tag_dirs" type="text" value="" />
<label for="music_path_depth">目录深度:</label>
<input id="music_path_depth" type="number" value="10" />

View File

@ -98,6 +98,9 @@ var vConsole = new window.VConsole();
<label for="exclude_dirs">忽略目录(逗号分割):</label>
<input id="exclude_dirs" type="text" value="@eaDir,tmp" />
<label for="ignore_tag_dirs">不扫码标签信息目录(逗号分割):</label>
<input id="ignore_tag_dirs" type="text" value="" />
<label for="music_path_depth">目录深度:</label>
<input id="music_path_depth" type="number" value="10" />

View File

@ -990,3 +990,15 @@ def try_add_access_control_param(config, url):
).geturl()
return new_url
# 判断文件在不在排除目录列表
def not_in_dirs(filename, ignore_absolute_dirs):
file_absolute_path = os.path.abspath(filename)
file_dir = os.path.dirname(file_absolute_path)
for ignore_dir in ignore_absolute_dirs:
if file_dir.startswith(ignore_dir):
log.info(f"{file_dir} in {ignore_dir}")
return False # 文件在排除目录中
return True # 文件不在排除目录中

View File

@ -49,6 +49,7 @@ from xiaomusic.utils import (
get_local_music_duration,
get_web_music_duration,
list2str,
not_in_dirs,
parse_cookie_string,
parse_str_to_dict,
save_picture_by_base64,
@ -577,6 +578,9 @@ class XiaoMusic:
all_music_tags = self.try_load_from_tag_cache()
all_music_tags.update(self.all_music_tags) # 保证最新
ignore_tag_absolute_dirs = self.config.get_ignore_tag_dirs()
self.log.info(f"ignore_tag_absolute_dirs: {ignore_tag_absolute_dirs}")
for name, file_or_url in only_items.items():
start = time.perf_counter()
if name not in all_music_tags:
@ -584,7 +588,9 @@ class XiaoMusic:
if self.is_web_music(name):
# TODO: 网络歌曲获取歌曲额外信息
pass
elif os.path.exists(file_or_url):
elif os.path.exists(file_or_url) and not_in_dirs(
file_or_url, ignore_tag_absolute_dirs
):
all_music_tags[name] = extract_audio_metadata(
file_or_url, self.config.picture_cache_path
)