Skip to content

Commit 56aff8f

Browse files
committed
👷 Optimized CLI performance.
1 parent ff96847 commit 56aff8f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

tidal_dl_ng/cli.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
6262
SpinnerColumn(),
6363
BarColumn(),
6464
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
65+
refresh_per_second=20,
66+
auto_refresh=True,
67+
expand=True,
68+
transient=False, # Prevent progress from disappearing
6569
)
6670
fn_logger = LoggerWrapped(progress.print)
6771
dl = Download(
@@ -78,21 +82,21 @@ def _download(ctx: typer.Context, urls: list[str], try_login: bool = True) -> bo
7882

7983
urls_pos_last = len(urls) - 1
8084

81-
for item in urls:
82-
media_type: MediaType | bool = False
85+
# Use a single Live display for both progress and table
86+
with Live(progress_table, refresh_per_second=20):
87+
for item in urls:
88+
media_type: MediaType | bool = False
8389

84-
# Extract media name and id from link.
85-
if "http" in item:
86-
media_type = get_tidal_media_type(item)
87-
item_id = get_tidal_media_id(item)
88-
file_template = get_format_template(media_type, settings)
89-
else:
90-
print(f"It seems like that you have supplied an invalid URL: {item}")
90+
# Extract media name and id from link.
91+
if "http" in item:
92+
media_type = get_tidal_media_type(item)
93+
item_id = get_tidal_media_id(item)
94+
file_template = get_format_template(media_type, settings)
95+
else:
96+
print(f"It seems like that you have supplied an invalid URL: {item}")
9197

92-
continue
98+
continue
9399

94-
# Create Live display for Progress.
95-
with Live(progress_table, refresh_per_second=10):
96100
# Download media.
97101
if media_type in [MediaType.TRACK, MediaType.VIDEO]:
98102
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
119123
download_delay=settings.data.download_delay,
120124
)
121125

122-
# Stop Progress display.
126+
# Clear and stop progress display
127+
progress.refresh()
123128
progress.stop()
129+
print("\nDownload completed!")
124130

125131
return True
126132

0 commit comments

Comments
 (0)