stable
This commit is contained in:
parent
fdeb1c4289
commit
696011bcbd
BIN
arts/_大空魔術 ~ Magical Astronomy_.jpg
Normal file
BIN
arts/_大空魔術 ~ Magical Astronomy_.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 423 KiB |
52
mobject.py
52
mobject.py
@ -42,50 +42,60 @@ class MObject:
|
||||
class MMP3Object(MObject):
|
||||
_id3 : ID3
|
||||
def __init__(self, file : bytes):
|
||||
super().__init__(self, file)
|
||||
super().__init__(file)
|
||||
|
||||
self._id3 = ID3()
|
||||
self._id3.load(self._file_io, translate = True)
|
||||
return
|
||||
|
||||
def get_title(self) -> str:
|
||||
return self._id3.get("TIT2", default = TIT2(text = None)).text
|
||||
return self._id3.get("TIT2", default = TIT2(text = ""))
|
||||
|
||||
def set_title(self, val : str) -> None:
|
||||
self._id3.delall("TIT2")
|
||||
self._id3.add(TIT2(text = val))
|
||||
self._id3.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._id3.save(self._file_io)
|
||||
|
||||
def get_album(self) -> str:
|
||||
return self._id3.get("TALB", default = TALB(text = None)).text
|
||||
return self._id3.get("TALB", default = TALB(text = ""))
|
||||
|
||||
def set_album(self, val : str) -> None:
|
||||
self._id3.delall("TALB")
|
||||
self._id3.add(TALB(text = val))
|
||||
self._id3.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._id3.save(self._file_io)
|
||||
|
||||
def get_artist(self) -> str:
|
||||
return self._id3.get("TPE1", default = TPE1(text = None)).text
|
||||
return self._id3.get("TPE1", default = TPE1(text = ""))
|
||||
|
||||
def set_artist(self, val : str):
|
||||
self._id3.delall("TPE1")
|
||||
self._id3.add(TPE1(text = val))
|
||||
self._id3.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._id3.save(self._file_io)
|
||||
|
||||
def get_cover(self) -> bytes:
|
||||
cover = self._id3.get("APIC", default=APIC(encoding = Encoding.UTF8, mime = "image/jpeg", type=PictureType.COVER_FRONT, desc=u"Cover", data = None))
|
||||
return cover.data
|
||||
cover = self._id3.getall("APIC")
|
||||
if (cover == None or len(cover) == 0):
|
||||
return None
|
||||
return cover[0].data
|
||||
|
||||
def set_cover(self, val : bytes, png : bool = False) -> None:
|
||||
self._id3.delall("APIC")
|
||||
self._id3.add(APIC(encoding = Encoding.UTF8, mime = "image/png" if png else "image/jpeg", type=PictureType.COVER_FRONT, desc=u"Cover", data = val))
|
||||
self._id3.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._id3.save(self._file_io)
|
||||
|
||||
|
||||
class MFLACObject(MObject):
|
||||
_flac : FLAC
|
||||
def __init__(self, file : bytes):
|
||||
super().__init__(self, file)
|
||||
super().__init__(file)
|
||||
|
||||
self._flac = FLAC(self._file_io)
|
||||
return
|
||||
@ -95,21 +105,27 @@ class MFLACObject(MObject):
|
||||
|
||||
def set_title(self, val : str) -> None:
|
||||
self._flac["TITLE"] = val
|
||||
self._flac.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._flac.save(self._file_io)
|
||||
|
||||
def get_album(self) -> str:
|
||||
return self._flac.get("ALBUM", default = None)
|
||||
|
||||
def set_album(self, val : str) -> None:
|
||||
self._flac["ALBUM"] = val
|
||||
self._flac.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._flac.save(self._file_io)
|
||||
|
||||
def get_artist(self) -> str:
|
||||
return self._flac.get("ARTIST", default = None)
|
||||
|
||||
def set_artist(self, val : str):
|
||||
self._flac["ARTIST"] = val
|
||||
self._flac.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._flac.save(self._file_io)
|
||||
|
||||
def get_cover(self) -> bytes:
|
||||
pics = self._flac.pictures
|
||||
@ -126,15 +142,17 @@ class MFLACObject(MObject):
|
||||
pic.desc = "Cover"
|
||||
pic.data = val
|
||||
self._flac.add_picture(pic)
|
||||
self._flac.save()
|
||||
|
||||
self._file_io.seek(0)
|
||||
self._flac.save(self._file_io)
|
||||
|
||||
|
||||
def create_mobject(filepath : str) -> MObject:
|
||||
fp = Path(filepath)
|
||||
with open(fp, "rb") as f:
|
||||
buf = f.read()
|
||||
if (fp.suffix == "mp3"):
|
||||
if (fp.suffix == ".mp3"):
|
||||
return MMP3Object(buf)
|
||||
if (fp.suffix == "flac"):
|
||||
if (fp.suffix == ".flac"):
|
||||
return MFLACObject(buf)
|
||||
return None
|
29
musick.py
29
musick.py
@ -8,7 +8,10 @@ import mobject
|
||||
total_proc = 0
|
||||
total_succ = 0
|
||||
total_error = 0
|
||||
total_missing_cover = 0
|
||||
total_cover_exists = 0
|
||||
total_cover_written = 0
|
||||
cover_missing = []
|
||||
errors = []
|
||||
|
||||
input_dir = None
|
||||
output_dir = None
|
||||
@ -92,7 +95,7 @@ def load_cover_arts():
|
||||
f = os.path.join(cover_dir, f)
|
||||
print("Processing cover art - " + f)
|
||||
with open(f,'rb') as img:
|
||||
cover_arts.append((artist, album, title, img.read(), os.path.basename(f)))
|
||||
cover_arts.append((artist, album, title, img.read(), os.path.basename(f), f))
|
||||
print(" Loading cover art - " + f + " Artist: " + artist + " Album: " + album + " Title: " + title)
|
||||
except Exception as e:
|
||||
print(" Skipping due to Exception - " + str(e))
|
||||
@ -108,7 +111,8 @@ def usage():
|
||||
-c cover : cover arts page\n")
|
||||
|
||||
def process_file(f: str, odir: str):
|
||||
global total_missing_cover
|
||||
global total_cover_exists
|
||||
global total_cover_written
|
||||
global total_succ
|
||||
global total_error
|
||||
global total_proc
|
||||
@ -138,12 +142,14 @@ def process_file(f: str, odir: str):
|
||||
cover_idx = find_best_cover(artist, album, title)
|
||||
if (cover_idx >= 0):
|
||||
mobj.set_cover(cover_arts[cover_idx][3])
|
||||
print(" Cover: <None> -> <New>")
|
||||
print(f" Cover: \"{cover_arts[cover_idx][5]}\"")
|
||||
total_cover_written += 1
|
||||
else:
|
||||
total_missing_cover += 1
|
||||
print(" Cover: <None> -> <None>")
|
||||
print(" Cover: <Missing>")
|
||||
cover_missing.append(f)
|
||||
else:
|
||||
print(" Cover: <Exists>")
|
||||
total_cover_exists += 1
|
||||
|
||||
target_dir = os.path.join(odir, artist, album)
|
||||
os.makedirs(target_dir, exist_ok = True)
|
||||
@ -157,6 +163,7 @@ def process_file(f: str, odir: str):
|
||||
|
||||
except Exception as e:
|
||||
total_error += 1
|
||||
errors.append(f)
|
||||
print(" Skipping due to exception - %s" % str(e))
|
||||
|
||||
print("")
|
||||
@ -205,6 +212,14 @@ def main():
|
||||
load_cover_arts()
|
||||
process_directory(input_dir, output_dir)
|
||||
|
||||
print("\nSummary - Total Files: " + str(total_proc) + " Total Errors: " + str(total_error) + " Total Missing Covers: " + str(total_missing_cover))
|
||||
print("\nSummary - Files: " + str(total_proc) + ". Processed: " + str(total_succ) + ". Cover Exists: " + str(total_cover_exists) + ". Cover Written: " + str(total_cover_written))
|
||||
if (len(errors) > 0):
|
||||
print(f"Errors: {len(errors)}")
|
||||
for f in errors:
|
||||
print(f" {f}")
|
||||
if (len(cover_missing) > 0):
|
||||
print(f"Cover Missing: {len(cover_missing)}")
|
||||
for f in cover_missing:
|
||||
print(f" {f}")
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user