feat: 支持下载的目录与本地音乐目录分开 see #98

This commit is contained in:
涵曦 2024-07-05 15:12:36 +00:00
parent 1919bc84d9
commit f4d9a6c1fd
3 changed files with 15 additions and 3 deletions

View File

@ -65,7 +65,10 @@ class Config:
hardware: str = os.getenv("MI_HARDWARE", "L07A") # 逗号分割支持多设备 hardware: str = os.getenv("MI_HARDWARE", "L07A") # 逗号分割支持多设备
cookie: str = "" cookie: str = ""
verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true" verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true"
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music") music_path: str = os.getenv(
"XIAOMUSIC_MUSIC_PATH", "music"
) # 只能是music目录下的子目录
download_path: str = os.getenv("XIAOMUSIC_DOWNLOAD_PATH", "")
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None) conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None)
hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5") hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5")
port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口 port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口

View File

@ -49,6 +49,9 @@ var vConsole = new window.VConsole();
<label for="music_path">音乐目录:</label> <label for="music_path">音乐目录:</label>
<input id="music_path" type="text" value="music"></input> <input id="music_path" type="text" value="music"></input>
<label for="download_path">音乐下载目录(必须是music的子目录):</label>
<input id="download_path" type="text"></input>
<label for="conf_path">配置文件目录:</label> <label for="conf_path">配置文件目录:</label>
<input id="conf_path" type="text"></input> <input id="conf_path" type="text"></input>

View File

@ -106,6 +106,12 @@ class XiaoMusic:
self.conf_path = self.config.conf_path self.conf_path = self.config.conf_path
if not self.conf_path: if not self.conf_path:
self.conf_path = self.config.music_path self.conf_path = self.config.music_path
self.download_path = self.config.download_path
if not self.download_path:
self.download_path = self.music_path
if not os.path.exists(self.download_path):
os.makedirs(self.download_path)
self.hostname = self.config.hostname self.hostname = self.config.hostname
self.port = self.config.port self.port = self.config.port
@ -373,7 +379,7 @@ class XiaoMusic:
"--audio-format", "--audio-format",
"mp3", "mp3",
"--paths", "--paths",
self.music_path, self.download_path,
"-o", "-o",
f"{name}.mp3", f"{name}.mp3",
"--ffmpeg-location", "--ffmpeg-location",
@ -551,7 +557,7 @@ class XiaoMusic:
# 把下载的音乐加入播放列表 # 把下载的音乐加入播放列表
def add_download_music(self, name): def add_download_music(self, name):
self._all_music[name] = os.path.join(self.music_path, f"{name}.mp3") self._all_music[name] = os.path.join(self.download_path, f"{name}.mp3")
if name not in self._play_list: if name not in self._play_list:
self._play_list.append(name) self._play_list.append(name)
self.log.debug("add_music %s", name) self.log.debug("add_music %s", name)