From b6a8966503adabcbaf5083d81a46449554f3dbe6 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Wed, 11 Jan 2023 16:30:53 +0100 Subject: [PATCH] am --- src/goof.py | 11 ++++- src/music_kraken/database/objects/song.py | 1 + src/music_kraken/tagging/__init__.py | 9 ++++ src/music_kraken/tagging/id3.py | 55 ++++++++++++++++++---- src/music_kraken/utils/shared.py | 1 + test.db | Bin 69632 -> 69632 bytes 6 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/goof.py b/src/goof.py index 4313320..0e51dad 100644 --- a/src/goof.py +++ b/src/goof.py @@ -8,6 +8,12 @@ from music_kraken import ( Artist ) +from music_kraken.tagging import ( + AudioMetadata, + write_metadata, + write_many_metadata +) + import music_kraken.database.new_database as db @@ -45,7 +51,7 @@ song_input = Song( length=666, isrc="US-S1Z-99-00001", tracksort=2, - target=Target(file="~/Music/genre/artist/album/song.mp3", path="~/Music/genre/artist/album"), + target=Target(file="~/Music/test/Linkin Park/Hybrid Theory/Cure for the Itch.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"), lyrics=[ Lyrics(text="these are some depressive lyrics", language="en"), Lyrics(text="test", language="en") @@ -91,6 +97,9 @@ print("--src--") for source in song.sources: print(source) +# try writing metadata +write_metadata(song) + # getting song by album ref div() song_output_list = cache.pull_songs(album_ref=album_input.reference) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 677accb..3ca1cdc 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -301,6 +301,7 @@ class Song(DatabaseObject): self._sources = source_list for source in self._sources: source.add_song(self) + self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = [s.url for s in self._sources] def get_metadata(self): diff --git a/src/music_kraken/tagging/__init__.py b/src/music_kraken/tagging/__init__.py index e69de29..2a2c527 100644 --- a/src/music_kraken/tagging/__init__.py +++ b/src/music_kraken/tagging/__init__.py @@ -0,0 +1,9 @@ +from .id3 import ( + AudioMetadata, + write_many_metadata, + write_metadata +) + +AudioMetadata = AudioMetadata +write_many_metadata = write_many_metadata +write_metadata = write_metadata diff --git a/src/music_kraken/tagging/id3.py b/src/music_kraken/tagging/id3.py index a7044ae..137ac21 100644 --- a/src/music_kraken/tagging/id3.py +++ b/src/music_kraken/tagging/id3.py @@ -1,23 +1,35 @@ import mutagen -from mutagen.id3 import ID3 +from mutagen.id3 import ID3, Frame +from typing import List import logging - -logger = logging.Logger("hs") +from ..utils.shared import ( + TAGGING_LOGGER as logger +) +from ..database import ( + Song +) class AudioMetadata: def __init__(self, file_location: str = None) -> None: - self.file_location = file_location + self._file_location = None self.frames: ID3 = ID3() + if self.file_location is not None: - # try loading the data from the given file. if it doesn't succeed the frame remains empty - try: - self.frames.load(self.file_location) - except mutagen.MutagenError: - logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"") + self.file_location = file_location + + + def add_song_metadata(self, song: Song): + print("adding") + for key, value in song.metadata: + """ + TODO: + Implement the adding to the frame thingie of the metadata + """ + print(key, value) def save(self, file_location: str = None): if file_location is not None: @@ -27,6 +39,31 @@ class AudioMetadata: raise Exception("no file target provided to save the data to") self.frames.save(filething=self.file_location) + def set_file_location(self, file_location): + # try loading the data from the given file. if it doesn't succeed the frame remains empty + try: + self.frames.load(file_location) + self._file_location = file_location + except mutagen.MutagenError: + logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"") + + file_location = property(fget=lambda self: self._file_location, fset=set_file_location) + + +def write_metadata(song: Song): + if not song.target.exists_on_disc: + print("afhhkj") + return + + id3_object = AudioMetadata(file_location=song.target.file) + id3_object.add_song_metadata(song=song) + id3_object.save() + + +def write_many_metadata(song_list: List[Song]): + for song in song_list: + write_metadata(song=song) + if __name__ == "__main__": print("called directly") diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 4b5e037..fdd7fa9 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -39,6 +39,7 @@ PATH_LOGGER = logging.getLogger("create-paths") DOWNLOAD_LOGGER = logging.getLogger("download") LYRICS_LOGGER = logging.getLogger("lyrics") GENIUS_LOGGER = logging.getLogger("genius") +TAGGING_LOGGER = logging.getLogger("tagging") NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea" MUSIC_DIR = os.path.join(os.path.expanduser("~"), "Music") diff --git a/test.db b/test.db index 232709a98dc44bad6bde174c4cbb0ecb2f30f35d..856e732f325ff666893e9cbf0937c2cb24045e09 100644 GIT binary patch delta 2431 zcmc&$O>10L7@nD%#75}c&O*em_F{`EwuhW^?)hA3lrB`7(3EZ8^25qs^ z9~RNw+TFWZ+!*iOG&)$SSVYljkC>+%X(lwHl$V@|SjJL*)qknlxHRZj-Z4^&=#ejl z19TserMhfc*`UhEv*>a2;N0c&38=>h-{y77VA;j2>Zc4gSj(!_g&cw6>0Yll$Va_= zzKTcr1x%?i-bEyt0d<4H$XYGh*<_4?aZY{n{>Iw%6zn@7)*Dw(tyat#;c;+CNgfcx z#vUL8AMcsH@|GW13oTL6&SzVF`o7ES^j7~+WsNG-ine!yb~pb%klQFd5UlI zC!asgNrJ(x%GvOKFMoIV=kWe~bmp63y_GFjyhh#8Eb9)Tg_I4BRP5xw{92Dz?q!*80bH?PS*%pYDY5FJCjhv z@uZmUgyNH_+i8BP-@3BkM=60gE}%UrGIs4r5$NBbB+T7rG0X3@?KwF7KP#LK|7b}Z zJsO_3S`n*kL|jS=YYbi#!xk15XCWx2Fm9G+@6{AXjG6Mns_e0S0~g^5kMF)e zd;HgL!=zJ|Fk!iwEmhU2lihwqji_iTkitLU&O&2Ij|#je6u1p8iNLI|_LE@> zUmYCn4L?6V+QX~FiXg!;#z2VZ!O=hNx?pv+6z`MW}q(4zA2lW!iw8P)y*lacdMv2F6D?6uXQ?|UODKL%MCIp zH@UamI3d6#DnU@6z}Y|{C}xD#N})cpkGF5_=3t+qSnu4ux=|4k>p)F{LIk^9Ax!a18LwqGl4wuFKpUNEHmM^~iqof%I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