From 2536a4825a9a49fff9e82876c6b0df136fbffd77 Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 19 Feb 2019 13:18:05 -0500 Subject: [PATCH] added eta --- rtorrent.py | 28 ++++++++++++++++++++++++++++ static/aberrant.css | 6 +++--- static/aberrant.js | 1 + templates/index.html | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/rtorrent.py b/rtorrent.py index d9f96f2..f30fda0 100644 --- a/rtorrent.py +++ b/rtorrent.py @@ -37,6 +37,16 @@ class Torrent: self.total_size = raw[8] self.total_size_str = size_units(self.total_size) self.down_percent = round((self.down_total / self.total_size) * 100, 2) + if self.state == "leeching": + if self.downrate: + self.eta = (self.total_size - self.down_total) / self.downrate + self.eta_str = time_units(self.eta) + else: + self.eta = float("inf") + self.eta_str = "∞" + else: + self.eta = 0 + self.eta_str = "" class Watch(threading.Thread): @@ -76,6 +86,24 @@ def size_units(rate): rate = round(rate, 1) return str(rate) + unit +def time_units(seconds): + """Helper to convert seconds into more useful units.""" + if seconds > (24*60*60): + days = seconds // (24*60*60) + hours = (seconds % (24*60*60)) // (60*60) + eta = f"{days}d{hours}h" + elif seconds > (60*60): + hours = seconds // (60*60) + minutes = (seconds % (60*60)) // 60 + eta = f"{hours}h{minutes}m" + elif seconds > 60: + minutes = seconds // 60 + seconds = seconds % 60 + eta = f"{minutes}m{seconds}s" + else: + eta = f"{seconds}s" + return eta + def get_tracker(path): """ At present I don't have an efficient way to get the tracker url diff --git a/static/aberrant.css b/static/aberrant.css index e93deda..3c1ddf3 100644 --- a/static/aberrant.css +++ b/static/aberrant.css @@ -14,11 +14,11 @@ tr { border: 1px solid #ccc; } -#name { - padding-left: 1em; +.name { + padding-left: 0.5em; } -.totalSize, .state, .downrate, .downPercent, .uprate, .tracker { +.totalSize, .state, .downrate, .downPercent, .eta, .uprate, .tracker { text-align: center; width: 10%; } diff --git a/static/aberrant.js b/static/aberrant.js index 8cf359b..8c3e4fa 100644 --- a/static/aberrant.js +++ b/static/aberrant.js @@ -17,6 +17,7 @@ function get_active_torrents() { html_str += '' + torrents[i].state + ''; html_str += '' + torrents[i].downrate_str + ''; html_str += '' + torrents[i].down_percent + ''; + html_str += '' + torrents[i].eta_str + ''; html_str += '' + torrents[i].uprate_str + ''; html_str += '' + torrents[i].tracker + ''; html_str += ''; diff --git a/templates/index.html b/templates/index.html index 6f70d69..4401804 100644 --- a/templates/index.html +++ b/templates/index.html @@ -18,6 +18,7 @@ State DL % + ETA UL Tracker @@ -30,12 +31,14 @@ {{ torrent.state }} {{ torrent.downrate_str }} {{ torrent.down_percent }} + {{ torrent.eta_str }} {{ torrent.uprate_str }} {{ torrent.tracker }} {% endfor %} +
{% for tracker, count in tracker_stats.items() %}