Ejemplo n.º 1
0
    def connect(self, reconnect=False):
        """ Connect to the delugeRPC, re-use connection when already available
        :param reconnect: force reconnect
        :return: DelugeRPC instance
        """

        # Load host from config and split out port.
        host = clean_host(self.conf('host'), protocol=False).split(':')

        # Force host assignment
        if len(host) == 1:
            host.append(80)

        if not is_int(host[1]):
            log.error(
                'Config properties are not filled in correctly, port is missing.'
            )
            return False

        if not self.drpc or reconnect:
            self.drpc = DelugeRPC(host[0],
                                  port=host[1],
                                  username=self.conf('username'),
                                  password=self.conf('password'))

        return self.drpc
Ejemplo n.º 2
0
    def connect(self):
        # Load host from config and split out port.
        host = clean_host(self.conf('host'), protocol=False).split(':')

        if not is_int(host[1]):
            log.error('Config properties are not filled in correctly, port is missing.')
            return False

        # This is where v4 and v5 begin to differ
        if(self.conf('version') == 'v4'):
            if not self.conf('api_key'):
                log.error('Config properties are not filled in correctly, API key is missing.')
                return False

            url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/jsonrpc'
            client = JsonRpcClient(url, 'Token ' + self.conf('api_key'))
            self.hadouken_api = HadoukenAPIv4(client)

            return True
        else:
            auth_type = self.conf('auth_type')
            header = None

            if auth_type == 'api_key':
                header = 'Token ' + self.conf('api_key')
            elif auth_type == 'user_pass':
                header = 'Basic ' + b64encode(self.conf('auth_user') + ':' + self.conf('auth_pass'))

            url = 'http://' + str(host[0]) + ':' + str(host[1]) + '/api'
            client = JsonRpcClient(url, header)
            self.hadouken_api = HadoukenAPIv5(client)

            return True

        return False
Ejemplo n.º 3
0
    def cleanValue(self, value):
        if (is_int(value)):
            return int(value)

        if str(value).lower() in self.bool:
            return self.bool.get(str(value).lower())

        return value.strip()
Ejemplo n.º 4
0
    def cleanValue(self, value):
        if is_int(value):
            return int(value)

        if str(value).lower() in self.bool:
            return self.bool.get(str(value).lower())

        return value.strip()
Ejemplo n.º 5
0
    def download(self, data=None, media=None, filedata=None):
        """
        Send a torrent/nzb file to the downloader

        :param data: dict returned from provider
            Contains the release information
        :param media: media dict with information
            Used for creating the filename when possible
        :param filedata: downloaded torrent/nzb filedata
            The file gets downloaded in the searcher and send to this function
            This is done to have fail checking before using the downloader, so the downloader
            doesn't need to worry about that
        :return: boolean
            One fail returns false, but the downloader should log his own errors
        """

        if not media: media = {}
        if not data: data = {}

        response = False
        log.info('Sending "%s" (%s) to Synology.',
                 (data['name'], data['protocol']))

        # Load host from config and split out port.
        host = clean_host(self.conf('host'), protocol=False).split(':')
        if not is_int(host[1]):
            log.error(
                'Config properties are not filled in correctly, port is missing.'
            )
            return False

        try:
            # Send request to Synology
            srpc = SynologyRPC(host[0], host[1], self.conf('username'),
                               self.conf('password'), self.conf('destination'))
            if data['protocol'] == 'torrent_magnet':
                log.info('Adding torrent URL %s', data['url'])
                response = srpc.create_task(url=data['url'])
            elif data['protocol'] in ['nzb', 'torrent']:
                log.info('Adding %s' % data['protocol'])
                if not filedata:
                    log.error('No %s data found', data['protocol'])
                else:
                    filename = data['name'] + '.' + data['protocol']
                    response = srpc.create_task(filename=filename,
                                                filedata=filedata)
        except:
            log.error('Exception while adding torrent: %s',
                      traceback.format_exc())
        finally:
            return self.download_return_id('') if response else False
Ejemplo n.º 6
0
    def connect(self):
        # Load host from config and split out port.
        host = clean_host(self.conf('host'), protocol=False).split(':')
        if not is_int(host[1]):
            log.error(
                'Config properties are not filled in correctly, port is missing.'
            )
            return False

        self.utorrent_api = uTorrentAPI(host[0],
                                        port=host[1],
                                        username=self.conf('username'),
                                        password=self.conf('password'))

        return self.utorrent_api
Ejemplo n.º 7
0
    def connect(self):
        # Load host from config and split out port.
        host = clean_host(self.conf('host')).rstrip('/').rsplit(':', 1)
        if not is_int(host[1]):
            log.error(
                'Config properties are not filled in correctly, port is missing.'
            )
            return False

        self.trpc = TransmissionRPC(host[0],
                                    port=host[1],
                                    rpc_url=self.conf('rpc_url').strip('/ '),
                                    username=self.conf('username'),
                                    password=self.conf('password'))
        return self.trpc