This commit is contained in:
Hellow 2023-01-12 19:55:24 +01:00
parent a00cbb0d0c
commit 25eea44d08
3 changed files with 10 additions and 10 deletions

View File

@ -51,7 +51,7 @@ song_input = Song(
length=666, length=666,
isrc="US-S1Z-99-00001", isrc="US-S1Z-99-00001",
tracksort=2, tracksort=2,
target=Target(file="test/Linkin Park/Hybrid Theory/out.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"), target=Target(file="song.mp3", path="~/Music"),
lyrics=[ lyrics=[
Lyrics(text="these are some depressive lyrics", language="en"), Lyrics(text="these are some depressive lyrics", language="en"),
Lyrics(text="test", language="en") Lyrics(text="test", language="en")
@ -101,6 +101,7 @@ for source in song.sources:
write_metadata(song) write_metadata(song)
exit() exit()
# getting song by album ref # getting song by album ref
div() div()
song_output_list = cache.pull_songs(album_ref=album_input.reference) song_output_list = cache.pull_songs(album_ref=album_input.reference)

View File

@ -1,4 +1,4 @@
import mutagen import mutagen
from mutagen.id3 import ID3, Frame from mutagen.id3 import ID3, Frame
from typing import List from typing import List
@ -21,14 +21,12 @@ class AudioMetadata:
if file_location is not None: if file_location is not None:
self.file_location = file_location self.file_location = file_location
def add_song_metadata(self, song: Song): def add_song_metadata(self, song: Song):
print("adding") print("adding")
for key, value in song.metadata: for key, value in song.metadata:
""" """
https://www.programcreek.com/python/example/84797/mutagen.id3.ID3 https://www.programcreek.com/python/example/84797/mutagen.id3.ID3
""" """
print(key, value)
self.frames.add(mutagen.id3.Frames[key](encoding=3, text=value)) self.frames.add(mutagen.id3.Frames[key](encoding=3, text=value))
def save(self, file_location: str = None): def save(self, file_location: str = None):
@ -43,18 +41,19 @@ class AudioMetadata:
# try loading the data from the given file. if it doesn't succeed the frame remains empty # try loading the data from the given file. if it doesn't succeed the frame remains empty
try: try:
self.frames.load(file_location, v2_version=4) self.frames.load(file_location, v2_version=4)
self._file_location = file_location
except mutagen.MutagenError: except mutagen.MutagenError:
logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"") logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"")
self._file_location = file_location
file_location = property(fget=lambda self: self._file_location, fset=set_file_location) file_location = property(fget=lambda self: self._file_location, fset=set_file_location)
def write_metadata(song: Song): def write_metadata(song: Song, ignore_file_not_found: bool = False):
if not song.target.exists_on_disc: if not song.target.exists_on_disc:
print(song.target.file) if ignore_file_not_found:
return return
raise ValueError(f"{song.target.file} not found")
id3_object = AudioMetadata(file_location=song.target.file) id3_object = AudioMetadata(file_location=song.target.file)
id3_object.add_song_metadata(song=song) id3_object.add_song_metadata(song=song)
id3_object.save() id3_object.save()
@ -62,7 +61,7 @@ def write_metadata(song: Song):
def write_many_metadata(song_list: List[Song]): def write_many_metadata(song_list: List[Song]):
for song in song_list: for song in song_list:
write_metadata(song=song) write_metadata(song=song, ignore_file_not_found=True)
if __name__ == "__main__": if __name__ == "__main__":

Binary file not shown.