From 635c8b87a406947d3dbc8f24c854807125ff580b Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Fri, 10 Mar 2023 10:13:35 +0100 Subject: [PATCH] fixed exceptions --- src/create_custom_objects.py | 67 ++++++++++++-------------- src/music_kraken/objects/__init__.py | 1 - src/music_kraken/objects/collection.py | 5 +- src/music_kraken/objects/lyrics.py | 2 +- src/music_kraken/objects/song.py | 3 +- src/music_kraken/objects/source.py | 15 +++--- src/music_kraken/pages/abstract.py | 2 +- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/create_custom_objects.py b/src/create_custom_objects.py index 02656c2..8886dca 100644 --- a/src/create_custom_objects.py +++ b/src/create_custom_objects.py @@ -1,14 +1,5 @@ -import music_kraken from music_kraken import objects -from music_kraken.tagging import ( - AudioMetadata, - write_metadata, - write_many_metadata -) - -import music_kraken.database.old_database as db - import pycountry import logging @@ -19,10 +10,7 @@ def div(msg: str = ""): print("-" * 50 + msg + "-" * 50) -cache.reset() - - -def print_song(song_: Song): +def print_song(song_: objects.Song): print(str(song_.metadata)) print("----album--") print(song_.album) @@ -34,49 +22,56 @@ def print_song(song_: Song): print("\n") -song = Song( +song = objects.Song( genre="HS Core", title="Vein Deep in the Solution", length=666, isrc="US-S1Z-99-00001", tracksort=2, - target=Target(file="song.mp3", path="~/Music"), - lyrics=[ - Lyrics(text="these are some depressive lyrics", language="en"), - Lyrics(text="Dies sind depressive Lyrics", language="de") + target=[ + objects.Target(file="song.mp3", path="example") + ], + lyrics_list=[ + objects.Lyrics(text="these are some depressive lyrics", language="en"), + objects.Lyrics(text="Dies sind depressive Lyrics", language="de") ], source_list=[ - Source(SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"), - Source(SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/") + objects.Source(objects.SourcePages.YOUTUBE, "https://youtu.be/dfnsdajlhkjhsd"), + objects.Source(objects.SourcePages.MUSIFY, "https://ln.topdf.de/Music-Kraken/") ], - album=Album( + album_list=[ + objects.Album( title="One Final Action", - date=ID3Timestamp(year=1986, month=3, day=1), + date=objects.ID3Timestamp(year=1986, month=3, day=1), language=pycountry.languages.get(alpha_2="en"), label="cum productions", source_list=[ - Source(SourcePages.ENCYCLOPAEDIA_METALLUM, - "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614") - ] - ), - main_artist_list=[ - Artist( - name="I'm in a coffin", - source_list=[ - Source(SourcePages.ENCYCLOPAEDIA_METALLUM, - "https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727") + objects.Source(objects.SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614") ] ), - Artist(name="some_split_artist") ], - feature_artist_list=[Artist(name="Ruffiction")], + main_artist_list=[ + objects.Artist( + name="I'm in a coffin", + source_list=[ + objects.Source( + objects.SourcePages.ENCYCLOPAEDIA_METALLUM, + "https://www.metal-archives.com/bands/I%27m_in_a_Coffin/127727" + ) + ] + ), + objects.Artist(name="some_split_artist") + ], + feature_artist_list=[objects.Artist(name="Ruffiction")], ) -print_song(song) +print(song) + +exit() div() song_ref = song.reference -cache.push([song]) + # getting song by song ref song_list = cache.pull_songs(song_ref=song_ref) diff --git a/src/music_kraken/objects/__init__.py b/src/music_kraken/objects/__init__.py index dcdb1e2..2f39411 100644 --- a/src/music_kraken/objects/__init__.py +++ b/src/music_kraken/objects/__init__.py @@ -15,7 +15,6 @@ ID3Timestamp = metadata.ID3Timestamp Source = source.Source SourceTypes = source.SourceTypes SourcePages = source.SourcePages -SourceAttribute = source.SourceAttribute Song = song.Song Artist = song.Artist diff --git a/src/music_kraken/objects/collection.py b/src/music_kraken/objects/collection.py index 0908bf9..9012f45 100644 --- a/src/music_kraken/objects/collection.py +++ b/src/music_kraken/objects/collection.py @@ -34,7 +34,8 @@ class Collection: """ self._attribute_to_object_map: Dict[str, Dict[object, DatabaseObject]] = defaultdict(dict) - self.extend(data, merge_on_conflict=True) + if data is not None: + self.extend(data, merge_on_conflict=True) def sort(self, reverse: bool = False, **kwargs): self._data.sort(reverse=reverse, **kwargs) @@ -51,7 +52,7 @@ class Collection: """ # if the element type has been defined in the initializer it checks if the type matches - if self.element_type is not None and isinstance(element, self.element_type): + if self.element_type is not None and not isinstance(element, self.element_type): raise TypeError(f"{type(element)} is not the set type {self.element_type}") for name, value in element.indexing_values: diff --git a/src/music_kraken/objects/lyrics.py b/src/music_kraken/objects/lyrics.py index fcd9ea5..67931c6 100644 --- a/src/music_kraken/objects/lyrics.py +++ b/src/music_kraken/objects/lyrics.py @@ -18,7 +18,7 @@ class Lyrics(DatabaseObject): source_list: List[Source] = None, **kwargs ) -> None: - DatabaseObject.__init__(_id=_id, dynamic=dynamic) + DatabaseObject.__init__(self, _id=_id, dynamic=dynamic) self.text: FormattedText = text self.language: pycountry.Languages = language diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index 13378a0..bd224a5 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -20,7 +20,6 @@ from .source import ( Source, SourceTypes, SourcePages, - SourceAttribute, SourceCollection ) from .formatted_text import FormattedText @@ -462,7 +461,7 @@ Label """ -class Label(MainObject, SourceAttribute): +class Label(MainObject): COLLECTION_ATTRIBUTES = ("album_collection", "current_artist_collection") SIMPLE_ATTRIBUTES = ("name",) diff --git a/src/music_kraken/objects/source.py b/src/music_kraken/objects/source.py index 3b4a431..f95ab80 100644 --- a/src/music_kraken/objects/source.py +++ b/src/music_kraken/objects/source.py @@ -47,7 +47,7 @@ class SourcePages(Enum): return homepage_map[attribute] -class Source(DatabaseObject, MetadataAttribute): +class Source(DatabaseObject): """ create somehow like that ```python @@ -95,14 +95,14 @@ class Source(DatabaseObject, MetadataAttribute): if url.startswith("https://twitter"): return cls(SourcePages.TWITTER, url) - def get_song_metadata(self) -> MetadataAttribute.Metadata: - return MetadataAttribute.Metadata({ + def get_song_metadata(self) -> Metadata: + return Metadata({ Mapping.FILE_WEBPAGE_URL: [self.url], Mapping.SOURCE_WEBPAGE_URL: [self.homepage] }) - def get_artist_metadata(self) -> MetadataAttribute.Metadata: - return MetadataAttribute.Metadata({ + def get_artist_metadata(self) -> Metadata: + return Metadata({ Mapping.ARTIST_WEBPAGE_URL: [self.url] }) @@ -136,10 +136,11 @@ class Source(DatabaseObject, MetadataAttribute): class SourceCollection(Collection): def __init__(self, source_list: List[Source]): - super().__init__(data=source_list, element_type=Source) - self._page_to_source_list: Dict[SourcePages, List[Source]] = defaultdict(list) + super().__init__(data=source_list, element_type=Source) + + def map_element(self, source: Source): super().map_element(source) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 59cd428..be08b81 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -2,7 +2,7 @@ from typing import ( List ) -from ..database import ( +from ..objects import ( Song, Source, Album,