mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Better computation of speed
Distinct VODs took from disk and freshly downloaded
This commit is contained in:
parent
caabe3138c
commit
dd1f4e0d26
@ -1,6 +1,11 @@
|
|||||||
Twitch Downloader change log
|
Twitch Downloader change log
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
1.17.0 (TBA)
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Fix speed calculation when resuming download (#75, thanks CroquetteTheThe)
|
||||||
|
|
||||||
1.16.1 (2021-07-31)
|
1.16.1 (2021-07-31)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
@ -34,11 +34,13 @@ def _download(url, path):
|
|||||||
|
|
||||||
def download_file(url, path, retries=RETRY_COUNT):
|
def download_file(url, path, retries=RETRY_COUNT):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return os.path.getsize(path)
|
from_disk = True
|
||||||
|
return (os.path.getsize(path), from_disk)
|
||||||
|
|
||||||
|
from_disk = False
|
||||||
for _ in range(retries):
|
for _ in range(retries):
|
||||||
try:
|
try:
|
||||||
return _download(url, path)
|
return (_download(url, path), from_disk)
|
||||||
except RequestException:
|
except RequestException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -51,17 +53,26 @@ def _print_progress(futures):
|
|||||||
max_msg_size = 0
|
max_msg_size = 0
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
total_count = len(futures)
|
total_count = len(futures)
|
||||||
|
current_download_size = 0
|
||||||
|
current_downloaded_count = 0
|
||||||
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
size = future.result()
|
size, from_disk = future.result()
|
||||||
downloaded_count += 1
|
downloaded_count += 1
|
||||||
downloaded_size += size
|
downloaded_size += size
|
||||||
|
|
||||||
|
# If we find something on disk, we don't want to take it in account in
|
||||||
|
# the speed calculation
|
||||||
|
if not from_disk:
|
||||||
|
current_download_size += size
|
||||||
|
current_downloaded_count += 1
|
||||||
|
|
||||||
percentage = 100 * downloaded_count // total_count
|
percentage = 100 * downloaded_count // total_count
|
||||||
est_total_size = int(total_count * downloaded_size / downloaded_count)
|
est_total_size = int(total_count * downloaded_size / downloaded_count)
|
||||||
duration = (datetime.now() - start_time).seconds
|
duration = (datetime.now() - start_time).seconds
|
||||||
speed = downloaded_size // duration if duration else 0
|
speed = current_download_size // duration if duration else 0
|
||||||
remaining = (total_count - downloaded_count) * duration / downloaded_count
|
remaining = (total_count - downloaded_count) * duration / current_downloaded_count \
|
||||||
|
if current_downloaded_count else 0
|
||||||
|
|
||||||
msg = " ".join([
|
msg = " ".join([
|
||||||
"Downloaded VOD {}/{}".format(downloaded_count, total_count),
|
"Downloaded VOD {}/{}".format(downloaded_count, total_count),
|
||||||
@ -69,7 +80,7 @@ def _print_progress(futures):
|
|||||||
"<cyan>{}</cyan>".format(format_size(downloaded_size)),
|
"<cyan>{}</cyan>".format(format_size(downloaded_size)),
|
||||||
"of <cyan>~{}</cyan>".format(format_size(est_total_size)),
|
"of <cyan>~{}</cyan>".format(format_size(est_total_size)),
|
||||||
"at <cyan>{}/s</cyan>".format(format_size(speed)) if speed > 0 else "",
|
"at <cyan>{}/s</cyan>".format(format_size(speed)) if speed > 0 else "",
|
||||||
"remaining <cyan>~{}</cyan>".format(format_duration(remaining)) if speed > 0 else "",
|
"remaining <cyan>~{}</cyan>".format(format_duration(remaining)) if remaining > 0 else "",
|
||||||
])
|
])
|
||||||
|
|
||||||
max_msg_size = max(len(msg), max_msg_size)
|
max_msg_size = max(len(msg), max_msg_size)
|
||||||
|
Loading…
Reference in New Issue
Block a user