added torrent size and completion
This commit is contained in:
parent
b80d3b989a
commit
450a8d6a06
36
rtorrent.py
36
rtorrent.py
|
@ -27,12 +27,17 @@ class Torrent:
|
||||||
self.state = "leeching"
|
self.state = "leeching"
|
||||||
|
|
||||||
self.downrate = raw[4]
|
self.downrate = raw[4]
|
||||||
self.downrate_str = speedrate(self.downrate)
|
self.downrate_str = size_units(self.downrate) + '/s'
|
||||||
self.uprate = raw[5]
|
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.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):
|
class Watch(threading.Thread):
|
||||||
"""A thread class that continously queries the rTorrent instances."""
|
"""A thread class that continously queries the rTorrent instances."""
|
||||||
|
@ -56,15 +61,18 @@ class Watch(threading.Thread):
|
||||||
self._stop_event.wait(2)
|
self._stop_event.wait(2)
|
||||||
|
|
||||||
|
|
||||||
def speedrate(rate):
|
def size_units(rate):
|
||||||
"""Helper to assign appropriate prefixes to speed rates."""
|
"""Helper to assign appropriate prefixes to numbers."""
|
||||||
unit = "B/s"
|
unit = "B"
|
||||||
if rate > 1024:
|
if rate > 1024:
|
||||||
rate /= 1024
|
rate /= 1024
|
||||||
unit = "KiB/s"
|
unit = "KiB"
|
||||||
if rate > 1024:
|
if rate > 1024:
|
||||||
rate /= 1024
|
rate /= 1024
|
||||||
unit = "MiB/s"
|
unit = "MiB"
|
||||||
|
if rate > 1024:
|
||||||
|
rate /= 1024
|
||||||
|
unit = "GiB"
|
||||||
rate = round(rate, 1)
|
rate = round(rate, 1)
|
||||||
return str(rate) + unit
|
return str(rate) + unit
|
||||||
|
|
||||||
|
@ -83,13 +91,6 @@ def all_torrents():
|
||||||
res += item
|
res += item
|
||||||
return res
|
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):
|
def get_all(n):
|
||||||
"""Gets all torrent information from a instance and returns it."""
|
"""Gets all torrent information from a instance and returns it."""
|
||||||
res = sp[n].d.multicall2('', 'main',
|
res = sp[n].d.multicall2('', 'main',
|
||||||
|
@ -100,13 +101,18 @@ def get_all(n):
|
||||||
'd.down.rate=',
|
'd.down.rate=',
|
||||||
'd.up.rate=',
|
'd.up.rate=',
|
||||||
'd.directory=',
|
'd.directory=',
|
||||||
|
'd.completed_bytes=',
|
||||||
|
'd.size_bytes=',
|
||||||
)
|
)
|
||||||
return [Torrent(raw) for raw in res]
|
return [Torrent(raw) for raw in res]
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initializes the rTorrent interface."""
|
"""Initializes the rTorrent interface."""
|
||||||
global WATCH_HANDLE
|
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 = Watch()
|
||||||
WATCH_HANDLE.start()
|
WATCH_HANDLE.start()
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ tr {
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.state, .downrate, .uprate, .tracker {
|
.totalSize, .state, .downrate, .downPercent, .uprate, .tracker {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: 10%;
|
width: 10%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,15 @@ function get_active_torrents() {
|
||||||
torrents = JSON.parse(httpRequest.responseText);
|
torrents = JSON.parse(httpRequest.responseText);
|
||||||
let html_str = '';
|
let html_str = '';
|
||||||
for (let i = 0; i < torrents.length; i++) {
|
for (let i = 0; i < torrents.length; i++) {
|
||||||
html_str += '<tr><td class="name">' + torrents[i].name + '</td><td class="state">' + torrents[i].state + '</td><td class="downrate">' + torrents[i].downrate_str + '</td><td class="uprate">' + torrents[i].uprate_str + '</td><td class="tracker">' + torrents[i].tracker + "</td>";
|
html_str += '<tr>'
|
||||||
|
html_str += '<td class="name">' + torrents[i].name + '</td>';
|
||||||
|
html_str += '<td class="totalSize">' + torrents[i].total_size_str + '</td>';
|
||||||
|
html_str += '<td class="state">' + torrents[i].state + '</td>';
|
||||||
|
html_str += '<td class="downrate">' + torrents[i].downrate_str + '</td>';
|
||||||
|
html_str += '<td class="downPercent">' + torrents[i].down_percent + '</td>';
|
||||||
|
html_str += '<td class="uprate">' + torrents[i].uprate_str + '</td>';
|
||||||
|
html_str += '<td class="tracker">' + torrents[i].tracker + '</td>';
|
||||||
|
html_str += '</tr>';
|
||||||
}
|
}
|
||||||
document.getElementById('torrents').children[1].innerHTML = html_str;
|
document.getElementById('torrents').children[1].innerHTML = html_str;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,8 +14,10 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="name">Name</th>
|
<th class="name">Name</th>
|
||||||
|
<th class="sizeTotal">Size</th>
|
||||||
<th class="state">State</th>
|
<th class="state">State</th>
|
||||||
<th class="downrate">DL</th>
|
<th class="downrate">DL</th>
|
||||||
|
<th class="downPercent">%</th>
|
||||||
<th class="uprate">UL</th>
|
<th class="uprate">UL</th>
|
||||||
<th class="tracker">Tracker</th>
|
<th class="tracker">Tracker</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -24,8 +26,10 @@
|
||||||
{% for torrent in torrents %}
|
{% for torrent in torrents %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name">{{ torrent.name }}</td>
|
<td class="name">{{ torrent.name }}</td>
|
||||||
|
<td class="totalSize">{{ torrent.total_size_str }}</td>
|
||||||
<td class="state">{{ torrent.state }}</td>
|
<td class="state">{{ torrent.state }}</td>
|
||||||
<td class="downrate">{{ torrent.downrate_str }}</td>
|
<td class="downrate">{{ torrent.downrate_str }}</td>
|
||||||
|
<td class="downPercent">{{ torrent.down_percent }}</td>
|
||||||
<td class="uprate">{{ torrent.uprate_str }}</td>
|
<td class="uprate">{{ torrent.uprate_str }}</td>
|
||||||
<td class="tracker">{{ torrent.tracker }}</td>
|
<td class="tracker">{{ torrent.tracker }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user