diff --git a/src/goof.py b/src/goof.py index 0e51dad..c7aab3d 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="~/Music/test/Linkin Park/Hybrid Theory/Cure for the Itch.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"), + target=Target(file="test/Linkin Park/Hybrid Theory/out.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"), lyrics=[ Lyrics(text="these are some depressive lyrics", language="en"), Lyrics(text="test", language="en") @@ -100,6 +100,7 @@ for source in song.sources: # try writing metadata 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/database/new_database.py b/src/music_kraken/database/new_database.py index c06c9c8..b830bd8 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -4,17 +4,18 @@ import logging from typing import List, Tuple from pkg_resources import resource_string -from .objects.database_object import Reference +from .objects.parents import Reference +from .objects.source import Source from .objects import ( Song, Lyrics, Metadata, Target, Artist, - Source, Album ) + logger = logging.getLogger("database") # Due to this not being deployed on a Server **HOPEFULLY** diff --git a/src/music_kraken/database/objects/__init__.py b/src/music_kraken/database/objects/__init__.py index d749de5..50f2e5c 100644 --- a/src/music_kraken/database/objects/__init__.py +++ b/src/music_kraken/database/objects/__init__.py @@ -1,13 +1,14 @@ from . import ( song, - id3_mapping + id3_mapping, + source ) ID3_MAPPING = id3_mapping.Mapping Song = song.Song Artist = song.Artist -Source = song.Source +Source = source.Source Target = song.Target Metadata = song.Metadata Lyrics = song.Lyrics diff --git a/src/music_kraken/database/objects/artist.py b/src/music_kraken/database/objects/artist.py index 4789a1b..e06ea05 100644 --- a/src/music_kraken/database/objects/artist.py +++ b/src/music_kraken/database/objects/artist.py @@ -1,7 +1,7 @@ from ...utils.shared import ( DATABASE_LOGGER as logger ) -from .database_object import ( +from .parents import ( DatabaseObject, Reference ) diff --git a/src/music_kraken/database/objects/database_object.py b/src/music_kraken/database/objects/parents.py similarity index 72% rename from src/music_kraken/database/objects/database_object.py rename to src/music_kraken/database/objects/parents.py index 506d148..6e104d8 100644 --- a/src/music_kraken/database/objects/database_object.py +++ b/src/music_kraken/database/objects/parents.py @@ -45,3 +45,22 @@ class DatabaseObject: id = property(fget=get_id) reference = property(fget=get_reference) + + +class SongAttribute: + def __init__(self, song=None): + # the reference to the song the lyrics belong to + self.song = song + + def add_song(self, song): + self.song = song + + def get_ref_song_id(self): + if self.song is None: + return None + return self.song.reference.id + + def set_ref_song_id(self, song_id): + self.song_ref = Reference(song_id) + + song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 3ca1cdc..0cb0c62 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -7,33 +7,19 @@ from ...utils.shared import ( MUSIC_DIR, DATABASE_LOGGER as logger ) -from .database_object import ( +from .parents import ( DatabaseObject, - Reference + Reference, + SongAttribute ) +from .source import Source """ All Objects dependent """ -class SongAttribute: - def __init__(self, song=None): - # the reference to the song the lyrics belong to - self.song = song - def add_song(self, song): - self.song = song - - def get_ref_song_id(self): - if self.song is None: - return None - return self.song.reference.id - - def set_ref_song_id(self, song_id): - self.song_ref = Reference(song_id) - - song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id) class Metadata: @@ -58,7 +44,9 @@ class Metadata: return if type(value) != list: raise ValueError(f"can only set attribute to list, not {type(value)}") - self.id3_attributes[key] = value + + # self.id3_attributes[key] = [value[0], "HHHHSSSS"] + self.id3_attributes[key] = value[0] def __getitem__(self, key): if key not in self.id3_attributes: @@ -96,24 +84,7 @@ class Metadata: return "\n".join(rows) -class Source(DatabaseObject, SongAttribute): - """ - create somehow like that - ```python - # url won't be a valid one due to it being just an example - Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd") - ``` - """ - def __init__(self, id_: str = None, src: str = None, url: str = None) -> None: - DatabaseObject.__init__(self, id_=id_) - SongAttribute.__init__(self) - - self.src = src - self.url = url - - def __str__(self): - return f"{self.src}: {self.url}" class Target(DatabaseObject, SongAttribute): diff --git a/src/music_kraken/database/objects/source.py b/src/music_kraken/database/objects/source.py new file mode 100644 index 0000000..75cc89c --- /dev/null +++ b/src/music_kraken/database/objects/source.py @@ -0,0 +1,41 @@ +from enum import Enum + +from .parents import ( + DatabaseObject, + SongAttribute +) + +class sources(Enum): + YOUTUBE = "youtube" + MUSIFY = "musify" + + @classmethod + def get_homepage(cls, attribute) -> str: + homepage_map = { + cls.YOUTUBE: "https://www.youtube.com/", + cls.MUSIFY: "https://musify.club/" + } + return homepage_map[attribute] + + + +class Source(DatabaseObject, SongAttribute): + """ + create somehow like that + ```python + # url won't be a valid one due to it being just an example + Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd") + ``` + """ + + def __init__(self, id_: str = None, src: str = None, url: str = None) -> None: + DatabaseObject.__init__(self, id_=id_) + SongAttribute.__init__(self) + + self.src = sources(src) + self.url = url + + def __str__(self): + return f"{self.src}: {self.url}" + + homepage = property(fget=lambda self: sources.get_homepage(self.src)) diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index 1a264d5..a2a8f60 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -7,7 +7,7 @@ from ..utils.shared import ( MUSIC_DIR, SONG_LOGGER as logger ) -from .objects.database_object import DatabaseObject +from .objects.parents import DatabaseObject class Metadata: def __init__(self) -> None: diff --git a/src/music_kraken/tagging/id3.py b/src/music_kraken/tagging/id3.py index 137ac21..8d0b06d 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 @@ -18,7 +18,7 @@ class AudioMetadata: self.frames: ID3 = ID3() - if self.file_location is not None: + if file_location is not None: self.file_location = file_location @@ -26,10 +26,10 @@ class AudioMetadata: print("adding") for key, value in song.metadata: """ - TODO: - Implement the adding to the frame thingie of the 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): if file_location is not None: @@ -37,12 +37,12 @@ class AudioMetadata: if self.file_location is None: raise Exception("no file target provided to save the data to") - self.frames.save(filething=self.file_location) + self.frames.save(self.file_location, v2_version=4) 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.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}\"") @@ -52,7 +52,7 @@ class AudioMetadata: def write_metadata(song: Song): if not song.target.exists_on_disc: - print("afhhkj") + print(song.target.file) return id3_object = AudioMetadata(file_location=song.target.file) diff --git a/test.db b/test.db index 856e732..10a5c2d 100644 Binary files a/test.db and b/test.db differ