diff --git a/rtorrent.py b/rtorrent.py index e90e331..d9f96f2 100644 --- a/rtorrent.py +++ b/rtorrent.py @@ -27,12 +27,17 @@ class Torrent: self.state = "leeching" self.downrate = raw[4] - self.downrate_str = speedrate(self.downrate) + self.downrate_str = size_units(self.downrate) + '/s' self.uprate = raw[5] - self.uprate_str = speedrate(self.uprate) + self.uprate_str = size_units(self.uprate) + '/s' self.tracker = get_tracker(raw[6]) + self.down_total = raw[7] + 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) + class Watch(threading.Thread): """A thread class that continously queries the rTorrent instances.""" @@ -56,15 +61,18 @@ class Watch(threading.Thread): self._stop_event.wait(2) -def speedrate(rate): - """Helper to assign appropriate prefixes to speed rates.""" - unit = "B/s" +def size_units(rate): + """Helper to assign appropriate prefixes to numbers.""" + unit = "B" if rate > 1024: rate /= 1024 - unit = "KiB/s" + unit = "KiB" if rate > 1024: rate /= 1024 - unit = "MiB/s" + unit = "MiB" + if rate > 1024: + rate /= 1024 + unit = "GiB" rate = round(rate, 1) return str(rate) + unit @@ -83,13 +91,6 @@ def all_torrents(): res += item return res -def open_proxy(): - """Opens connections to all of the rtorrent instances.""" - global sp - for n in range(NUM_INST): - s = xmlrpc.client.ServerProxy(f"http://localhost:8000/RPC{n}") - sp.append(s) - def get_all(n): """Gets all torrent information from a instance and returns it.""" res = sp[n].d.multicall2('', 'main', @@ -100,13 +101,18 @@ def get_all(n): 'd.down.rate=', 'd.up.rate=', 'd.directory=', + 'd.completed_bytes=', + 'd.size_bytes=', ) return [Torrent(raw) for raw in res] def init(): """Initializes the rTorrent interface.""" global WATCH_HANDLE - open_proxy() + global sp + for n in range(NUM_INST): + s = xmlrpc.client.ServerProxy(f"http://localhost:8000/RPC{n}") + sp.append(s) WATCH_HANDLE = Watch() WATCH_HANDLE.start() diff --git a/static/aberrant.css b/static/aberrant.css index 90e95e5..e93deda 100644 --- a/static/aberrant.css +++ b/static/aberrant.css @@ -18,7 +18,7 @@ tr { padding-left: 1em; } -.state, .downrate, .uprate, .tracker { +.totalSize, .state, .downrate, .downPercent, .uprate, .tracker { text-align: center; width: 10%; } diff --git a/static/aberrant.js b/static/aberrant.js index 832dacb..8cf359b 100644 --- a/static/aberrant.js +++ b/static/aberrant.js @@ -11,7 +11,15 @@ function get_active_torrents() { torrents = JSON.parse(httpRequest.responseText); let html_str = ''; for (let i = 0; i < torrents.length; i++) { - html_str += '