Skip to content

Commit

Permalink
feat: 支持下载的目录与本地音乐目录分开 see #98
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 5, 2024
1 parent 1919bc8 commit f4d9a6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class Config:
hardware: str = os.getenv("MI_HARDWARE", "L07A") # 逗号分割支持多设备
cookie: str = ""
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)
hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5")
port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口
Expand Down
3 changes: 3 additions & 0 deletions xiaomusic/static/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ <h2>小爱音箱设置面板
<label for="music_path">音乐目录:</label>
<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>
<input id="conf_path" type="text"></input>

Expand Down
10 changes: 8 additions & 2 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def init_config(self):
self.conf_path = self.config.conf_path
if not self.conf_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.port = self.config.port
Expand Down Expand Up @@ -373,7 +379,7 @@ async def download(self, search_key, name):
"--audio-format",
"mp3",
"--paths",
self.music_path,
self.download_path,
"-o",
f"{name}.mp3",
"--ffmpeg-location",
Expand Down Expand Up @@ -551,7 +557,7 @@ def _gen_play_list(self):

# 把下载的音乐加入播放列表
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:
self._play_list.append(name)
self.log.debug("add_music %s", name)
Expand Down

0 comments on commit f4d9a6c

Please sign in to comment.