From 133e36056241219c10ca4b03a71583277a8338c5 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 12 Jan 2023 16:25:50 +0100 Subject: [PATCH] dasfh --- src/goof.py | 3 +- src/music_kraken/database/new_database.py | 5 +- src/music_kraken/database/objects/__init__.py | 5 +- src/music_kraken/database/objects/artist.py | 2 +- .../{database_object.py => parents.py} | 19 ++++++++ src/music_kraken/database/objects/song.py | 43 +++--------------- src/music_kraken/database/objects/source.py | 41 +++++++++++++++++ src/music_kraken/database/song.py | 2 +- src/music_kraken/tagging/id3.py | 14 +++--- test.db | Bin 69632 -> 69632 bytes 10 files changed, 84 insertions(+), 50 deletions(-) rename src/music_kraken/database/objects/{database_object.py => parents.py} (72%) create mode 100644 src/music_kraken/database/objects/source.py 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 856e732f325ff666893e9cbf0937c2cb24045e09..10a5c2dce2bbeb2a8a8796264d305fffdbbfc5c0 100644 GIT binary patch delta 655 zcma)(yGjE=6oxaK#anZ<(L%u#ffVt;?9R;2PG!JKM6lV~%w}dJpi$5&jVV%#mo8O` zyg;(#9r6$sK7d6YK+we|2o_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