Fix Filename mistake

This commit is contained in:
1826013250 2023-06-22 02:14:17 +08:00
parent 3003b3bb3b
commit feb68498dc
2 changed files with 24 additions and 16 deletions

View File

@ -6,6 +6,7 @@ from time import sleep
from colorama import Fore, Style from colorama import Fore, Style
from modules.utils.bar import CompactBar, bprint from modules.utils.bar import CompactBar, bprint
from modules.utils.dump import regular_filename
def wait_retry(kind, identify, bar=None): 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: if not name:
bprint(Fore.RED + "歌曲错误!这是网易云的问题,请不要找作者", bar) bprint(Fore.RED + "歌曲错误!这是网易云的问题,请不要找作者", bar)
return "song_err" return "song_err"
replaces = { # 处理非法字符所用的替换字典(根据网易云下载的文件分析得到)
"|": "", name = regular_filename(name)
":": "", artists = regular_filename(artists)
"<": "",
">": "",
"?": "",
"/": "",
"\\": "",
"*": "",
'"': ""
}
for k, v in replaces.items():
name = name.replace(k, v)
artists = artists.replace(k, v)
bprint(Fore.YELLOW + "\t-> 歌曲:" + Style.RESET_ALL + f"{name} - {artists}", bar) bprint(Fore.YELLOW + "\t-> 歌曲:" + Style.RESET_ALL + f"{name} - {artists}", bar)
filename = f"{name} - {artists}.lrc" filename = f"{name} - {artists}.lrc"

View File

@ -10,6 +10,24 @@ from Cryptodome.Util.strxor import strxor as xor
from mutagen import mp3, flac, id3 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 def load_and_decrypt_from_ncm(file_path, target_dir, out_format) -> dict | str: # author: Nzix Repo: nondanee
core_key = binascii.a2b_hex('687A4852416D736F356B496E62617857') 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 # media data
if meta_length: 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"]] [x[0]+"," for x in meta_data["artist"]]
)[:-1]} + "." + meta_data["format"]) )[:-1]} + "." + meta_data["format"]))
else: else:
output_path = os.path.join(target_dir, "Unnamed." + meta_data["format"]) output_path = os.path.join(target_dir, "Unnamed." + meta_data["format"])