From fb3a1e22b01362fce0eb56628f48b6598be37c00 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Thu, 15 Jun 2023 11:48:04 +0200 Subject: [PATCH] removed redundand requests to the invidious api --- src/music_kraken/pages/abstract.py | 16 +++++++++++++--- src/music_kraken/pages/youtube.py | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 5e96be8..d5e9b99 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -172,6 +172,9 @@ class Page: SOURCE_TYPE: SourcePages LOGGER = logging.getLogger("this shouldn't be used") + # set this to true, if all song details can also be fetched by fetching album details + NO_ADDITIONAL_DATA_FROM_SONG = False + def __init__(self): super().__init__() @@ -341,13 +344,20 @@ class Page: return self._download(music_object, naming_dict, download_all) - def _download(self, music_object: DatabaseObject, naming_dict: NamingDict, download_all: bool = False) -> DownloadResult: + def _download(self, music_object: DatabaseObject, naming_dict: NamingDict, download_all: bool = False, skip_details: bool = False) -> DownloadResult: + skip_next_details = skip_details + # Skips all releases, that are defined in shared.ALBUM_TYPE_BLACKLIST, if download_all is False if isinstance(music_object, Album): + if self.NO_ADDITIONAL_DATA_FROM_SONG: + skip_next_details = True + if not download_all and music_object.album_type in shared.ALBUM_TYPE_BLACKLIST: return DownloadResult() - self.fetch_details(music_object=music_object, stop_at_level=2) + if not isinstance(music_object, Song) or not self.NO_ADDITIONAL_DATA_FROM_SONG: + self.fetch_details(music_object=music_object, stop_at_level=2) + naming_dict.add_object(music_object) if isinstance(music_object, Song): @@ -360,7 +370,7 @@ class Page: sub_ordered_music_object: DatabaseObject for sub_ordered_music_object in collection: - download_result.merge(self._download(sub_ordered_music_object, naming_dict.copy(), download_all)) + download_result.merge(self._download(sub_ordered_music_object, naming_dict.copy(), download_all, skip_details=skip_next_details)) return download_result diff --git a/src/music_kraken/pages/youtube.py b/src/music_kraken/pages/youtube.py index b343282..4e5b9fe 100644 --- a/src/music_kraken/pages/youtube.py +++ b/src/music_kraken/pages/youtube.py @@ -132,6 +132,8 @@ class YouTube(Page): SOURCE_TYPE = SourcePages.YOUTUBE LOGGER = YOUTUBE_LOGGER + NO_ADDITIONAL_DATA_FROM_SONG = True + def __init__(self, *args, **kwargs): self.connection: Connection = Connection( host=get_invidious_url(),