Skip to content

Commit

Permalink
v.2.1.3-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NingmengLemon committed Jul 23, 2022
1 parent 731b127 commit c9b8879
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 60 deletions.
102 changes: 43 additions & 59 deletions CMLD.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import key163
from tinytag import TinyTag

version = '2.1.2-fix'
version = '2.1.3-fix'

encoding = 'utf-8'
root_window = tk.Tk()
Expand Down Expand Up @@ -136,17 +136,23 @@ def parse_filename(fn):
return title,artists

def get_fileinfo(file):
#tag
tags = parse_tag(file)
#163key
if tags['comment']:
if tags['comment'].startswith("163 key(Don't modify):"):
key = tags['comment'][22:]
key = key163.parse_163key(key)
return key['musicName'],[i[0] for i in key['artist']],key['musicId']
#common
if tags['title'] and tags['artist']:
return tags['title'],tags['artist'].split('/'),None
try:
#get tag
tags = parse_tag(file)
#163key
try:
if tags['comment']:
if tags['comment'].startswith("163 key(Don't modify):"):
key = tags['comment'][22:]
key = key163.parse_163key(key)
return key['musicName'],[i[0] for i in key['artist']],key['musicId']
except Exception as e:
print('Error Occurred while handling 163 key:',str(e))
#tag
if tags['title'] and tags['artist']:
return tags['title'],tags['artist'].split('/'),None
except Exception as e:
print('Error Occurred while handling music tag:',str(e))
#filename
t,a = parse_filename(os.path.splitext(os.path.split(file)[1])[0])
if t and a:
Expand Down Expand Up @@ -272,11 +278,6 @@ def main():
else:
print('No album id to extract.')
elif choice == '3':
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
Expand All @@ -299,39 +300,28 @@ def main():
title,artists,musicid = get_fileinfo(os.path.join(root,file))
if musicid:
print('File "{}" is music "{}"(id{})'.format(file,title,musicid))
download_lyrics(matched_obj['mid'],root,trans=trans)
download_lyrics(musicid,root,trans=trans)
else:
data = search_music(title,*artists)
if artists:
data = search_music(title,*artists)
else:
data = search_music(title)
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))
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:
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
Expand All @@ -350,27 +340,21 @@ def main():
print('File "{}" is music "{}"(id{})'.format(file,title,musicid))
download_lyrics(musicid,root,trans=trans)
else:
data = search_music(title,*artists)
if artists:
data = search_music(title,*artists)
else:
data = search_music(title)
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))
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:
continue
else:
Expand Down
6 changes: 5 additions & 1 deletion DevelopmentLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ v.2.1.1.20220521
v.2.1.2.20220608
现在能根据 Tag信息 及其中的 163 Key 进行匹配了
v.2.1.2-fix
修复在处理没有专辑的音乐时出错的Bug
修复在处理没有专辑的音乐时出错的Bug
v.2.1.3.20220709
移除完全匹配
v.2.1.3-fix
修复Bug

0 comments on commit c9b8879

Please sign in to comment.