From fe5d450cb3d3ae3514f11ec6685579b553ac6225 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Thu, 1 Feb 2024 20:04:55 +0100 Subject: ✨ Respect download delay when downloading a bunch of tracks / videos. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/download.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tidal_dl_ng/download.py') diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index 4d5b5e8..fb7db37 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -181,6 +181,7 @@ class Download: media_id: str = None, media_type: MediaType = None, video_download: bool = True, + download_delay: bool = False, ) -> (bool, str): # If no media instance is provided, we need to create the media instance. if media_id and media_type: @@ -241,6 +242,16 @@ class Download: else: self.fn_logger.debug(f"Download skipped, since file exists: '{path_file}'") + status_download: bool = not download_skip + + # If a file was downloaded and the download delay is enabled, wait until the next download. + # Only use this, if you have a list of several Track items. Do not use this for list items. + if download_delay and status_download: + time_sleep: float = round(random.SystemRandom().uniform(2, 5), 1) + + self.fn_logger.debug(f"Next download will start in {time_sleep} seconds.") + time.sleep(time_sleep) + return not download_skip, path_file def cover_url(self, sid: str, dimension: CoverDimensions = CoverDimensions.Px320): @@ -355,7 +366,6 @@ class Download: if download_delay and status_download: time_sleep: float = round(random.SystemRandom().uniform(2, 5), 1) - # TODO: Fix logging. Is not displayed in debug window. self.fn_logger.debug(f"Next download will start in {time_sleep} seconds.") time.sleep(time_sleep) -- cgit v1.3.1