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