From 6d3c36e075c7f78826b28e9af6c74a13ae1255f4 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Thu, 30 Mar 2023 14:52:50 +0200 Subject: [PATCH] completed the downloading layout --- src/music_kraken/pages/abstract.py | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index fee2603..e0819b4 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -213,7 +213,7 @@ class Page: @classmethod - def _fetch_object_from_source(cls, source: Source, obj_type: Union[Type[Song], Type[Album], Type[Artist], Type[Label]], stop_at_level: int = 1): + def _fetch_object_from_source(cls, source: Source, obj_type: Union[Type[Song], Type[Album], Type[Artist], Type[Label]], stop_at_level: int = 1) -> Union[Song, Album, Artist, Label]: if obj_type == Artist: return cls._fetch_artist_from_source(source=source, stop_at_level=stop_at_level) @@ -274,6 +274,39 @@ class Page: cls._clean_collection(song.feature_artist_collection, collections) cls._clean_collection(song.main_artist_collection, collections) + @classmethod + def download(cls, music_object: Union[Song, Album, Artist, Label], download_features: bool = True): + if type(music_object) is Song: + return cls.download_song(music_object) + if type(music_object) is Album: + return cls.download_album(music_object) + if type(music_object) is Artist: + return cls.download_artist(music_object, download_features=download_features) + if type(music_object) is Label: + return cls.download_label(music_object, download_features=download_features) + + @classmethod + def download_label(cls, label: Label, download_features: bool = True): + for artist in label.current_artist_collection: + cls.download_artist(artist, download_features=download_features) + + for album in label.album_collection: + cls.download_album(album) + + @classmethod + def download_artist(cls, artist: Artist, download_features: bool = True): + for album in artist.main_album_collection: + cls.download_album(album) + + if download_features: + for song in artist.feature_album: + cls.download_song(song) + + @classmethod + def download_album(cls, album: Album): + for song in album.song_collection: + cls.download_song(song) + @classmethod def download_song(cls, song: Song): if song.target_collection.empty: