👷 Optimized CLI performance.

This commit is contained in:
Robert Honz
2025-02-28 13:22:38 +01:00
parent ff96847e34
commit 56aff8fa19
+19 -13
View File
@@ -62,6 +62,10 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
SpinnerColumn(), SpinnerColumn(),
BarColumn(), BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
refresh_per_second=20,
auto_refresh=True,
expand=True,
transient=False, # Prevent progress from disappearing
) )
fn_logger = LoggerWrapped(progress.print) fn_logger = LoggerWrapped(progress.print)
dl = Download( dl = Download(
@@ -78,21 +82,21 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
urls_pos_last = len(urls) - 1 urls_pos_last = len(urls) - 1
for item in urls: # Use a single Live display for both progress and table
media_type: MediaType | bool = False with Live(progress_table, refresh_per_second=20):
for item in urls:
media_type: MediaType | bool = False
# Extract media name and id from link. # Extract media name and id from link.
if "http" in item: if "http" in item:
media_type = get_tidal_media_type(item) media_type = get_tidal_media_type(item)
item_id = get_tidal_media_id(item) item_id = get_tidal_media_id(item)
file_template = get_format_template(media_type, settings) file_template = get_format_template(media_type, settings)
else: else:
print(f"It seems like that you have supplied an invalid URL: {item}") print(f"It seems like that you have supplied an invalid URL: {item}")
continue continue
# Create Live display for Progress.
with Live(progress_table, refresh_per_second=10):
# Download media. # Download media.
if media_type in [MediaType.TRACK, MediaType.VIDEO]: if media_type in [MediaType.TRACK, MediaType.VIDEO]:
download_delay: bool = bool(settings.data.download_delay and urls.index(item) < urls_pos_last) download_delay: bool = bool(settings.data.download_delay and urls.index(item) < urls_pos_last)
@@ -119,8 +123,10 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
download_delay=settings.data.download_delay, download_delay=settings.data.download_delay,
) )
# Stop Progress display. # Clear and stop progress display
progress.refresh()
progress.stop() progress.stop()
print("\nDownload completed!")
return True return True