From 564621b3325258e73442f4482e1b5e44e8c75d72 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 15 Jan 2024 11:52:31 +0100 Subject: [PATCH] fix: downloading into correct artist --- src/music_kraken/objects/parents.py | 2 +- src/music_kraken/objects/song.py | 10 +++++----- src/music_kraken/pages/abstract.py | 22 +++++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/music_kraken/objects/parents.py b/src/music_kraken/objects/parents.py index f231bfd..e1d07f5 100644 --- a/src/music_kraken/objects/parents.py +++ b/src/music_kraken/objects/parents.py @@ -61,7 +61,7 @@ class OuterProxy: """ _default_factories: dict = {} - _outer_attribute: Set[str] = {"options", "metadata", "indexing_values"} + _outer_attribute: Set[str] = {"options", "metadata", "indexing_values", "option_string"} DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = tuple() UPWARDS_COLLECTION_STRING_ATTRIBUTES = tuple() diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index 120f109..0b6b553 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -61,13 +61,13 @@ class Song(Base): "album_collection": Collection, "feature_artist_collection": Collection, - "title": lambda: None, + "title": lambda: "", "unified_title": lambda: None, "isrc": lambda: None, "genre": lambda: None, } - def __init__(self, title: str = None, unified_title: str = None, isrc: str = None, length: int = None, + def __init__(self, title: str = "", unified_title: str = None, isrc: str = None, length: int = None, genre: str = None, note: FormattedText = None, source_list: List[Source] = None, target_list: List[Target] = None, lyrics_list: List[Lyrics] = None, main_artist_list: List[Artist] = None, feature_artist_list: List[Artist] = None, @@ -264,7 +264,7 @@ class Album(Base): @property def option_string(self) -> str: return f"{self.__repr__()} " \ - f"by Artist({OPTION_STRING_DELIMITER.join([str(artist.name) for artist in self.artist_collection])}) " \ + f"by Artist({OPTION_STRING_DELIMITER.join([artist.name for artist in self.artist_collection])}) " \ f"under Label({OPTION_STRING_DELIMITER.join([label.name for label in self.label_collection])})" @property @@ -390,7 +390,7 @@ class Artist(Base): label_collection: Collection[Label] _default_factories = { - "name": lambda: None, + "name": str, "unified_name": lambda: None, "country": lambda: None, "unformated_location": lambda: None, @@ -408,7 +408,7 @@ class Artist(Base): } # This is automatically generated - def __init__(self, name: str = None, unified_name: str = None, country: Country = None, + def __init__(self, name: str = "", unified_name: str = None, country: Country = None, formed_in: ID3Timestamp = None, notes: FormattedText = None, lyrical_themes: List[str] = None, general_genre: str = None, unformated_location: str = None, source_list: List[Source] = None, contact_list: List[Contact] = None, feature_song_list: List[Song] = None, diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index da15133..7a8751c 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -240,20 +240,28 @@ class Page: """ # creating a new object, of the same type - new_music_object: DatabaseObject = type(music_object)() + new_music_object: Optional[DatabaseObject] = None # only certain database objects, have a source list if isinstance(music_object, INDEPENDENT_DB_OBJECTS): source: Source for source in music_object.source_collection.get_sources_from_page(self.SOURCE_TYPE): - new_music_object.merge(self.fetch_object_from_source( - source=source, - enforce_type=type(music_object), - stop_at_level=stop_at_level, + tmp = self.fetch_object_from_source( + source=source, + enforce_type=type(music_object), + stop_at_level=stop_at_level, post_process=False - )) + ) - return music_object.merge(new_music_object) + if new_music_object is None: + new_music_object = tmp + else: + new_music_object.merge(tmp) + + if new_music_object is not None: + music_object.merge(new_music_object) + + return music_object def fetch_object_from_source(self, source: Source, stop_at_level: int = 2, enforce_type: Type[DatabaseObject] = None, post_process: bool = True) -> Optional[DatabaseObject]: obj_type = self.get_source_type(source)