👷 Optimized CLI performance.
This commit is contained in:
+9
-3
@@ -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,6 +82,8 @@ 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
|
||||||
|
|
||||||
|
# Use a single Live display for both progress and table
|
||||||
|
with Live(progress_table, refresh_per_second=20):
|
||||||
for item in urls:
|
for item in urls:
|
||||||
media_type: MediaType | bool = False
|
media_type: MediaType | bool = False
|
||||||
|
|
||||||
@@ -91,8 +97,6 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user