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 += '