diff options
| author | exislow <exislow@users.noreply.github.com> | 2024-02-01 20:05:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-01 20:05:25 +0100 |
| commit | 9306a30f250b880ab092d27e08a809cd5f7ae7c7 (patch) | |
| tree | 082f5b16d7324986640bb3f0c68bdcf7fe969400 | |
| parent | 4b21ecd820159e7913eab62df83a3fc27bfafce6 (diff) | |
| parent | fe5d450cb3d3ae3514f11ec6685579b553ac6225 (diff) | |
| download | tidal-dl-ng-9306a30f250b880ab092d27e08a809cd5f7ae7c7.tar.gz | |
Merge pull request #26 from exislow/dl-wait-track
✨ Respect download delay when downloading a bunch of tracks / videos.
| -rw-r--r-- | tidal_dl_ng/cli.py | 14 | ||||
| -rw-r--r-- | tidal_dl_ng/download.py | 12 | ||||
| -rw-r--r-- | tidal_dl_ng/gui.py | 17 |
3 files changed, 30 insertions, 13 deletions
diff --git a/tidal_dl_ng/cli.py b/tidal_dl_ng/cli.py index e84eafc..4902f74 100644 --- a/tidal_dl_ng/cli.py +++ b/tidal_dl_ng/cli.py @@ -105,7 +105,7 @@ def login(ctx: typer.Context) -> bool: def download( ctx: typer.Context, urls: Annotated[Optional[list[str]], typer.Argument()] = None, - list_urls: Annotated[ + file_urls: Annotated[ Optional[Path], typer.Option( "--list", @@ -122,8 +122,8 @@ def download( ): if not urls: # Read the text file provided. - if list_urls: - text = list_urls.read_text() + if file_urls: + text = file_urls.read_text() urls = text.splitlines() else: print("Provide either URLs, IDs or a file containing URLs (one per line).") @@ -154,6 +154,8 @@ def download( # Style Progress display. progress_table.add_row(Panel.fit(progress, title="Download Progress", border_style="green", padding=(2, 2))) + urls_pos_last = len(urls) - 1 + for item in urls: media_type: MediaType | bool = False @@ -173,10 +175,10 @@ def download( with Live(progress_table, refresh_per_second=10): # Download media. if media_type in [MediaType.TRACK, MediaType.VIDEO]: + download_delay: bool = bool(settings.data.download_delay and urls.index(item) < urls_pos_last) + dl.item( - media_id=item_id, - media_type=media_type, - file_template=file_template, + media_id=item_id, media_type=media_type, file_template=file_template, download_delay=download_delay ) elif media_type in [MediaType.ALBUM, MediaType.PLAYLIST, MediaType.MIX]: dl.items( 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) diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index 2a1b2d1..267ff3b 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -483,25 +483,30 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): if len(items) == 0: logger_gui.error("Please select a row first.") else: + items_pos_last = len(items) - 1 + for item in items: media: Track | Album | Playlist | Video = item.data(5, QtCore.Qt.ItemDataRole.UserRole) + # Skip only if Track item, skip option set and the item is not the last in the list. + download_delay: bool = bool( + isinstance(media, Track | Video) + and self.settings.data.download_delay + and items.index(item) < items_pos_last + ) - self.download(media, self.dl) + self.download(media, self.dl, delay_track=download_delay) self.b_download.setText("Download") self.b_download.setEnabled(True) - def download(self, media: Track | Album | Playlist | Video | Mix, dl: Download) -> None: + def download(self, media: Track | Album | Playlist | Video | Mix, dl: Download, delay_track: bool = False) -> None: self.s_pb_reset.emit() self.s_statusbar_message.emit(StatusbarMessage(message="Download started...")) file_template = get_format_template(media, self.settings) if isinstance(media, Track | Video): - dl.item( - media=media, - file_template=file_template, - ) + dl.item(media=media, file_template=file_template, download_delay=delay_track) elif isinstance(media, Album | Playlist | Mix): dl.items( media=media, |
