From 18de4e1cea84de24c82813bbcea0149f5c6aff75 Mon Sep 17 00:00:00 2001 From: 1826013250 <1826013250@qq.com> Date: Mon, 17 Apr 2023 02:41:06 +0800 Subject: [PATCH] Temp Upload --- modules/functions/get_song.py | 3 +++ modules/functions/load_file_song.py | 2 ++ modules/utils/bar.py | 33 +++++++++++++++++++++++++++++ modules/utils/length.py | 7 ++++++ 4 files changed, 45 insertions(+) create mode 100644 modules/utils/bar.py create mode 100644 modules/utils/length.py diff --git a/modules/functions/get_song.py b/modules/functions/get_song.py index 82c039c..b031b44 100644 --- a/modules/functions/get_song.py +++ b/modules/functions/get_song.py @@ -78,6 +78,9 @@ def get_song_lyric(id: str | int | dict, path: str, allinfo: bool = False): artists = artists[:-1] name = sinfo["name"] + if not name: + print("歌曲错误!这是网易云的问题,请不要找作者") + return "song_err" replaces = { # 处理非法字符所用的替换字典(根据网易云下载的文件分析得到) "|": "|", ":": ":", diff --git a/modules/functions/load_file_song.py b/modules/functions/load_file_song.py index d860f52..dda7f6d 100644 --- a/modules/functions/load_file_song.py +++ b/modules/functions/load_file_song.py @@ -250,7 +250,9 @@ def get_lyric_from_folder(self): q_err, q_info)).start() allocated += 1 + current_process += 1 bar.suffix = f"已分配: {ncm_files[allocated-1]}" + print(len(bar.fill)) bar.update() while True: # 错误队列检测 try: diff --git a/modules/utils/bar.py b/modules/utils/bar.py new file mode 100644 index 0000000..ca3f5bb --- /dev/null +++ b/modules/utils/bar.py @@ -0,0 +1,33 @@ +"""一些有关调整进度条的设置""" +from os import get_terminal_size + +from progress.bar import Bar + + +def suit_length(bar: Bar, original: Bar): + """尽量调整进度条大小去匹配终端宽度""" + length = get_terminal_size().columns + original_length = original.width + len((original.message + + original.bar_suffix + + original.bar_prefix + + original.suffix) % bar) + if length >= original_length: + return + if length < len(str(bar.max) + "/" + str(bar.index)): + bar.bar_suffix = bar.suffix = bar.bar_prefix = "" + bar.width = 0 + bar.suffix = Bar.suffix + elif length >= original_length - bar.width: + bar.width = length - len((bar.message + bar.bar_suffix + bar.bar_prefix + bar.suffix) % bar) + elif length >= original_length - (bar.width + len(bar.suffix % bar)) and "(index)" in bar.message: + bar.suffix = "" + bar.width = length - len((bar.message + bar.bar_suffix + bar.bar_prefix + bar.suffix) % bar) + elif length >= original_length - (bar.width + len(bar.message % bar)) and "(index)" in bar.suffix: + bar.message = "" + bar.width = length - len((bar.message + bar.bar_suffix + bar.bar_prefix + bar.suffix) % bar) + elif length >= original_length - (bar.width + len((bar.message + bar.suffix) % bar)) + Bar.suffix % bar: + bar.message = "" + bar.suffix = Bar.suffix + bar.width = length - len((bar.message + bar.bar_suffix + bar.bar_prefix + bar.suffix) % bar) + bar.update() + return diff --git a/modules/utils/length.py b/modules/utils/length.py new file mode 100644 index 0000000..5297e89 --- /dev/null +++ b/modules/utils/length.py @@ -0,0 +1,7 @@ +"""一些有关计算长度的工具""" + + +def len_abs(content): + """针对中文:将一个汉字识别为2个长度,而不是1个""" + + return len(content) + (len(content.encode("utf-8")) - len(content)) // 2