diff --git a/modules/functions/mainly/get_song.py b/modules/functions/mainly/get_song.py index 9b4d449..5412c86 100644 --- a/modules/functions/mainly/get_song.py +++ b/modules/functions/mainly/get_song.py @@ -6,6 +6,7 @@ from time import sleep from colorama import Fore, Style from modules.utils.bar import CompactBar, bprint +from modules.utils.dump import regular_filename def wait_retry(kind, identify, bar=None): @@ -90,20 +91,9 @@ def get_song_lyric(identify: str | int | dict, path: str, allinfo: bool = False, if not name: bprint(Fore.RED + "歌曲错误!这是网易云的问题,请不要找作者", bar) return "song_err" - replaces = { # 处理非法字符所用的替换字典(根据网易云下载的文件分析得到) - "|": "|", - ":": ":", - "<": "<", - ">": ">", - "?": "?", - "/": "/", - "\\": "\", - "*": "*", - '"': """ - } - for k, v in replaces.items(): - name = name.replace(k, v) - artists = artists.replace(k, v) + + name = regular_filename(name) + artists = regular_filename(artists) bprint(Fore.YELLOW + "\t-> 歌曲:" + Style.RESET_ALL + f"{name} - {artists}", bar) filename = f"{name} - {artists}.lrc" diff --git a/modules/utils/dump.py b/modules/utils/dump.py index 1662837..0662e32 100644 --- a/modules/utils/dump.py +++ b/modules/utils/dump.py @@ -10,6 +10,24 @@ from Cryptodome.Util.strxor import strxor as xor from mutagen import mp3, flac, id3 +def regular_filename(filename): + """处理替换非法字符""" + replaces = { # 处理非法字符所用的替换字典(根据网易云下载的文件分析得到) + "|": "|", + ":": ":", + "<": "<", + ">": ">", + "?": "?", + "/": "/", + "\\": "\", + "*": "*", + '"': """ + } + for k, v in replaces.items(): + filename = filename.replace(k, v) + return filename + + def load_and_decrypt_from_ncm(file_path, target_dir, out_format) -> dict | str: # author: Nzix Repo: nondanee core_key = binascii.a2b_hex('687A4852416D736F356B496E62617857') @@ -72,9 +90,9 @@ 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, 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"]) + )[:-1]} + "." + meta_data["format"])) else: output_path = os.path.join(target_dir, "Unnamed." + meta_data["format"])