Updated rTorrent downloader to set ratio stop action, added new seeding methods and updated the rTorrent library
This commit is contained in:
@@ -24,6 +24,7 @@ from rtorrent.lib.torrentparser import TorrentParser
|
||||
from rtorrent.lib.xmlrpc.http import HTTPServerProxy
|
||||
from rtorrent.rpc import Method, BasicAuthTransport
|
||||
from rtorrent.torrent import Torrent
|
||||
from rtorrent.group import Group
|
||||
import os.path
|
||||
import rtorrent.rpc # @UnresolvedImport
|
||||
import time
|
||||
@@ -286,6 +287,26 @@ class RTorrent:
|
||||
|
||||
getattr(p, func_name)(finput)
|
||||
|
||||
def get_views(self):
|
||||
p = self._get_conn()
|
||||
return p.view_list()
|
||||
|
||||
def create_group(self, name, persistent=True, view=None):
|
||||
p = self._get_conn()
|
||||
|
||||
if persistent is True:
|
||||
p.group.insert_persistent_view('', name)
|
||||
else:
|
||||
assert view is not None, "view parameter required on non-persistent groups"
|
||||
p.group.insert('', name, view)
|
||||
|
||||
def get_group(self, name):
|
||||
assert name is not None, "group name required"
|
||||
|
||||
group = Group(self, name)
|
||||
group.update()
|
||||
return group
|
||||
|
||||
def set_dht_port(self, port):
|
||||
"""Set DHT port
|
||||
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
# Copyright (c) 2013 Dean Gardiner, <gardiner91@gmail.com>
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import rtorrent.rpc
|
||||
|
||||
Method = rtorrent.rpc.Method
|
||||
|
||||
|
||||
class Group:
|
||||
__name__ = 'Group'
|
||||
|
||||
def __init__(self, _rt_obj, name):
|
||||
self._rt_obj = _rt_obj
|
||||
self.name = name
|
||||
|
||||
self.methods = [
|
||||
# RETRIEVERS
|
||||
Method(Group, 'get_max', 'group.' + self.name + '.ratio.max', varname='max'),
|
||||
Method(Group, 'get_min', 'group.' + self.name + '.ratio.min', varname='min'),
|
||||
Method(Group, 'get_upload', 'group.' + self.name + '.ratio.upload', varname='upload'),
|
||||
|
||||
# MODIFIERS
|
||||
Method(Group, 'set_max', 'group.' + self.name + '.ratio.max.set', varname='max'),
|
||||
Method(Group, 'set_min', 'group.' + self.name + '.ratio.min.set', varname='min'),
|
||||
Method(Group, 'set_upload', 'group.' + self.name + '.ratio.upload.set', varname='upload')
|
||||
]
|
||||
|
||||
rtorrent.rpc._build_rpc_methods(self, self.methods)
|
||||
|
||||
# Setup multicall_add method
|
||||
caller = lambda multicall, method, *args: \
|
||||
multicall.add(method, *args)
|
||||
setattr(self, "multicall_add", caller)
|
||||
|
||||
def _get_prefix(self):
|
||||
return 'group.' + self.name + '.ratio.'
|
||||
|
||||
def update(self):
|
||||
multicall = rtorrent.rpc.Multicall(self)
|
||||
|
||||
retriever_methods = [m for m in self.methods
|
||||
if m.is_retriever() and m.is_available(self._rt_obj)]
|
||||
|
||||
for method in retriever_methods:
|
||||
multicall.add(method)
|
||||
|
||||
multicall.call()
|
||||
|
||||
def enable(self):
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
self.multicall_add(m, self._get_prefix() + 'enable')
|
||||
|
||||
return(m.call()[-1])
|
||||
|
||||
def disable(self):
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
self.multicall_add(m, self._get_prefix() + 'disable')
|
||||
|
||||
return(m.call()[-1])
|
||||
|
||||
def set_command(self, *methods):
|
||||
methods = [m + '=' for m in methods]
|
||||
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
self.multicall_add(
|
||||
m, 'system.method.set',
|
||||
self._get_prefix() + 'command',
|
||||
*methods
|
||||
)
|
||||
|
||||
return(m.call()[-1])
|
||||
@@ -19,6 +19,7 @@
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
from base64 import encodestring
|
||||
import httplib
|
||||
import inspect
|
||||
import string
|
||||
|
||||
import rtorrent
|
||||
@@ -223,7 +224,9 @@ class Multicall:
|
||||
result = process_result(method, r)
|
||||
results_processed.append(result)
|
||||
# assign result to class_obj
|
||||
setattr(self.class_obj, method.varname, result)
|
||||
exists = hasattr(self.class_obj, method.varname)
|
||||
if not exists or not inspect.ismethod(getattr(self.class_obj, method.varname)):
|
||||
setattr(self.class_obj, method.varname, result)
|
||||
|
||||
return(tuple(results_processed))
|
||||
|
||||
@@ -315,6 +318,11 @@ def process_result(method, result):
|
||||
|
||||
def _build_rpc_methods(class_, method_list):
|
||||
"""Build glorified aliases to raw RPC methods"""
|
||||
instance = None
|
||||
if not inspect.isclass(class_):
|
||||
instance = class_
|
||||
class_ = instance.__class__
|
||||
|
||||
for m in method_list:
|
||||
class_name = m.class_name
|
||||
if class_name != class_.__name__:
|
||||
@@ -337,6 +345,10 @@ def _build_rpc_methods(class_, method_list):
|
||||
call_method(self, method, self.rpc_id,
|
||||
bool_to_int(arg))
|
||||
|
||||
elif class_name == "Group":
|
||||
caller = lambda arg = None, method = m: \
|
||||
call_method(instance, method, bool_to_int(arg))
|
||||
|
||||
if m.docstring is None:
|
||||
m.docstring = ""
|
||||
|
||||
@@ -351,4 +363,7 @@ def _build_rpc_methods(class_, method_list):
|
||||
caller.__doc__ = docstring
|
||||
|
||||
for method_name in [m.method_name] + list(m.aliases):
|
||||
setattr(class_, method_name, caller)
|
||||
if instance is None:
|
||||
setattr(class_, method_name, caller)
|
||||
else:
|
||||
setattr(instance, method_name, caller)
|
||||
|
||||
@@ -190,6 +190,20 @@ class Torrent:
|
||||
self.active = m.call()[-1]
|
||||
return(self.active)
|
||||
|
||||
def pause(self):
|
||||
"""Pause the torrent"""
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
self.multicall_add(m, "d.pause")
|
||||
|
||||
return(m.call()[-1])
|
||||
|
||||
def resume(self):
|
||||
"""Resume the torrent"""
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
self.multicall_add(m, "d.resume")
|
||||
|
||||
return(m.call()[-1])
|
||||
|
||||
def close(self):
|
||||
"""Close the torrent and it's files"""
|
||||
m = rtorrent.rpc.Multicall(self)
|
||||
@@ -305,6 +319,14 @@ class Torrent:
|
||||
|
||||
return(m.call()[-1])
|
||||
|
||||
def set_visible(self, view, visible=True):
|
||||
p = self._rt_obj._get_conn()
|
||||
|
||||
if visible:
|
||||
return p.view.set_visible(self.info_hash, view)
|
||||
else:
|
||||
return p.view.set_not_visible(self.info_hash, view)
|
||||
|
||||
############################################################################
|
||||
# CUSTOM METHODS (Not part of the official rTorrent API)
|
||||
##########################################################################
|
||||
|
||||
Reference in New Issue
Block a user