From 89a03c829a575607d412f6cddedc2da75c9b49f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Dudzi=C5=84ski?= <56404247+oskvr37@users.noreply.github.com> Date: Thu, 25 Sep 2025 19:12:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20concurrent=20playlist=20?= =?UTF-8?q?download=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiddl/cli/download/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tiddl/cli/download/__init__.py b/tiddl/cli/download/__init__.py index 2d4286c..e8edeed 100644 --- a/tiddl/cli/download/__init__.py +++ b/tiddl/cli/download/__init__.py @@ -1,8 +1,9 @@ import logging import click import asyncio + from time import perf_counter -from concurrent.futures import ThreadPoolExecutor, Future +from concurrent.futures import ThreadPoolExecutor, Future, as_completed from pathlib import Path from requests import Session @@ -442,6 +443,8 @@ def DownloadCommand( playlist_path = None playlist_tracks: dict[str, Track] = {} + futures = {} + while True: playlist_items = api.getPlaylistItems(playlist.uuid, offset=offset) @@ -453,11 +456,9 @@ def DownloadCommand( playlist_index=item.item.index // 100000, ) - track_path_future = submitItem(item.item, filename) - - if track_path_future: - track_path = track_path_future.result() - playlist_tracks[track_path] = item.item + future = submitItem(item.item, filename) + if future: + futures[future] = item.item playlist_path = Path(filename).parent @@ -469,6 +470,10 @@ def DownloadCommand( offset += playlist_items.limit + for future in as_completed(futures): + track_path = future.result() + playlist_tracks[track_path] = futures[future] + path = Path(PATH) if PATH else ctx.obj.config.download.path if playlist_path and SAVE_M3U: