Change file structure

This commit is contained in:
1826013250 2023-04-04 19:58:02 +08:00
parent dcd275e3b1
commit 71e967808b
14 changed files with 432 additions and 413 deletions

22
main.py
View File

@ -4,14 +4,14 @@
# author: David-123 # author: David-123
from modules.inputs import rinput from modules.utils.inputs import rinput
from modules.information import print_info from modules.utils.information import print_info
from modules.multi_download import mdl from modules.functions.multi_download import mdl
from modules.one_download import download_one_lyric from modules.functions.one_download import download_one_lyric
from modules.settings import settings_menu from modules.submenus.settings import settings_menu
from modules.save_load_settings import load_settings from modules.functions.save_load_settings import load_settings
from modules.clear_screen import clear from modules.utils.clear_screen import clear
from modules.load_file_song import get_lyric_from_folder from modules.functions.load_file_song import get_lyric_from_folder
class MainProcess(object): class MainProcess(object):
@ -30,11 +30,11 @@ class MainProcess(object):
r = rinput("请选择:") r = rinput("请选择:")
if r == "1": if r == "1":
download_one_lyric(self.settings.lyric_path) download_one_lyric(self)
elif r == "2": elif r == "2":
mdl(self.settings.lyric_path) mdl(self)
elif r == "3": elif r == "3":
get_lyric_from_folder(self.settings.lyric_path) get_lyric_from_folder(self)
elif r == "0": elif r == "0":
exit(0) exit(0)
elif r == "i": elif r == "i":

View File

View File

@ -11,9 +11,9 @@ from Cryptodome.Cipher import AES
from mutagen import File, flac from mutagen import File, flac
from mutagen.id3 import ID3, TPE1, APIC, COMM, TIT2, TALB from mutagen.id3 import ID3, TPE1, APIC, COMM, TIT2, TALB
from modules.clear_screen import clear from modules.utils.clear_screen import clear
from modules.get_song import get_song_lyric from modules.functions.get_song import get_song_lyric
from modules.inputs import cinput, rinput from modules.utils.inputs import cinput, rinput
def load_information_from_song(path): def load_information_from_song(path):
@ -164,9 +164,13 @@ def process_work(path, filename, target, q_err: Queue, q_info: Queue):
q_info.put(result) q_info.put(result)
def get_lyric_from_folder(lyric_path: str): def get_lyric_from_folder(self):
global ncm_files_num
clear() clear()
path = cinput("请输入歌曲的保存文件夹(绝对路径):") path = cinput(
f"[NeteaseMusicLyricDownloader] {self.version}\n"
"[自动获取]\n"
"请输入歌曲的保存文件夹(绝对路径):")
if not os.path.exists(path): if not os.path.exists(path):
input("路径不存在.\n按回车返回...") input("路径不存在.\n按回车返回...")
return return
@ -208,7 +212,7 @@ def get_lyric_from_folder(lyric_path: str):
target_path = path target_path = path
break break
elif select == '2': elif select == '2':
target_path = lyric_path target_path = self.settings.lyric_path
break break
elif select == '3': elif select == '3':
target_path = input("请输入: ").strip() target_path = input("请输入: ").strip()
@ -261,7 +265,11 @@ def get_lyric_from_folder(lyric_path: str):
print(i) print(i)
# 汇报索引结果 # 汇报索引结果
print(f"\n索引完毕!共找到{fails + len(musics) + len(ncm_files)}个目标文件\n{len(musics)}个文件已载入\n{fails}个文件失败") ncm_files_num = 0
if ncm_files:
if target_path == "NOT_DECRYPT":
ncm_files_num = len(ncm_files)
print(f"\n索引完毕!共找到{fails + len(musics) + ncm_files_num}个目标文件\n{len(musics)}个文件已载入\n{fails}个文件失败")
if ncm_files: if ncm_files:
if target_path == "NOT_DECRYPT": if target_path == "NOT_DECRYPT":
print(f"{len(ncm_files)}个文件放弃加载") print(f"{len(ncm_files)}个文件放弃加载")

View File

@ -1,16 +1,18 @@
import re import re
from modules.clear_screen import clear from modules.utils.clear_screen import clear
from modules.inputs import rinput from modules.utils.inputs import rinput
from modules.get_song import get_song_lyric from modules.functions.get_song import get_song_lyric
def mdl(path: str): def mdl(self):
"""多个歌词文件的下载 """多个歌词文件的下载
``path: str`` 传入歌词文件保存的路径""" ``path: str`` 传入歌词文件保存的路径"""
clear() clear()
ids = [] ids = []
print("输入歌曲id,用回车分开,输入s停止") print(f"[NeteaseMusicLyricDownloader] {self.version}\n"
"[手动-多个下载]\n"
"输入歌曲id,用回车分开,输入s停止")
while True: while True:
r = rinput() r = rinput()
if r == 's': if r == 's':
@ -30,7 +32,7 @@ def mdl(path: str):
clear() clear()
for i in range(0, len(ids)): for i in range(0, len(ids)):
print("进度: %d/%d" % (i+1, len(ids))) print("进度: %d/%d" % (i+1, len(ids)))
r = get_song_lyric(ids[i], path) r = get_song_lyric(ids[i], self.settings.lyric_path)
if r == "dl_err_connection": if r == "dl_err_connection":
input("下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键继续任务(该任务会被跳过)...") input("下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键继续任务(该任务会被跳过)...")
input("按回车键返回...") input("按回车键返回...")

View File

@ -1,15 +1,18 @@
import re import re
from modules.inputs import rinput from modules.utils.inputs import rinput
from modules.get_song import get_song_lyric from modules.functions.get_song import get_song_lyric
from modules.clear_screen import clear from modules.utils.clear_screen import clear
def download_one_lyric(path: str): def download_one_lyric(self):
"""单次下载歌词 """单次下载歌词
``path: str`` 存储歌词的路径""" ``path: str`` 存储歌词的路径"""
clear() clear()
song_id = rinput("请输入歌曲id:") song_id = rinput(
f"[NeteaseMusicLyricDownloader] {self.version}\n"
"[手动-单个下载]\n"
"请输入歌曲id:")
try: try:
int(song_id) int(song_id)
except ValueError: except ValueError:
@ -20,6 +23,6 @@ def download_one_lyric(path: str):
input("不合法的形式.\n按回车键返回...") input("不合法的形式.\n按回车键返回...")
return return
if get_song_lyric(song_id, path) == "dl_err_connection": if get_song_lyric(song_id, self.settings.lyric_path) == "dl_err_connection":
input("下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键返回...") input("下载发生错误!可能是连接被拒绝!请检查网络后再试\n按回车键返回...")
input("按回车键返回...") input("按回车键返回...")

View File

View File

@ -1,9 +1,9 @@
"""集合设置参数""" """集合设置参数"""
import os import os
from modules.clear_screen import clear from modules.utils.clear_screen import clear
from modules.inputs import rinput, cinput from modules.utils.inputs import rinput, cinput
from modules.save_load_settings import save_settings from modules.functions.save_load_settings import save_settings
def settings_menu(self): def settings_menu(self):
@ -36,7 +36,7 @@ def __remove_output_files(self):
clear() clear()
print(f"[NeteaseMusicLyricDownloader] {self.version}\n" print(f"[NeteaseMusicLyricDownloader] {self.version}\n"
"[设置菜单 - 删除文件]\n" "[设置菜单 - 删除文件]\n"
"[0] 返回上级\n[1] 清除歌词文件\n[2] 清除歌曲文件") "[0] 返回上级\n[1] 清除歌词文件\n[2] 清除歌曲文件\n[a] 清除所有文件")
r = rinput("请选择:") # 选择清除的文件格式 r = rinput("请选择:") # 选择清除的文件格式
if r == "0": if r == "0":
return return
@ -46,14 +46,20 @@ def __remove_output_files(self):
elif r == "2": elif r == "2":
dellist = [".mp3", ".flac"] dellist = [".mp3", ".flac"]
break break
elif r == "a":
dellist = ["ALL"]
break
else: else:
input("输入无效!\n按回车键继续...") input("输入无效!\n按回车键继续...")
files = [] files = []
for i in os.listdir(self.settings.lyric_path): # 列出所有文件 for i in os.listdir(self.settings.lyric_path): # 列出所有文件
if os.path.splitext(i)[-1] in dellist: # 匹配文件 if dellist[0] == "ALL":
files = os.listdir(self.settings.lyric_path)
break
elif os.path.splitext(i)[-1] in dellist: # 匹配文件
files.append(i) # 将匹配到的文件加入到列表, 等待删除 files.append(i) # 将匹配到的文件加入到列表, 等待删除
if len(files) != 0: if len(files) != 0:
if len(files) > 50: if len(files) > 30:
special_text = "\033[F" special_text = "\033[F"
else: else:
special_text = "\n" special_text = "\n"

View File

View File

@ -1,5 +1,5 @@
"""该程序的自述信息,调用即输出""" """该程序的自述信息,调用即输出"""
from modules.clear_screen import clear from modules.utils.clear_screen import clear
def print_info(self): def print_info(self):