diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cbe31f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +out/ +settings.json +.idea/ +venv/ +venv_win/ +test/ diff --git a/modules/functions/load_file_song.py b/modules/functions/load_file_song.py index c8a10ce..d4604dc 100644 --- a/modules/functions/load_file_song.py +++ b/modules/functions/load_file_song.py @@ -5,6 +5,7 @@ import struct from base64 import b64decode from multiprocessing import Process, Queue from queue import Empty +from time import sleep from progress.bar import Bar from Cryptodome.Cipher import AES @@ -16,7 +17,7 @@ from modules.functions.get_song import get_song_lyric from modules.utils.inputs import cinput, rinput -def load_information_from_song(path): +def load_information_from_song(path) -> str | dict: """从音乐文件中的 Comment 字段获取 163 key 并解密返回歌曲信息""" file = File(path) # 使用 mutagen 获取歌曲信息 if os.path.splitext(path)[-1] == ".mp3": # 当文件为 mp3 时使用 ID3 格式读取 @@ -64,10 +65,12 @@ def load_information_from_song(path): return "decrypt_failed" -def load_and_decrypt_from_ncm(file_path, targetdir): # nondanee的源代码, 根据需求更改了某些东西 +def load_and_decrypt_from_ncm(file_path, target_dir) -> dict: # nondanee的源代码, 根据需求更改了某些东西 core_key = binascii.a2b_hex("687A4852416D736F356B496E62617857") meta_key = binascii.a2b_hex("2331346C6A6B5F215C5D2630553C2728") - unpad = lambda s: s[0:-(s[-1] if type(s[-1]) == int else ord(s[-1]))] + + def unpad(s): + return s[0:-(s[-1] if type(s[-1]) == int else ord(s[-1]))] f = open(file_path, 'rb') header = f.read(8) assert binascii.b2a_hex(header) == b'4354454e4644414d' @@ -84,7 +87,6 @@ def load_and_decrypt_from_ncm(file_path, targetdir): # nondanee的源代码, key_length = len(key_data) key_data = bytearray(key_data) key_box = bytearray(range(256)) - c = 0 last_byte = 0 key_offset = 0 for i in range(256): @@ -110,13 +112,13 @@ def load_and_decrypt_from_ncm(file_path, targetdir): # nondanee的源代码, meta_data = json.loads(meta_data) crc32 = f.read(4) crc32 = struct.unpack('检测队列->检测任务完成 的循环 - if current_process <= max_process and finished < total: # 分配进程 + sleep(0) + if current_process <= max_process and allocated < total: # 分配进程 Process(target=process_work, - args=(os.path.join(path, ncm_files[finished]), - ncm_files[finished], + args=(os.path.join(path, ncm_files[allocated]), + ncm_files[allocated], target_path, q_err, q_info)).start() - finished += 1 + allocated += 1 + bar.suffix = f"已分配: {ncm_files[allocated-1]}" + bar.update() while True: # 错误队列检测 try: errors.append(q_err.get_nowait()) @@ -253,6 +260,8 @@ def get_lyric_from_folder(self): musics.append({"id": r['musicId'], "name": r["musicName"], "artists": r["artist"]}) passed += 1 current_process -= 1 + bar.suffix = f"已完成: {r['musicName']} - "\ + f"{''.join([x + ', ' for x in [x[0] for x in r['artist']]])[:-2]}" bar.next() except Empty: break @@ -279,6 +288,7 @@ def get_lyric_from_folder(self): lyric_path = path break elif r == "2": + lyric_path = self.settings.lyric_path break else: try: