增加了保存歌词时不保存歌词时间的设定,增加了自动初始化文件夹的功能,修复了设置歌词文件名格式不生效的bug

This commit is contained in:
Onlyacat233
2023-08-09 14:36:46 +08:00
parent c10bd094da
commit 9078104529
23 changed files with 55 additions and 27 deletions

View File

@@ -30,7 +30,7 @@ def wait_retry(kind, identify, bar=None):
def get_song_info_raw(types: list, identify: str, bar: CompactBar = None):
"""获取歌曲信息
``types`` 提供一个list,将会返回内部所有符合要求的信息类型\n
``identify`` 提供一个歌曲id(str),将会把歌曲的`types`信息返回"""
bprint(Fore.CYAN + "ID:%s" % identify, bar)
@@ -63,9 +63,10 @@ def get_song_lyric(identify: str | int | dict,
path: str,
lyric_format="%(name)s - %(artists)s",
allinfo: bool = False,
bar: CompactBar = None):
bar: CompactBar = None,
save_lyrics_time: bool = True):
"""获取歌词
``identify`` 提供一个歌曲id
``path`` 提供歌曲下载的路径
``lyric_format`` 提供歌词保存的格式
@@ -122,6 +123,12 @@ def get_song_lyric(identify: str | int | dict,
return
else:
with open(os.path.join(path, filename), "w", encoding="utf-8") as f:
f.write(info["lyric"])
bprint(Fore.GREEN + "\t--> 歌词下载完成!被保存在" + Style.RESET_ALL + f"{os.path.join(path, filename)}\n", bar)
if not save_lyrics_time:
for lyric in info["lyric"].split("\n"):
print(lyric)
f.write("".join(lyric.split("]")[1:]))
f.write('\n')
else:
f.write(info["lyric"])
bprint(Fore.GREEN + "\t--> 歌词下载完成!文件被保存在" + Style.RESET_ALL + f"{os.path.join(path, filename)}\n", bar)
return

View File

@@ -23,6 +23,6 @@ def download_one_lyric(self):
input("不合法的形式.\n按回车键返回...")
return
if get_song_lyric(int(song_id), self.settings.lyric_path) == "dl_err_connection":
if get_song_lyric(int(song_id), self.settings.lyric_path, self.settings.lyric_format, save_lyrics_time = self.settings.save_lyrics_time) == "dl_err_connection":
input("下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键返回...")
input("按回车键返回...")