コード例 #1
0
ファイル: hadouken.py プロジェクト: michaelsexton/WhatPotato
    def connect(self):
        # Load host from config and split out port.
        host = cleanHost(self.conf('host'), protocol = False).split(':')

        if not isInt(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
コード例 #2
0
    def connect(self):
        # Load host from config and split out port.
        host = cleanHost(self.conf('host')).rstrip('/').rsplit(':', 1)
        if not isInt(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
コード例 #3
0
ファイル: utorrent.py プロジェクト: michaelsexton/WhatPotato
    def connect(self):
        # Load host from config and split out port.
        host = cleanHost(self.conf('host'), protocol = False).split(':')
        if not isInt(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
コード例 #4
0
ファイル: synology.py プロジェクト: michaelsexton/WhatPotato
    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 failed checking before using the downloader, so the downloader
            doesn't need to worry about that
        :return: boolean
            One faile returns false, but the downloaded should log his own errors
        """

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

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

        # Load host from config and split out port.
        host = cleanHost(self.conf('host'), protocol = False).split(':')
        if not isInt(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.downloadReturnId('') if response else False
コード例 #5
0
ファイル: deluge.py プロジェクト: michaelsexton/WhatPotato
    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 = cleanHost(self.conf('host'), protocol = False).split(':')

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

        if not isInt(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