This commit is contained in:
quackerd 2022-11-30 17:27:29 +01:00
parent 3ef2f54515
commit 08098695cc

View File

@ -1,4 +1,5 @@
import os
import mutagen
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB
import getopt
@ -107,7 +108,6 @@ def usage():
-o output : output directory\n\
-c cover : cover arts page\n")
no_match = []
def process_file(f: str, odir: str):
@ -136,7 +136,7 @@ def process_file(f: str, odir: str):
if title == "":
raise Exception("No title")
print(" Artist: " + artist + " Album: " + album + " Title: " + title)
print(" Identified artist: " + artist + " album: " + album + " title: " + title)
target_dir = os.path.join(odir, artist, album)
os.makedirs(target_dir, exist_ok = True)
@ -146,32 +146,25 @@ def process_file(f: str, odir: str):
shutil.copyfile(f, target_f)
except shutil.SameFileError:
pass
print(" Copied file to - " + target_f)
print(" Copied file to: " + target_f)
cover_idx = find_best_cover(artist, album, title)
# write id3 tags of the target file
id3 = ID3(target_f)
# write title
id3.delall("TIT2")
id3.add(TIT2(text = title))
# write album
id3.delall("TALB")
id3.add(TALB(text = album))
# write artist
id3.delall("TPE1")
id3.add(TPE1(text = artist))
if cover_idx >= 0:
# install cover
id3.delall("APIC")
id3.add(APIC(3, "image/jpeg", 3, "Front cover", cover_arts[cover_idx][3]))
total_cover += 1
print(" Written cover art - " + cover_arts[cover_idx][4])
else:
no_match.append(target_f)
audio = mutagen.File(f)
print(f" File info: {audio.info.pprint()}")
audio["title"] = title
audio["artist"] = artist
audio["album"] = album
audio.save()
id3.save(v2_version=3)
# if cover_idx >= 0:
# # install cover
# id3.delall("APIC")
# id3.add(APIC(3, "image/jpeg", 3, "front cover", cover_arts[cover_idx][3]))
# total_cover += 1
# print(f" Written metadata for {f} with cover art - " + cover_arts[cover_idx][4])
# else:
# no_match.append(target_f)
total_succ += 1