diff --git a/xiaomusic/config.py b/xiaomusic/config.py index 6c2f293..13a6228 100644 --- a/xiaomusic/config.py +++ b/xiaomusic/config.py @@ -97,6 +97,7 @@ class Config: conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", "conf") cache_dir: str = os.getenv("XIAOMUSIC_CACHE_DIR", "music/cache") cache_max_size_mb: int = int(os.getenv("XIAOMUSIC_CACHE_MAX_SIZE_MB", "500")) + cache_song_name: str = os.getenv("XIAOMUSIC_CACHE_SONG_NAME", "cache_songs") hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "http://192.168.2.5") port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口 public_port: int = int(os.getenv("XIAOMUSIC_PUBLIC_PORT", 58090)) # 歌曲访问端口 @@ -133,7 +134,7 @@ class Config: os.getenv("XIAOMUSIC_USE_MUSIC_API", "false").lower() == "true" ) use_music_audio_id: str = os.getenv( - "XIAOMUSIC_USE_MUSIC_AUDIO_ID", "1582971365183456177" + "XIAOMUSIC_USE_MUSIC_AUDIO_ID", "436490277987655" ) use_music_id: str = os.getenv("XIAOMUSIC_USE_MUSIC_ID", "355454500") log_file: str = os.getenv("XIAOMUSIC_LOG_FILE", "xiaomusic.log.txt") @@ -153,19 +154,25 @@ class Config: ) # 多结果处理方式: random=随机播放, first=从第一个开始播放 multi_result_action: str = os.getenv("XIAOMUSIC_MULTI_RESULT_ACTION", "random") - stop_tts_msg: str = os.getenv("XIAOMUSIC_STOP_TTS_MSG", "收到,再见") + stop_tts_msg: str = os.getenv("XIAOMUSIC_STOP_TTS_MSG", "") enable_config_example: bool = False keywords_playlocal: str = os.getenv( "XIAOMUSIC_KEYWORDS_PLAYLOCAL", "播放本地歌曲,本地播放歌曲" ) keywords_play: str = os.getenv("XIAOMUSIC_KEYWORDS_PLAY", "播放歌曲,放歌曲") - keywords_online_play: str = os.getenv("XIAOMUSIC_KEYWORDS_ONLINE_PLAY", "在线播放") + keywords_online_play: str = os.getenv( + "XIAOMUSIC_KEYWORDS_ONLINE_PLAY", "在线播放,搜索歌曲" + ) keywords_online_playlist_play: str = os.getenv( "XIAOMUSIC_KEYWORDS_ONLINE_PLAYLIST", "在线歌单,搜索歌单" ) - keywords_singer_play: str = os.getenv("XIAOMUSIC_KEYWORDS_SINGER_PLAY", "播放歌手") - keywords_stop: str = os.getenv("XIAOMUSIC_KEYWORDS_STOP", "关机,暂停,停止,停止播放") + keywords_singer_play: str = os.getenv( + "XIAOMUSIC_KEYWORDS_SINGER_PLAY", "播放歌手,搜索歌手" + ) + keywords_stop: str = os.getenv( + "XIAOMUSIC_KEYWORDS_STOP", "关机,暂停,停止,停止播放,关闭,退出,关掉音乐" + ) keywords_playlist: str = os.getenv( "XIAOMUSIC_KEYWORDS_PLAYLIST", "播放列表,播放歌单" ) @@ -184,9 +191,7 @@ class Config: ) convert_to_mp3: bool = os.getenv("CONVERT_TO_MP3", "false").lower() == "true" delay_sec: int = int(os.getenv("XIAOMUSIC_DELAY_SEC", 0)) # 下一首歌延迟播放秒数 - continue_play: bool = ( - os.getenv("XIAOMUSIC_CONTINUE_PLAY", "false").lower() == "true" - ) + continue_play: bool = os.getenv("XIAOMUSIC_CONTINUE_PLAY", "true").lower() == "true" # 目录监控配置 enable_file_watch: bool = ( os.getenv("XIAOMUSIC_ENABLE_FILE_WATCH", "false").lower() == "true" diff --git a/xiaomusic/music_library.py b/xiaomusic/music_library.py index 8855c27..3cbf51e 100644 --- a/xiaomusic/music_library.py +++ b/xiaomusic/music_library.py @@ -829,7 +829,9 @@ class MusicLibrary: ) # 将纠正后的 actual_cache_dir 传给底层 - return build_cache_file_path(datab64, name, actual_cache_dir) + return build_cache_file_path( + datab64, name, actual_cache_dir, self.config.cache_song_name + ) except Exception as e: self.log.debug(f"提取缓存路径失败: {e}") return "" @@ -945,6 +947,7 @@ class MusicLibrary: clean_old_caches, self.config.cache_dir, getattr(self.config, "cache_max_size_mb", 0), + self.config.cache_song_name, ) ) cleanup_task.add_done_callback(lambda t: t.exception()) diff --git a/xiaomusic/static/default/setting.html b/xiaomusic/static/default/setting.html index 278bc58..26e81b4 100644 --- a/xiaomusic/static/default/setting.html +++ b/xiaomusic/static/default/setting.html @@ -232,23 +232,44 @@ - - - - - + + - - +
+ +
+ + +
+ + +
+ + + int: return 0 -def clean_old_caches(cache_dir: str, max_size_mb: int) -> None: +def clean_old_caches( + cache_dir: str, max_size_mb: int, cache_song_name: str = "cache_songs" +) -> None: """ LRU 清理逻辑:当缓存目录总大小超过设定阈值(MB)时,删除最旧的文件。 """ @@ -268,7 +270,7 @@ def clean_old_caches(cache_dir: str, max_size_mb: int) -> None: return max_size_bytes = max_size_mb * 1024 * 1024 - songs_dir = os.path.join(cache_dir, "songs") + songs_dir = os.path.join(cache_dir, cache_song_name) if not os.path.exists(songs_dir): return diff --git a/xiaomusic/utils/music_utils.py b/xiaomusic/utils/music_utils.py index 325d2e3..6d197f1 100644 --- a/xiaomusic/utils/music_utils.py +++ b/xiaomusic/utils/music_utils.py @@ -817,7 +817,9 @@ def get_real_audio_format(file_path: str) -> str: return "mp3" -def build_cache_file_path(datab64: str, name: str, cache_dir: str) -> str: +def build_cache_file_path( + datab64: str, name: str, cache_dir: str, cache_song_name: str = "cache_songs" +) -> str: """ 根据核心字段生成唯一缓存路径,彻底免疫一切前端和插件附加的动态干扰字段。 """ @@ -843,4 +845,4 @@ def build_cache_file_path(datab64: str, name: str, cache_dir: str) -> str: safe_name = re.sub(r"[^\w\-_.\s()()\[\]【】]", "_", name) filename = f"{short_hash}_{safe_name}.mp3" - return os.path.join(cache_dir, "songs", filename) + return os.path.join(cache_dir, cache_song_name, filename) diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index cb43d13..77e5583 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -175,7 +175,9 @@ class XiaoMusic: if not os.path.exists(self.config.download_path): os.makedirs(self.config.download_path) - songs_cache_dir = os.path.join(self.config.cache_dir, "songs") + songs_cache_dir = os.path.join( + self.config.cache_dir, self.config.cache_song_name + ) if getattr(self.config, "cache_max_size_mb", 0) > 0 and not os.path.exists( songs_cache_dir ):