aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/FileDownloader.py
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-08-28 10:55:31 +0200
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2013-08-28 10:56:11 +0200
commitaf8bd6a82d140e5a776185707a9b21d5b8a9fe52 (patch)
tree9c6dc83aa9e3a4f03d2b4ac183ec8aeda945a14b /youtube_dl/FileDownloader.py
parent6d38616e67ff9859bce2a7bea2ec4a844530eb71 (diff)
Show the time taken to download in the same format as the ETA
Diffstat (limited to 'youtube_dl/FileDownloader.py')
-rw-r--r--youtube_dl/FileDownloader.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py
index 4f6a23835..7c5ac4bc2 100644
--- a/youtube_dl/FileDownloader.py
+++ b/youtube_dl/FileDownloader.py
@@ -64,6 +64,17 @@ class FileDownloader(object):
return '%.2f%s' % (converted, suffix)
@staticmethod
+ def format_seconds(seconds):
+ (mins, secs) = divmod(seconds, 60)
+ (hours, eta_mins) = divmod(mins, 60)
+ if hours > 99:
+ return '--:--:--'
+ if hours == 0:
+ return '%02d:%02d' % (mins, secs)
+ else:
+ return '%02d:%02d:%02d' % (hours, mins, secs)
+
+ @staticmethod
def calc_percent(byte_counter, data_len):
if data_len is None:
return '---.-%'
@@ -78,14 +89,7 @@ class FileDownloader(object):
return '--:--'
rate = float(current) / dif
eta = int((float(total) - float(current)) / rate)
- (eta_mins, eta_secs) = divmod(eta, 60)
- (eta_hours, eta_mins) = divmod(eta_mins, 60)
- if eta_hours > 99:
- return '--:--:--'
- if eta_hours == 0:
- return '%02d:%02d' % (eta_mins, eta_secs)
- else:
- return '%02d:%02d:%02d' % (eta_hours, eta_mins, eta_secs)
+ return FileDownloader.format_seconds(eta)
@staticmethod
def calc_speed(start, now, bytes):
@@ -240,8 +244,8 @@ class FileDownloader(object):
self.to_screen(u'[download] Download completed')
else:
clear_line = (u'\x1b[K' if sys.stderr.isatty() and os.name != 'nt' else u'')
- self.to_screen(u'\r%s[download] 100%% of %s in %ss' %
- (clear_line, data_len_str, int(tot_time)))
+ self.to_screen(u'\r%s[download] 100%% of %s in %s' %
+ (clear_line, data_len_str, self.format_seconds(tot_time)))
def _download_with_rtmpdump(self, filename, url, player_url, page_url, play_path, tc_url):
self.report_destination(filename)