added eta

This commit is contained in:
iou1name 2019-02-19 13:18:05 -05:00
parent 450a8d6a06
commit 2536a4825a
4 changed files with 35 additions and 3 deletions

View File

@ -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

View File

@ -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%;
}

View File

@ -17,6 +17,7 @@ function get_active_torrents() {
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="eta">' + torrents[i].eta_str + '</td>';
html_str += '<td class="uprate">' + torrents[i].uprate_str + '</td>';
html_str += '<td class="tracker">' + torrents[i].tracker + '</td>';
html_str += '</tr>';

View File

@ -18,6 +18,7 @@
<th class="state">State</th>
<th class="downrate">DL</th>
<th class="downPercent">%</th>
<th class="eta">ETA</th>
<th class="uprate">UL</th>
<th class="tracker">Tracker</th>
</tr>
@ -30,12 +31,14 @@
<td class="state">{{ torrent.state }}</td>
<td class="downrate">{{ torrent.downrate_str }}</td>
<td class="downPercent">{{ torrent.down_percent }}</td>
<td class="eta">{{ torrent.eta_str }}</td>
<td class="uprate">{{ torrent.uprate_str }}</td>
<td class="tracker">{{ torrent.tracker }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<br>
<table id="tracker_stats">
{% for tracker, count in tracker_stats.items() %}
<tr>