diff --git a/src/music_kraken/objects/collection.py b/src/music_kraken/objects/collection.py index 3a35e0a..2daf0fa 100644 --- a/src/music_kraken/objects/collection.py +++ b/src/music_kraken/objects/collection.py @@ -96,7 +96,7 @@ class Collection: return AppendResult(True, existing_object, False) # if the object does already exist - # thus merging and don't add it afterwards + # thus merging and don't add it afterward if merge_into_existing: existing_object.merge(element) # in case any relevant data has been added (e.g. it remaps the old object) diff --git a/src/music_kraken/objects/parents.py b/src/music_kraken/objects/parents.py index f692dea..a6b50fb 100644 --- a/src/music_kraken/objects/parents.py +++ b/src/music_kraken/objects/parents.py @@ -11,6 +11,10 @@ class DatabaseObject: COLLECTION_ATTRIBUTES: tuple = tuple() SIMPLE_ATTRIBUTES: dict = dict() + # contains all collection attributes, which describe something "smaller" + # e.g. album has songs, but not artist. + DOWNWARDS_COLLECTION_ATTRIBUTES: tuple = tuple() + def __init__(self, _id: int = None, dynamic: bool = False, **kwargs) -> None: self.automatic_id: bool = False diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index 3716b03..e7b0194 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -204,6 +204,8 @@ class Album(MainObject): "notes": FormattedText() } + DOWNWARDS_COLLECTION_ATTRIBUTES = ("song_collection",) + def __init__( self, _id: int = None, @@ -422,6 +424,8 @@ class Artist(MainObject): "general_genre": "" } + DOWNWARDS_COLLECTION_ATTRIBUTES = ("feature_song_collection", "main_album_collection") + def __init__( self, _id: int = None, @@ -646,6 +650,8 @@ class Label(MainObject): "notes": FormattedText() } + DOWNWARDS_COLLECTION_ATTRIBUTES = COLLECTION_ATTRIBUTES + def __init__( self, _id: int = None, diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index d5cd8fa..a53526b 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -237,6 +237,38 @@ class Page(threading.Thread): def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label: return Label() + def download(self, music_object: DatabaseObject, download_all: bool = False) -> DownloadResult: + self._download(music_object, {}, download_all) + + return DownloadResult() + + + def _download(self, music_object: DatabaseObject, naming_objects: Dict[Type[DatabaseObject], DatabaseObject], download_all: bool = False) -> list: + # Skips all releases, that are defined in shared.ALBUM_TYPE_BLACKLIST, if download_all is False + if isinstance(music_object, Album): + if not download_all and music_object.album_type in shared.ALBUM_TYPE_BLACKLIST: + return [] + + naming_objects[type(music_object)] = music_object + + if isinstance(music_object, Song): + print("Downloading", music_object) + return [music_object] + + return_values: List = [] + + for collection_name in music_object.DOWNWARDS_COLLECTION_ATTRIBUTES: + collection: Collection = getattr(self, collection_name) + + sub_ordered_music_object: DatabaseObject + for sub_ordered_music_object in collection: + return_values.extend(self._download(sub_ordered_music_object, naming_objects.copy(), download_all)) + + return return_values + + def download_song(self, song: Song, naming_objects: Dict[Type[DatabaseObject], DatabaseObject]): + pass + @classmethod def download( cls,