Beispiel #1
0
def fetch_global_info():
    """
    Fetch global stuff (always displayed):
        -   Down/Up Rate.
        -   IP (perhaps move to static global)
    """
    res = {}
    for target in targets:
        rtorrent = RTorrent(target)
        try:
            r = rtorrent.query().get_upload_rate().get_download_rate()\
                .get_upload_throttle().get_download_throttle().get_ip()\
                .get_hostname().get_memory_usage().get_max_memory_usage()\
                .get_libtorrent_version().get_view_list()

            h = hash(r)

            res[target['name']] = cache.get(h)
            if res[target['name']]:
                continue

            res[target['name']] = r.first()

            cache.set(h, res[target['name']], timeout=60)

        except InvalidConnectionException, e:
            print 'InvalidConnectionException:', e
            # Do we want to return or just not get data for this target?
            # I'd say return for now.
            return {}
Beispiel #2
0
def handle_rtorrent_torrent(k, m, target):
    if 'attributes' not in k:
        return None

    attributes = k['attributes']

    try:
        if m == 'rtorrent':
            a = RTorrent(target).query()
        else:
            if 'hash' not in k:
                return None

            _hash = k['hash']

            a = Torrent(target, _hash).query()

        for method, args in attributes:
            getattr(a, method)(*args)

        h = hash(a)
        r = cache.get(h)
        if r is None:
            r = a.first()
            cache.set(h, r, timeout=CACHE_TIMEOUT)

        return r
    except (InvalidTorrentException, InvalidTorrentCommandException), e:
        print e
        return None
Beispiel #3
0
def handle_rtorrent_torrent(k, m, target):
    if 'attributes' not in k:
        return None

    attributes = k['attributes']

    try:
        if m == 'rtorrent':
            a = RTorrent(target).query()
        else:
            if 'hash' not in k:
                return None

            _hash = k['hash']

            a = Torrent(target, _hash).query()

        for method, args in attributes:
            getattr(a, method)(*args)

        h = hash(a)
        r = cache.get(h)
        if r is None:
            r = a.first()
            cache.set(h, r, timeout=CACHE_TIMEOUT)

        return r
    except (InvalidTorrentException, InvalidTorrentCommandException), e:
        print e
        return None
Beispiel #4
0
    def rtorrent_func(*args, **key_args):
        """
        require_rtorrent internal torrent argument wrapper
        """

        # Setup torrent object.
        r = RTorrent(key_args['target'])
        key_args['rtorrent'] = r

        return func(*args, **key_args)
Beispiel #5
0
def fetch_global_info():
    """
    Fetch global stuff (always displayed):
        -   Down/Up Rate.
        -   IP (perhaps move to static global)
    """
    res = {}
    for target in targets:
        rtorrent = RTorrent(target)
        try:
            r = rtorrent.query().get_upload_rate().get_download_rate()\
                .get_upload_throttle().get_download_throttle().get_ip()\
                .get_hostname().get_memory_usage().get_max_memory_usage()\
                .get_libtorrent_version().get_view_list()
            res[target['name']] = r.first()
        except InvalidConnectionException, e:
            print 'InvalidConnectionException:', e
            # Do we want to return or just not get data for this target?
            # I'd say return for now.
            return {}
Beispiel #6
0
def add_torrent_page(target):
    if request.method == 'POST':
        if 'torrent_file' in request.files:

            torrent_raw = request.files['torrent_file'].read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'torrent_url' in request.form:

            torrent_url = request.form['torrent_url']

            response = urllib2.urlopen(torrent_url)
            torrent_raw = response.read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'magnet' in request.form:
            magnet_link = request.form['magnet']

            torrent = 'd10:magnet-uri' + str(len(magnet_link)) + ':' + magnet_link + 'e'

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw(torrent)

        flash('Succesfully added torrent' if return_code == 0 else 'Failed to add torrent')

    rtorrent_data = fetch_global_info()

    return pyro_render_template('torrent_add.html',
            rtorrent_data=rtorrent_data, target=target['name'])
Beispiel #7
0
def fetch_global_info():
    """
    Fetch global stuff (always displayed):
        -   Down/Up Rate.
        -   IP (perhaps move to static global)
    """
    res = {}
    for target in targets:
        rtorrent = RTorrent(target)
        try:
            r = (
                rtorrent.query()
                .get_upload_rate()
                .get_download_rate()
                .get_upload_throttle()
                .get_download_throttle()
                .get_ip()
                .get_hostname()
                .get_memory_usage()
                .get_max_memory_usage()
                .get_libtorrent_version()
                .get_view_list()
            )

            h = hash(r)

            res[target["name"]] = cache.get(h)
            if res[target["name"]]:
                continue

            res[target["name"]] = r.first()

            cache.set(h, res[target["name"]], timeout=60)

        except InvalidConnectionException, e:
            print "InvalidConnectionException:", e
            # Do we want to return or just not get data for this target?
            # I'd say return for now.
            return {}
Beispiel #8
0
def handle_rtorrent_torrent(k, m, target):
    if 'attributes' not in k:
        return None

    attributes = k['attributes']

    try:
        if m == 'rtorrent':
            a = RTorrent(target).query()
        else:
            if 'hash' not in k:
                return None

            _hash = k['hash']

            a = Torrent(target, _hash).query()

        for method, args in attributes:
            getattr(a, method)(args)

        return a.first()
    except (InvalidTorrentException, InvalidTorrentCommandException):
        return None
Beispiel #9
0
def add_torrent_page(target):
    if request.method == 'POST':
        if 'torrent_file' in request.files:

            torrent_raw = request.files['torrent_file'].read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'torrent_url' in request.form:

            torrent_url = request.form['torrent_url']

            response = urllib2.urlopen(torrent_url)
            torrent_raw = response.read()

            torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin)
        elif 'magnet' in request.form:
            magnet_link = request.form['magnet']

            torrent = 'd10:magnet-uri' + str(
                len(magnet_link)) + ':' + magnet_link + 'e'

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw(torrent)

        flash('Succesfully added torrent' if return_code ==
              0 else 'Failed to add torrent')

    rtorrent_data = fetch_global_info()

    return pyro_render_template('torrent_add.html',
                                rtorrent_data=rtorrent_data,
                                target=target['name'])
Beispiel #10
0
from lib.torrentrequester import TorrentRequester
from lib.peerrequester import PeerRequester

from config import rtorrent_config
from lib.config_parser import parse_config_part, RTorrentConfigException

targets = []
for x in rtorrent_config:
    try:
        info = parse_config_part(rtorrent_config[x], x)
    except RTorrentConfigException, e:
        print 'Invalid config: ', e
        sys.exit(1)

    targets.append(info)

if len(x) == 0:
    print 'No targets'
    sys.exit(1)

r = RTorrent(targets[0])

print '''Welcome to the pyroTorrent CLI interface.
We have created a RTorrent() object called 'r'.

Use the help() commands to find out how to use the client interface;
help(RTorrent), help(Torrent) might be helpful'''

print 'RTorrent object using target: ', targets[0]
Beispiel #11
0
    # Check for POST vars
    if str(env['REQUEST_METHOD']) == 'POST':
        data = read_post_data(env)

        if 'torrent_url' in data:
            print "It's a URL!"
            torrent_url = data['torrent_url'].value
            if torrent_url:
                print "Loading URL:", torrent_url
                torrent_url = urllib.unquote_plus(torrent_url)
                response = urllib2.urlopen(torrent_url)
                torrent_raw = response.read()

                torrent_raw_bin = xmlrpclib.Binary(torrent_raw)

                rtorrent = RTorrent(target)
                return_code = rtorrent.add_torrent_raw(torrent_raw_bin)
        elif 'torrent_file' in data:
            if not data['torrent_file'].file:
                return "Error: Form field 'torrent_file' not a file!"

            print "Loading file:", data['torrent_file'].filename
            torrent_raw_bin = xmlrpclib.Binary(data['torrent_file'].value)

            rtorrent = RTorrent(target)
            return_code = rtorrent.add_torrent_raw(torrent_raw_bin)
        else:
            return str("Error: Invalid POST data")

    rtorrent_data = fetch_global_info()
Beispiel #12
0
from model.rtorrent import RTorrent
import socket
import sys

from config import rtorrent_config
from lib.config_parser import parse_config_part, RTorrentConfigException

targets = []
for x in rtorrent_config:
    try:
        info = parse_config_part(rtorrent_config[x], x)
    except RTorrentConfigException, e:
        print 'Invalid config: ', e
        sys.exit(1)

    targets.append(info)

for x in targets:
    r = RTorrent(x)

    try:
        print '[', x['name'], '] libTorrent version:', r.get_libtorrent_version()
    except socket.error, e:
        print 'Failed to connect to libTorrent:', str(e)