Settings: Filename Format Set
and small changes to follow PEP8 code style change default README to Chinese
This commit is contained in:
@@ -59,11 +59,16 @@ def get_song_info_raw(types: list, identify: str, bar: CompactBar = None):
|
||||
return need
|
||||
|
||||
|
||||
def get_song_lyric(identify: str | int | dict, path: str, allinfo: bool = False, bar: CompactBar = None):
|
||||
def get_song_lyric(identify: str | int | dict,
|
||||
path: str,
|
||||
lyric_format="%(name)s - %(artists)s",
|
||||
allinfo: bool = False,
|
||||
bar: CompactBar = None):
|
||||
"""获取歌词
|
||||
|
||||
``identify`` 提供一个歌曲id
|
||||
``path`` 提供歌曲下载的路径
|
||||
``lyric_format`` 提供歌词保存的格式
|
||||
``allinfo`` 若此项为 True ,则提供的identify格式必须为存储在网易云下载文件中meta_data的格式
|
||||
``bar`` 若获取歌词时下方有进度条, 则应当传入此参数"""
|
||||
if allinfo:
|
||||
@@ -96,7 +101,7 @@ def get_song_lyric(identify: str | int | dict, path: str, allinfo: bool = False,
|
||||
artists = regular_filename(artists)
|
||||
|
||||
bprint(Fore.YELLOW + "\t-> 歌曲:" + Style.RESET_ALL + f"{name} - {artists}", bar)
|
||||
filename = f"{name} - {artists}.lrc"
|
||||
filename = f"{lyric_format % {'name': name, 'artists': artists}}.lrc"
|
||||
|
||||
try:
|
||||
info = post(f"https://music.163.com/api/song/media?id={identify}").json()
|
||||
|
@@ -217,7 +217,7 @@ def get_lyric_from_folder(self):
|
||||
with CompactArrowBar(f"进度: %(index){len(str(len(musics)))}d/%(max)d",
|
||||
suffix="", max=len(musics), color="yellow", width=9999) as bar:
|
||||
for i in range(0, len(musics)): # 根据索引结果获取歌词
|
||||
if get_song_lyric(musics[i], lyric_path, allinfo=True, bar=bar) == "dl_err_connection":
|
||||
if get_song_lyric(musics[i], lyric_path, self.settings.lyric_format, True, bar) == "dl_err_connection":
|
||||
bar.print_onto_bar(Fore.RED + "下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键继续任务(该任务会被跳过)...")
|
||||
input()
|
||||
bar.next()
|
||||
|
@@ -34,7 +34,7 @@ def mdl(self):
|
||||
with CompactArrowBar(f"进度: %(index){len(str(len(ids)))}d/%(max)d",
|
||||
suffix="", max=len(ids), color="yellow", width=9999) as bar:
|
||||
for i in range(0, len(ids)):
|
||||
r = get_song_lyric(ids[i], self.settings.lyric_path, bar=bar)
|
||||
r = get_song_lyric(ids[i], self.settings.lyric_path, self.settings.lyric_path, bar=bar)
|
||||
if r == "dl_err_connection":
|
||||
bar.print_onto_bar(Fore.RED + "下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键继续任务(该任务会被跳过)...")
|
||||
input()
|
||||
|
@@ -5,7 +5,7 @@ from colorama import Fore
|
||||
from modules.utils.clear_screen import cls_stay
|
||||
from modules.utils.inputs import rinput, cinput
|
||||
from modules.functions.settings.save_load_settings import save_settings
|
||||
from modules.utils.prints import print_menu
|
||||
from modules.utils.prints import input_menu
|
||||
|
||||
|
||||
def settings_menu(self):
|
||||
@@ -16,7 +16,7 @@ def settings_menu(self):
|
||||
cls_stay(self, f"[设置菜单] "
|
||||
f"{Fore.LIGHTCYAN_EX}自动保存: "
|
||||
f"{({True: f'{Fore.GREEN}开', False: f'{Fore.RED}关'}[self.settings.auto_save])}")
|
||||
print_menu({
|
||||
r = input_menu({
|
||||
"0": "返回上级菜单",
|
||||
"1": "歌曲保存路径",
|
||||
"2": "清空输出文件夹内的内容",
|
||||
@@ -24,7 +24,6 @@ def settings_menu(self):
|
||||
"4": "部分动态效果",
|
||||
"s": "切换设置自动保存"
|
||||
})
|
||||
r = rinput("请选择:")
|
||||
if r == "0":
|
||||
return
|
||||
elif r == "1":
|
||||
@@ -32,7 +31,7 @@ def settings_menu(self):
|
||||
elif r == "2":
|
||||
__remove_output_files(self)
|
||||
elif r == "3":
|
||||
pass
|
||||
__set_lyric_format(self)
|
||||
elif r == "4":
|
||||
pass
|
||||
elif r == "s":
|
||||
@@ -44,8 +43,12 @@ def settings_menu(self):
|
||||
def __remove_output_files(self):
|
||||
while True:
|
||||
cls_stay(self, "[设置菜单 - 删除文件]")
|
||||
print("[0] 返回上级\n[1] 清除歌词文件\n[2] 清除歌曲文件\n[a] 清除所有文件")
|
||||
r = rinput("请选择:") # 选择清除的文件格式
|
||||
r = input_menu({
|
||||
"0": "返回上级",
|
||||
"1": "清除歌词文件",
|
||||
"2": "清除歌曲文件",
|
||||
"a": "清除所有文件",
|
||||
}) # 选择清除的文件格式
|
||||
if r == "0":
|
||||
return
|
||||
elif r == "1":
|
||||
@@ -84,7 +87,7 @@ def __remove_output_files(self):
|
||||
def __set_lyric_path(self):
|
||||
cls_stay(self, "[设置菜单 - 保存路径]")
|
||||
print("允许使用相对路径和绝对路径,默认为\"./out/\"\n请*不要*使用反斜杠来确保通用性\n"
|
||||
"当前值:%s\n请输入新的歌词保存路径:" % self.settings.lyric_path)
|
||||
"当前值:%s\n留空回车取消当前设置\n请输入新的歌词保存路径:" % self.settings.lyric_path)
|
||||
r = cinput()
|
||||
if not r:
|
||||
input("输入为空!\n按回车继续...")
|
||||
@@ -107,5 +110,31 @@ def __set_lyric_path(self):
|
||||
|
||||
|
||||
def __set_lyric_format(self):
|
||||
pass
|
||||
|
||||
while True:
|
||||
cls_stay(self, f"[设置菜单 - 文件名格式]\n{Fore.LIGHTCYAN_EX}当前格式: ", end="")
|
||||
if self.settings.lyric_format == "%(name)s":
|
||||
print(f"{Fore.GREEN}曲名", end="")
|
||||
else:
|
||||
print(Fore.GREEN + self.settings.lyric_format % {"name": "曲名", "artists": "歌手名"}, end="")
|
||||
print(".xxx")
|
||||
r = input_menu({
|
||||
"0": "返回上级",
|
||||
"1": "%(name)s - %(artists)s" % {"name": "曲名", "artists": "歌手名"},
|
||||
"2": "%(artists)s - %(name)s" % {"name": "曲名", "artists": "歌手名"},
|
||||
"3": "%(name)s" % {"name": "曲名", "artists": "歌手名"},
|
||||
})
|
||||
if r == "0":
|
||||
return
|
||||
elif r == "1":
|
||||
self.settings.lyric_format = "%(name)s - %(artists)s"
|
||||
break
|
||||
elif r == "2":
|
||||
self.settings.lyric_format = "%(artists)s - %(name)s"
|
||||
break
|
||||
elif r == "3":
|
||||
self.settings.lyric_format = "%(name)s"
|
||||
break
|
||||
else:
|
||||
input("输入无效!\n按回车继续...")
|
||||
input("修改成功! \n按回车返回...")
|
||||
return
|
||||
|
@@ -13,8 +13,8 @@ def clear():
|
||||
os.system("clear")
|
||||
|
||||
|
||||
def cls_stay(self, custom=""):
|
||||
def cls_stay(self, custom="", *args, **kwargs):
|
||||
"""保留版本号清除屏幕"""
|
||||
clear()
|
||||
print(f"{Fore.YELLOW}[{Fore.GREEN}NeteaseMusicLyricDownloader{Fore.YELLOW}] {Fore.LIGHTBLACK_EX}{self.version}")
|
||||
print(Fore.LIGHTMAGENTA_EX+custom)
|
||||
print(Fore.LIGHTMAGENTA_EX+custom, *args, **kwargs)
|
||||
|
@@ -90,7 +90,8 @@ def load_and_decrypt_from_ncm(file_path, target_dir, out_format) -> dict | str:
|
||||
|
||||
# media data
|
||||
if meta_length:
|
||||
output_path = os.path.join(target_dir, regular_filename(out_format % {"name": meta_data["musicName"], "artists": "".join(
|
||||
output_path = os.path.join(target_dir, regular_filename(out_format % {"name": meta_data["musicName"],
|
||||
"artists": "".join(
|
||||
[x[0]+"," for x in meta_data["artist"]]
|
||||
)[:-1]} + "." + meta_data["format"]))
|
||||
else:
|
||||
|
@@ -1,7 +1,9 @@
|
||||
"""该程序的自述信息,调用即输出"""
|
||||
from modules.utils.clear_screen import clear
|
||||
"""有关打印的函数"""
|
||||
from colorama import Fore
|
||||
|
||||
from modules.utils.clear_screen import clear
|
||||
from modules.utils.inputs import rinput
|
||||
|
||||
|
||||
def print_info(self):
|
||||
"""调用即输出,无返回值"""
|
||||
@@ -25,6 +27,17 @@ def print_info(self):
|
||||
|
||||
|
||||
def print_menu(menu: dict):
|
||||
"""传入一个字典, 格式为 {"需要输入的字符": "功能描述", ...}"""
|
||||
"""传入一个字典, 格式为 {"需要输入的字符": "功能描述", ...}
|
||||
将会按照以下格式打印:
|
||||
[字符1] 功能描述1
|
||||
[字符2] 功能描述2
|
||||
..."""
|
||||
for k, v in menu.items():
|
||||
print(f"{Fore.LIGHTBLUE_EX}[{k}] {Fore.LIGHTWHITE_EX}{v}")
|
||||
print(f"{Fore.LIGHTBLUE_EX}[{k}] {Fore.RESET}{v}")
|
||||
|
||||
|
||||
def input_menu(menu: dict):
|
||||
"""传入一个字典, 格式为 {"需要输入的字符": "功能描述", ...}
|
||||
在 print_menu 末尾添加'请选择: '字样并要求输入, 使用rinput获取输入"""
|
||||
print_menu(menu)
|
||||
return rinput("请选择: ")
|
||||
|
Reference in New Issue
Block a user