Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Date Huang <tjjh89017@hotmail.com>
  • Loading branch information
tjjh89017 committed Mar 29, 2024
1 parent 1dac198 commit ed75279
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ std::map<std::string, torrent_status> ezio::get_torrent_status(std::vector<std::
// do some filter for below
}

auto now = std::chrono::high_resolution_clock::now();

std::vector<lt::torrent_handle> torrents = session_.get_torrents();
for (lt::torrent_handle const &h : torrents) {
std::stringstream ss;
Expand Down Expand Up @@ -108,6 +110,9 @@ std::map<std::string, torrent_status> ezio::get_torrent_status(std::vector<std::
status.is_paused = (t_stat.flags & libtorrent::torrent_flags::paused) != 0;
status.save_path = t_stat.save_path;

status.last_upload = std::chrono::duration_cast<std::chrono::seconds>(now - t_stat.last_upload).count();
status.last_download = std::chrono::duration_cast<std::chrono::seconds>(now - t_stat.last_download).count();

result.emplace(hash, status);
}

Expand Down
2 changes: 2 additions & 0 deletions daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct torrent_status {
int64_t total_payload_upload;
bool is_paused;
std::string save_path;
int64_t last_upload;
int64_t last_download;
};

class ezio : boost::noncopyable
Expand Down
4 changes: 4 additions & 0 deletions ezio.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ message Torrent {
bool is_paused = 17;
// save_path
string save_path = 18;
// last_upload
int64 last_upload = 19;
// last_download
int64 last_download = 20;
}

message AddRequest {
Expand Down
3 changes: 3 additions & 0 deletions service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Status gRPCService::GetTorrentStatus(ServerContext *context,
t.set_total_payload_upload(t_stat.total_payload_upload);
t.set_is_paused(t_stat.is_paused);
t.set_save_path(t_stat.save_path);
t.set_last_upload(t_stat.last_upload);
t.set_last_download(t_stat.last_download);

response->mutable_torrents()->insert({hash, t});
}

Expand Down
6 changes: 5 additions & 1 deletion utils/ezio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def update_graph(self, force_update=False):
self.torrents[h]['total_payload_upload'].set_text("total_payload_upload: {}".format(torrent.total_payload_upload))
self.torrents[h]['is_paused'].set_text("paused: {}".format(str(torrent.is_paused)))
self.torrents[h]['save_path'].set_text("save_path: {}".format(torrent.save_path))
self.torrents[h]['last_upload'].set_text("last_upload: {}".format(torrent.last_upload))

# avg progress
l = len(torrents)
Expand Down Expand Up @@ -192,6 +193,7 @@ def graph_controls(self):
torrent_total_payload_upload = urwid.Text('', align="right")
torrent_is_paused = urwid.Text('', align="right")
torrent_save_path = urwid.Text('', align="right")
torrent_last_upload = urwid.Text('', align="right")
self.torrents[h] = {
'name': torrent_name,
'progress': torrent_progress,
Expand All @@ -210,6 +212,7 @@ def graph_controls(self):
'total_payload_upload': torrent_total_payload_upload,
'is_paused': torrent_is_paused,
'save_path': torrent_save_path,
'last_upload': torrent_last_upload,
}

l.append(torrent_name)
Expand All @@ -228,6 +231,7 @@ def graph_controls(self):
l.append(torrent_total_payload_download)
l.append(torrent_total_payload_upload)
l.append(torrent_is_paused)
l.append(torrent_last_upload)
l.append(urwid.Divider('-'))

w = urwid.ListBox(urwid.SimpleListWalker(l))
Expand Down Expand Up @@ -286,7 +290,7 @@ def detect_all_finished(self, loop=None, user_data=None):
if not t_stat.is_finished:
continue

if t_stat.total_payload_upload > 3 * t_stat.total_done or t_stat.seeding_time > 60:
if t_stat.total_payload_upload > 3 * t_stat.total_done or t_stat.last_upload > 60:
# stop torrent
request = ezio_pb2.PauseTorrentRequest()
request.hash = info_hash
Expand Down

0 comments on commit ed75279

Please sign in to comment.