feat: 临时文件目录支持配置 #99
This commit is contained in:
parent
def63b2407
commit
74837baaef
@ -88,9 +88,8 @@ class Config:
|
|||||||
miio_tts_command: str = os.getenv("MIIO_TTS_CMD", "")
|
miio_tts_command: str = os.getenv("MIIO_TTS_CMD", "")
|
||||||
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(
|
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music")
|
||||||
"XIAOMUSIC_MUSIC_PATH", "music"
|
temp_path: str = os.getenv("XIAOMUSIC_TEMP_PATH", "music/tmp")
|
||||||
) # 只能是music目录下的子目录
|
|
||||||
download_path: str = os.getenv("XIAOMUSIC_DOWNLOAD_PATH", "music/download")
|
download_path: str = os.getenv("XIAOMUSIC_DOWNLOAD_PATH", "music/download")
|
||||||
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", "conf")
|
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", "conf")
|
||||||
cache_dir: str = os.getenv("XIAOMUSIC_CACHE_DIR", "cache")
|
cache_dir: str = os.getenv("XIAOMUSIC_CACHE_DIR", "cache")
|
||||||
@ -307,6 +306,12 @@ class Config:
|
|||||||
cookies_path = os.path.join(self.conf_path, "yt-dlp-cookie.txt")
|
cookies_path = os.path.join(self.conf_path, "yt-dlp-cookie.txt")
|
||||||
return cookies_path
|
return cookies_path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def temp_dir(self):
|
||||||
|
if not os.path.exists(self.temp_path):
|
||||||
|
os.makedirs(self.temp_path)
|
||||||
|
return self.temp_path
|
||||||
|
|
||||||
def get_play_type_tts(self, play_type):
|
def get_play_type_tts(self, play_type):
|
||||||
if play_type == PLAY_TYPE_ONE:
|
if play_type == PLAY_TYPE_ONE:
|
||||||
return self.play_type_one_tts_msg
|
return self.play_type_one_tts_msg
|
||||||
|
@ -71,10 +71,12 @@ var vConsole = new window.VConsole();
|
|||||||
<label for="conf_path">配置文件目录:</label>
|
<label for="conf_path">配置文件目录:</label>
|
||||||
<input id="conf_path" type="text"></input>
|
<input id="conf_path" type="text"></input>
|
||||||
|
|
||||||
|
|
||||||
<label for="cache_dir">缓存文件目录:</label>
|
<label for="cache_dir">缓存文件目录:</label>
|
||||||
<input id="cache_dir" type="text"></input>
|
<input id="cache_dir" type="text"></input>
|
||||||
|
|
||||||
|
<label for="temp_path">临时文件目录:</label>
|
||||||
|
<input id="temp_path" type="text" value="music/tmp"></input>
|
||||||
|
|
||||||
<label for="ffmpeg_location">ffmpeg路径:</label>
|
<label for="ffmpeg_location">ffmpeg路径:</label>
|
||||||
<input id="ffmpeg_location" type="text" value="./ffmpeg/bin"></input>
|
<input id="ffmpeg_location" type="text" value="./ffmpeg/bin"></input>
|
||||||
|
|
||||||
|
@ -407,14 +407,6 @@ def no_padding(info):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def get_temp_dir(music_path: str):
|
|
||||||
# 指定临时文件的目录为 music_path 目录下的 tmp 文件夹
|
|
||||||
temp_dir = os.path.join(music_path, "tmp")
|
|
||||||
if not os.path.exists(temp_dir):
|
|
||||||
os.makedirs(temp_dir) # 确保目录存在
|
|
||||||
return temp_dir
|
|
||||||
|
|
||||||
|
|
||||||
def remove_id3_tags(input_file: str, config) -> str:
|
def remove_id3_tags(input_file: str, config) -> str:
|
||||||
audio = MP3(input_file, ID3=ID3)
|
audio = MP3(input_file, ID3=ID3)
|
||||||
|
|
||||||
@ -426,7 +418,7 @@ def remove_id3_tags(input_file: str, config) -> str:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
music_path = config.music_path
|
music_path = config.music_path
|
||||||
temp_dir = get_temp_dir(music_path)
|
temp_dir = config.temp_dir
|
||||||
|
|
||||||
# 构造新文件的路径
|
# 构造新文件的路径
|
||||||
out_file_name = os.path.splitext(os.path.basename(input_file))[0]
|
out_file_name = os.path.splitext(os.path.basename(input_file))[0]
|
||||||
@ -459,7 +451,7 @@ def remove_id3_tags(input_file: str, config) -> str:
|
|||||||
|
|
||||||
def convert_file_to_mp3(input_file: str, config) -> str:
|
def convert_file_to_mp3(input_file: str, config) -> str:
|
||||||
music_path = config.music_path
|
music_path = config.music_path
|
||||||
temp_dir = get_temp_dir(music_path)
|
temp_dir = config.temp_dir
|
||||||
|
|
||||||
out_file_name = os.path.splitext(os.path.basename(input_file))[0]
|
out_file_name = os.path.splitext(os.path.basename(input_file))[0]
|
||||||
out_file_path = os.path.join(temp_dir, f"{out_file_name}.mp3")
|
out_file_path = os.path.join(temp_dir, f"{out_file_name}.mp3")
|
||||||
|
Loading…
Reference in New Issue
Block a user