summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/download.py
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-12-15 23:35:10 +0100
committerRobert Honz <exislow+github@gmail.com>2024-12-15 23:35:10 +0100
commit5768edacc57fd29bf2ef182cb9db312d4aebb468 (patch)
treecb5ec1765386c3e08bf90fa82103341c1c8bb1d3 /tidal_dl_ng/download.py
parent62c32f19a4bbf708e6330f3c89813de1c1883ad1 (diff)
downloadtidal-dl-ng-5768edacc57fd29bf2ef182cb9db312d4aebb468.tar.gz
✨ Multithreaded downloads implemented (for Playlists, Albums etc.). Fixes #180
Diffstat (limited to 'tidal_dl_ng/download.py')
-rw-r--r--tidal_dl_ng/download.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index 83d8743..af00497 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -621,22 +621,30 @@ class Download:
# Iterate through list items
while not self.progress.finished:
- for item_media in items:
- # Download the item.
- status, result_path_file = self.item(
- media=item_media,
- file_template=file_name_relative,
- quality_audio=quality_audio,
- quality_video=quality_video,
- download_delay=download_delay,
- is_parent_album=is_album,
- )
+ with futures.ThreadPoolExecutor(max_workers=self.settings.data.downloads_concurrent_max) as executor:
+ # Dispatch all download tasks to worker threads
+ l_futures: [any] = [
+ executor.submit(
+ self.item,
+ media=item_media,
+ file_template=file_name_relative,
+ quality_audio=quality_audio,
+ quality_video=quality_video,
+ download_delay=download_delay,
+ is_parent_album=is_album,
+ )
+ for item_media in items
+ ]
+ # Report results as they become available
+ for future in futures.as_completed(l_futures):
+ # Retrieve result
+ status, result_path_file = future.result()
- # Advance progress bar.
- self.progress.advance(p_task1)
+ # Advance progress bar.
+ self.progress.advance(p_task1)
- if not progress_stdout:
- self.progress_gui.list_item.emit(self.progress.tasks[p_task1].percentage)
+ if not progress_stdout:
+ self.progress_gui.list_item.emit(self.progress.tasks[p_task1].percentage)
self.fn_logger.info(f"Finished list '{list_media_name}'.")