This commit is contained in:
quackerd 2023-10-28 02:13:36 +08:00
parent 26aceb66a1
commit d258b93347
2 changed files with 15 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -24,6 +24,15 @@ ARTIST_MATCH_SCORE = 10
ALBUM_MATCH_SCORE = 100
TITLE_MATCH_SCORE = 1000
escape_list : list[tuple[str, str]] = [
("%..%" , ":")
]
def escape_str(input : str) -> str:
for tup in escape_list:
input = input.replace(tup[0], tup[1])
return input
# to get a > 0 score, each field either must match or the cover tuple is wildcare (None)
def calc_cover_score(artist: list[str], album: list[str], title: list[str], tup : tuple) -> int:
score = 0
@ -74,15 +83,15 @@ def plus_str_to_list(s : str) -> list[str]:
ret.append(sss)
return ret
def parse_triple(f: str) -> tuple[list[str], list[str], list[str]]:
def parse_triple(f: str, escape : bool = True) -> tuple[list[str], list[str], list[str]]:
triple = os.path.splitext(os.path.basename(f))[0].split("_")
album = ""
title = ""
artist = plus_str_to_list(triple[0])
artist = plus_str_to_list(escape_str(triple[0]) if escape else triple[0])
if len(triple) >= 2:
album = plus_str_to_list(triple[1])
album = plus_str_to_list(escape_str(triple[1]) if escape else triple[1])
if len(triple) >= 3:
title = plus_str_to_list(triple[2])
title = plus_str_to_list(escape_str(triple[2]) if escape else triple[2])
return (artist, album, title)
@ -131,6 +140,7 @@ def process_file(f: str, odir: str):
total_proc += 1
artist, album, title = parse_triple(f)
fartist, falbum, _ = parse_triple(f, escape=False)
if len(title) == 0:
raise Exception("No title")
@ -157,7 +167,7 @@ def process_file(f: str, odir: str):
print(" Cover: <Exists>")
total_cover_exists += 1
target_dir = os.path.join(odir, "+".join(artist), "+".join(album))
target_dir = os.path.join(odir, "+".join(fartist), "+".join(falbum))
os.makedirs(target_dir, exist_ok = True)
target_f = os.path.join(target_dir, os.path.basename(f))