unstable
This commit is contained in:
parent
3ef2f54515
commit
08098695cc
41
musick.py
41
musick.py
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import mutagen
|
||||||
from mutagen.easyid3 import EasyID3
|
from mutagen.easyid3 import EasyID3
|
||||||
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB
|
from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB
|
||||||
import getopt
|
import getopt
|
||||||
@ -107,7 +108,6 @@ def usage():
|
|||||||
-o output : output directory\n\
|
-o output : output directory\n\
|
||||||
-c cover : cover arts page\n")
|
-c cover : cover arts page\n")
|
||||||
|
|
||||||
|
|
||||||
no_match = []
|
no_match = []
|
||||||
|
|
||||||
def process_file(f: str, odir: str):
|
def process_file(f: str, odir: str):
|
||||||
@ -136,7 +136,7 @@ def process_file(f: str, odir: str):
|
|||||||
if title == "":
|
if title == "":
|
||||||
raise Exception("No 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)
|
target_dir = os.path.join(odir, artist, album)
|
||||||
os.makedirs(target_dir, exist_ok = True)
|
os.makedirs(target_dir, exist_ok = True)
|
||||||
@ -146,32 +146,25 @@ def process_file(f: str, odir: str):
|
|||||||
shutil.copyfile(f, target_f)
|
shutil.copyfile(f, target_f)
|
||||||
except shutil.SameFileError:
|
except shutil.SameFileError:
|
||||||
pass
|
pass
|
||||||
print(" Copied file to - " + target_f)
|
print(" Copied file to: " + target_f)
|
||||||
|
|
||||||
cover_idx = find_best_cover(artist, album, title)
|
cover_idx = find_best_cover(artist, album, title)
|
||||||
|
|
||||||
# write id3 tags of the target file
|
audio = mutagen.File(f)
|
||||||
id3 = ID3(target_f)
|
print(f" File info: {audio.info.pprint()}")
|
||||||
# write title
|
audio["title"] = title
|
||||||
id3.delall("TIT2")
|
audio["artist"] = artist
|
||||||
id3.add(TIT2(text = title))
|
audio["album"] = album
|
||||||
# write album
|
audio.save()
|
||||||
id3.delall("TALB")
|
|
||||||
id3.add(TALB(text = album))
|
|
||||||
# write artist
|
|
||||||
id3.delall("TPE1")
|
|
||||||
id3.add(TPE1(text = artist))
|
|
||||||
|
|
||||||
if cover_idx >= 0:
|
# if cover_idx >= 0:
|
||||||
# install cover
|
# # install cover
|
||||||
id3.delall("APIC")
|
# id3.delall("APIC")
|
||||||
id3.add(APIC(3, "image/jpeg", 3, "Front cover", cover_arts[cover_idx][3]))
|
# id3.add(APIC(3, "image/jpeg", 3, "front cover", cover_arts[cover_idx][3]))
|
||||||
total_cover += 1
|
# total_cover += 1
|
||||||
print(" Written cover art - " + cover_arts[cover_idx][4])
|
# print(f" Written metadata for {f} with cover art - " + cover_arts[cover_idx][4])
|
||||||
else:
|
# else:
|
||||||
no_match.append(target_f)
|
# no_match.append(target_f)
|
||||||
|
|
||||||
id3.save(v2_version=3)
|
|
||||||
|
|
||||||
total_succ += 1
|
total_succ += 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user