Replace safe_gather with sequential_gather in downloader

This commit is contained in:
Rafael Moraes
2025-12-04 16:52:34 -03:00
parent fe6a6e308d
commit f3b7adaad3
2 changed files with 21 additions and 5 deletions
+5 -5
View File
@@ -6,7 +6,7 @@ from InquirerPy import inquirer
from InquirerPy.base.control import Choice
from ..interface import AppleMusicInterface
from ..utils import safe_gather
from ..utils import sequential_gather
from .constants import (
ALBUM_MEDIA_TYPE,
ARTIST_MEDIA_TYPE,
@@ -124,7 +124,7 @@ class AppleMusicDownloader:
for media_metadata in tracks_metadata
]
download_items = await safe_gather(*tasks)
download_items = await sequential_gather(*tasks)
return download_items
async def get_artist_download_items(
@@ -201,7 +201,7 @@ class AppleMusicDownloader:
)
for album_metadata in selected
]
album_responses = await safe_gather(*album_tasks)
album_responses = await sequential_gather(*album_tasks)
track_tasks = [
asyncio.create_task(
@@ -209,7 +209,7 @@ class AppleMusicDownloader:
)
for album_response in album_responses
]
track_results = await safe_gather(*track_tasks)
track_results = await sequential_gather(*track_tasks)
for track_result in track_results:
download_items.extend(track_result)
@@ -250,7 +250,7 @@ class AppleMusicDownloader:
)
for music_video_metadata in selected
]
download_items = await safe_gather(*music_video_tasks)
download_items = await sequential_gather(*music_video_tasks)
return download_items
+16
View File
@@ -69,3 +69,19 @@ async def safe_gather(
*(bounded_task(task) for task in tasks),
return_exceptions=True,
)
async def sequential_gather(
*tasks: typing.Awaitable[typing.Any],
interval: float = 0.5,
) -> list[typing.Any]:
results = []
for i, task in enumerate(tasks):
try:
result = await task
results.append(result)
except Exception as e:
results.append(e)
if interval > 0 and i < len(tasks) - 1:
await asyncio.sleep(interval)
return results