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,
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)

View File

@ -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,17 +41,18 @@ 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)
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)
@ -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__":

Binary file not shown.