diff --git a/src/goof.py b/src/goof.py index c7aab3d..b76b06e 100644 --- a/src/goof.py +++ b/src/goof.py @@ -51,7 +51,7 @@ song_input = Song( length=666, isrc="US-S1Z-99-00001", 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(text="these are some depressive lyrics", language="en"), Lyrics(text="test", language="en") @@ -101,6 +101,7 @@ for source in song.sources: write_metadata(song) exit() + # getting song by album ref div() song_output_list = cache.pull_songs(album_ref=album_input.reference) diff --git a/src/music_kraken/tagging/id3.py b/src/music_kraken/tagging/id3.py index 8d0b06d..e55319c 100644 --- a/src/music_kraken/tagging/id3.py +++ b/src/music_kraken/tagging/id3.py @@ -1,4 +1,4 @@ -import mutagen +import mutagen from mutagen.id3 import ID3, Frame from typing import List @@ -21,14 +21,12 @@ class AudioMetadata: if file_location is not None: self.file_location = file_location - def add_song_metadata(self, song: Song): print("adding") for key, value in song.metadata: """ https://www.programcreek.com/python/example/84797/mutagen.id3.ID3 """ - print(key, value) self.frames.add(mutagen.id3.Frames[key](encoding=3, text=value)) 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: self.frames.load(file_location, v2_version=4) - self._file_location = file_location except mutagen.MutagenError: 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) -def write_metadata(song: Song): +def write_metadata(song: Song, ignore_file_not_found: bool = False): if not song.target.exists_on_disc: - print(song.target.file) - return - + if ignore_file_not_found: + return + raise ValueError(f"{song.target.file} not found") + id3_object = AudioMetadata(file_location=song.target.file) id3_object.add_song_metadata(song=song) id3_object.save() @@ -62,7 +61,7 @@ def write_metadata(song: Song): def write_many_metadata(song_list: List[Song]): for song in song_list: - write_metadata(song=song) + write_metadata(song=song, ignore_file_not_found=True) if __name__ == "__main__": diff --git a/src/test.db b/src/test.db index 9bcedc1..6445b10 100644 Binary files a/src/test.db and b/src/test.db differ