Aberrant/rtorrent.py
2019-02-13 10:20:55 -05:00

42 lines
909 B
Python

#!/usr/bin/env python3
"""
This module handles the interface with rTorrent via XMLRPC.
"""
import xmlrpc.client
_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]
def get_all():
"""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]
def get_active():
"""Returns all actively seeding or leeching torrents."""
active = [t for t in torrents if t.downrate or t.uprate]
return active