Aberrant/rtorrent.py

42 lines
909 B
Python
Raw Normal View History

2019-01-16 12:49:42 -05:00
#!/usr/bin/env python3
"""
This module handles the interface with rTorrent via XMLRPC.
"""
import xmlrpc.client
2019-02-13 10:05:11 -05:00
_s = xmlrpc.client.ServerProxy("http://localhost:8000/RPC0")
torrents = []
class Torrent:
def __init__(self, raw):
self.hash = raw[0]
self.name = raw[1]
self.active = raw[2]
self.complete = raw[3]
if not self.active:
self.state = "inactive"
elif self.complete:
self.state = "seeding"
else:
self.state = "leeching"
self.downrate = raw[4]
self.uprate = raw[5]
2019-01-16 12:49:42 -05:00
def get_all():
2019-02-13 10:05:11 -05:00
"""Gets all torrent information and stores it."""
global torrents
res = _s.d.multicall2('', 'main',
'd.hash=',
'd.name=',
'd.is_active=',
'd.complete=',
'd.down.rate=',
'd.up.rate=',
)
torrents = [Torrent(raw) for raw in res]
2019-01-16 12:49:42 -05:00
def get_active():
2019-02-13 10:05:11 -05:00
"""Returns all actively seeding or leeching torrents."""
active = [t for t in torrents if t.downrate or t.uprate]
return active