Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 104 lines (72 sloc) 2.885 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
""" Output rTorrent - Feeds selected entries into rTorrent """
import logging
from flexget.plugin import *
from urlparse import uses_netloc


__pychecker__ = 'unusednames=parser'

log = logging.getLogger('rtorrent')

class OutputRtorrent:

    def validator(self):
from flexget import validator
        root = validator.factory()
        return root

    def get_config(self, feed):
        config = feed.config.get('rtorrent', {})
        if isinstance(config, bool)
            config = {'enabled': config}

        return config

    def on_feed_download(self, feed):
        if config['enabled']:
            if not 'download' in feed.config:
                download = get_plugin_by_name('download')
                download.instance.on_feed_download(feed)

    def on_feed_output(self, feed):
        if not feed.accepted or not config['enabled']:
            return

    def feed_exit(self, feed):
pass


    def open_socket(self, path):
        """ Open a socket to the rTorrent XMLRPC interface """

proto = path.split("://")[0]
path = path.split("://")[1]

        switch proto:
            case "file":

            case "http":
                raise PluginError("http xmlrpc interface not supported")
            else:
                raise PluginError("Unsupported path protocol: %s" % proto)


class ScgiTransport(xmlrpclib.Transport):

    """ SGI Transport

Used to communicate xmlrpc over raw SCGI services, like rTorrent """

    def __init__(self, use_datetime=0):
        self.headers=[]

    def _make_headers(self, headers):
        """ Generate the request headers """
        return '\x00'.join(['%s\x00%s'%t for t in headers])+'\x00'

    def _add_header(self, header, data):
        if not self.headers:
            self.headers = [('SCGI', '1'),]
        self.headers.append((header, data))

    def _gen_netstring(self, data):
        return '%d:%s,' % (len(data), data)

    def _gen_request(self, data):
        """ Generates the full SCGI request """
        headers = [("CONTENT_LENGTH", len(data))]
        headers += [('SCGI', '1')]
        rheaders = self._make_headers( headers.extend(self.headers) )

        return self._gen_netstring(rheaders) + data

    def make_connection(self, url):
        uses_netloc.append('unix')
        scheme, netloc, path, query, frag = urlparse.urlsplit(url)
        host, port = urllib.splitport(netloc)

        if netloc:
            addrinfo = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)
                       
            sock = socket.socket(*addrinfo[0][:3])
            sock.connect(addrinfo[0][4])
        else:
            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            sock.connect(path)

        return sock

    def send_request(self, connection, handler, request_body):

        pass

    def send_host(self, connection, host):
        pass
Something went wrong with that request. Please try again.