From a3ef671f00441afb18556adbc0e9f0bb01e2f6b9 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Tue, 30 Apr 2024 02:09:52 +0200 Subject: [PATCH] feat: tried improving fetching --- music_kraken/objects/collection.py | 5 ++++- music_kraken/pages/youtube_music/_list_render.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/music_kraken/objects/collection.py b/music_kraken/objects/collection.py index f3139cd..4bba8bb 100644 --- a/music_kraken/objects/collection.py +++ b/music_kraken/objects/collection.py @@ -143,7 +143,10 @@ class Collection(Generic[T]): return existing_object.merge(__object, **kwargs) - self._map_element(existing_object) + self._map_element(existing_object) + + def contains(self, __object: T) -> bool: + return self._find_object(__object) is not None def extend(self, __iterable: Optional[Generator[T, None, None]], **kwargs): if __iterable is None: diff --git a/music_kraken/pages/youtube_music/_list_render.py b/music_kraken/pages/youtube_music/_list_render.py index 8076e54..cd7f878 100644 --- a/music_kraken/pages/youtube_music/_list_render.py +++ b/music_kraken/pages/youtube_music/_list_render.py @@ -56,15 +56,24 @@ def music_responsive_list_item_renderer(renderer: dict) -> List[DatabaseObject]: for song in song_list: song.album_collection.extend(album_list) - song.main_artist_collection.extend(artist_list) + + for artist in artist_list: + existing_artist = song.main_artist_collection._find_object(artist) + + if existing_artist is None: + song.feature_artist_collection.append(artist) + else: + existing_artist.merge(artist) + + if len(song_list) > 0: + return song_list for album in album_list: album.artist_collection.extend(artist_list) - if len(song_list) > 0: - return song_list if len(album_list) > 0: return album_list + if len(artist_list) > 0: return artist_list