From cda7a378f233fe7da12c1c6dcd1e9d56e0f176ec Mon Sep 17 00:00:00 2001 From: NingmengLemon <1435439745@qq.com> Date: Sat, 21 May 2022 21:55:01 +0800 Subject: [PATCH] v.2.1.1 --- CMLD.py | 76 ++++++++++++++++++++++++++++++++++++++-------- DevelopmentLog.txt | 67 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 DevelopmentLog.txt diff --git a/CMLD.py b/CMLD.py index 087c1ed..cc195ee 100644 --- a/CMLD.py +++ b/CMLD.py @@ -12,7 +12,7 @@ from tkinter import filedialog from functools import wraps -version = '2.1.0' +version = '2.1.1' encoding = 'utf-8' root_window = tk.Tk() @@ -77,6 +77,8 @@ def get_album(aid): def search_music(*kws,limit=10,offset=0): url = 'https://music.163.com/api/search/get/?s={}&limit={}&type=1&offset={}'.format('+'.join([requester.parse.quote(kw) for kw in kws]),limit,offset) data = json.loads(requester.get_content_str(url)) + if 'result' not in data: + return [] if 'songs' in data['result']: res = [{ 'mid':i['id'],'title':i['name'], @@ -163,7 +165,7 @@ def fuzzy_match(string, collection, accessor=lambda x: x, sort_results=True): else: return (z[-1] for z in sorted(suggestions, key=lambda x: x[:2])) -def walk_topfolder(path): +def walk_topfolder(path): #返回的数据结构与os.walk保持一致 dirs = os.listdir(path) files = [] folders = [] @@ -183,7 +185,8 @@ def main(): choice = input('\nChoose one option to start.'\ '\n (1)Download lyrics via music id.'\ '\n (2)Parse album via album id and download lyrics of each music.'\ - '\n (3)Scan local folder and download lyrics of each music file according to their filename.'\ + '\n (3)Scan local folder and download lyrics of each music file according to their filenames.'\ + '\n (4)Choose some files manually and download lyrics for them according to thier filenames.'\ '\nChoice:').strip() if choice == '1': source = input('Music ID or Url:').strip() @@ -197,16 +200,18 @@ def main(): music_id = None if music_id: lrc_orig,lrc_trans = get_lyrics(music_id) - if lrc_orig and lrc_trans: - trans = input('Original version (0) or Translated version (1):').strip() - if trans == '1': - download_lyrics(music_id,desktop,trans=True,lrcs=(lrc_orig,lrc_trans)) + topath = filedialog.askdirectory(title='Choose Output Path') + if topath: + if lrc_orig and lrc_trans: + trans = input('Original version (0) or Translated version (1):').strip() + if trans == '1': + download_lyrics(music_id,topath,trans=True,lrcs=(lrc_orig,lrc_trans)) + else: + download_lyrics(music_id,topath,trans=False,lrcs=(lrc_orig,lrc_trans)) + elif lrc_orig and not lrc_trans: + download_lyrics(music_id,topath,trans=False,lrcs=(lrc_orig,lrc_trans)) else: - download_lyrics(music_id,desktop,trans=False,lrcs=(lrc_orig,lrc_trans)) - elif lrc_orig and not lrc_trans: - download_lyrics(music_id,desktop,trans=False,lrcs=(lrc_orig,lrc_trans)) - else: - print('No lyrics to download.') + print('No lyrics to download.') else: print('No music id to extract.') elif choice == '2': @@ -246,7 +251,7 @@ def main(): trans = True else: trans = False - toponly = input('Top folder only (0) or All file tree (1)').strip() + toponly = input('Top folder only (0) or All file tree (1):').strip() if toponly == '1': toponly = False else: @@ -286,6 +291,51 @@ def main(): continue else: print('No path to scan file.') + elif choice.lower() == '4': + match_mode = input('Fuzzy match (0) or Complete match (1):').strip() #匹配模式 + if match_mode == '1': + fuzzy = False + else: + fuzzy = True + trans = input('Original version (0) or Translated version (1):').strip() #是否翻译 + if trans == '1': + trans = True + else: + trans = False + targets = filedialog.askopenfilenames(title='Choose some files to match.') # + if targets: + loop_counter = 0 + for fullpath in targets: + loop_counter += 1 + root,file = os.path.split(fullpath) + base,extension = os.path.splitext(file) + if extension.lower() in ['.m4a','.mp3','.flac','.aac','.ape','.wma']: + title,artists = parse_filename(base) + data = search_music(title,*artists) + if not data: + print('File "{}" has no match result.'.format(file)) + continue + if fuzzy: + titles_to_match = [i['title'] for i in data] + match_res = fuzzy_match(title,titles_to_match) + try: + matched_obj = data[titles_to_match.index(next(match_res))] + print('File "{}" matched music "{}"(id{}).'.format(file,matched_obj['title'],matched_obj['mid'])) + download_lyrics(matched_obj['mid'],root,trans=trans,info=matched_obj) #因为键的命名方法一致, 所以可以直接传入 + except StopIteration: + print('File "{}" has no match result.'.format(file)) + else: + for obj in data: + if obj['title'] == title and sum([(i in obj['artists']) for i in artists]) == len(artists): + print('File "{}" matched music "{}"(id{}).'.format(file,obj['title'],obj['mid'])) + download_lyrics(matched_obj['mid'],root,trans=trans,info=obj) + break + else: + print('File "{}" has no match result.'.format(file)) + else: + continue + else: + print('No file to match..') elif choice.lower() == 'cls': os.system('cls') elif choice.lower() == 'config': diff --git a/DevelopmentLog.txt b/DevelopmentLog.txt new file mode 100644 index 0000000..67f3df8 --- /dev/null +++ b/DevelopmentLog.txt @@ -0,0 +1,67 @@ +v.1.0.0.20201205_alpha + 测试运行成功 +v.1.0.0.20201206_beta + 修复Bug + 添加帮助 +v.1.1.0.20201212_beta + 添加第三方api + 添加设置窗口 + 调整程序结构 + 整合函数 + 修复Bug +v.1.1.1.20201213_beta + 修复Bug +v.1.1.2.20201216_beta + 修复Bug +v.1.2.0.20201220_alpha + 修复Bug + 添加一言api + 添加搜索窗口 + 调整程序结构 +v.1.2.1.20201220_alpha + 修复Bug + 为Entry绑定Enter键 +v.1.2.2.20201226_beta + 修复Bug + 完善搜索窗口 + 增强错误处理 + 为一言标签绑定鼠标键 +v.1.2.3.20201230_alpha + 修复Bug + 调整程序结构 +v.1.3.0.20210101_beta + 修复Bug + 添加专辑解析 + 完善设置模块 +v.1.3.1.20210102_beta + 修复Bug + 继续完善设置模块 +v.1.4.0.20210103_beta + 更换api + 新增歌词翻译获取 + 继续完善设置模块 +v.1.4.1.20210103_beta + 改进批处理功能 +v.1.4.2.20210109_beta + 修复Bug +v.1.4.3.20210110_beta + 修复Bug + 新增音频下载功能 +v.2.0.0.20210727 + 现有api已不可用 + 削减功能,仅保留基础模块 + 删除GUI + 重构程序 +v.2.0.0.20210729 + 修复Bug + 现在输出目录变成桌面了 +v.2.0.1.20210823 + 修复了获取文件名的功能 +v.2.1.0.20220123 + 项目重构 + 现在能根据MusicID下载歌词 + 现在能根据AlbumID解析专辑 + 现在能扫描文件夹并匹配合适的歌词,并分为模糊匹配和完全匹配 +v.2.1.1.20220521 + 现在能手动指定文件进行匹配了 + 修复Bug \ No newline at end of file