Last active 1486608811

A script that lists currently downloading torrents in Deluge. Uses deluge-client and hurry.filesize from pypi

deluge-downloading.py Raw
1#!/usr/bin/env python3
2def sec(s):
3 m,s = divmod(int(s), 60)
4 h,m = divmod(m,60)
5 return "%d:%02d:%02d" % (h,m,s)
6
7def convert(data):
8 if isinstance(data, bytes): return data.decode('ascii')
9 if isinstance(data, dict): return dict(map(convert, data.items()))
10 if isinstance(data, tuple): return map(convert, data)
11 return data
12
13from hurry.filesize import size
14from deluge_client import DelugeRPCClient
15client = DelugeRPCClient("127.0.0.1", 58846, "me", "you")
16client.connect()
17torrents = client.call("core.get_torrents_status", {"state": "Downloading"}, [])
18if not torrents:
19 print("Nothing going at the moment")
20else:
21 torrents = convert(torrents)
22 for torrent, data in torrents.items():
23 data["until"] = sec(data["eta"])
24 data["dlrate"] = size(data["download_payload_rate"])
25 print("{progress:.0f}% {until} {dlrate}/s: {name}".format(**data))