コード例 #1
0
ファイル: client.py プロジェクト: eliovir/plugin-dlControl
 def __init__(self,
              address='localhost',
              port=DEFAULT_PORT,
              user=None,
              password=None,
              path=None,
              http_handler=None,
              timeout=None):
     rpcpath = '/transmission/rpc'
     if path:
         rpcpath = path
     if isinstance(timeout, (integer_types, float)):
         self._query_timeout = float(timeout)
     else:
         self._query_timeout = DEFAULT_TIMEOUT
     urlo = urlparse(address)
     if urlo.scheme == '':
         base_url = 'http://' + address + ':' + str(port)
         self.url = base_url + rpcpath
     else:
         if urlo.port:
             self.url = urlo.scheme + '://' + urlo.hostname + ':' + str(
                 urlo.port) + urlo.path
         else:
             self.url = urlo.scheme + '://' + urlo.hostname + urlo.path
         LOGGER.info('Using custom URL "' + self.url + '".')
         if urlo.username and urlo.password:
             user = urlo.username
             password = urlo.password
         elif urlo.username or urlo.password:
             LOGGER.warning(
                 'Either user or password missing, not using authentication.'
             )
     if http_handler is None:
         self.http_handler = DefaultHTTPHandler()
     else:
         if hasattr(http_handler, 'set_authentication') and hasattr(
                 http_handler, 'request'):
             self.http_handler = http_handler
         else:
             raise ValueError('Invalid HTTP handler.')
     if user and password:
         self.http_handler.set_authentication(self.url, user, password)
     elif user or password:
         LOGGER.warning(
             'Either user or password missing, not using authentication.')
     self._sequence = 0
     self.session = None
     self.session_id = 0
     self.server_version = None
     self.protocol_version = None
     self.get_session()
     self.torrent_get_arguments = get_arguments('torrent-get',
                                                self.rpc_version)
コード例 #2
0
ファイル: client.py プロジェクト: bemar/plugin-dlControl
 def __init__(self,
              address='localhost',
              port=DEFAULT_PORT,
              user=None,
              password=None,
              path=None,
              http_handler=None,
              timeout=None):
     rpcpath = '/transmission/rpc'
     if path:
         rpcpath = path
     if isinstance(timeout, (integer_types, float)):
         self._query_timeout = float(timeout)
     else:
         self._query_timeout = DEFAULT_TIMEOUT
     urlo = urlparse(address)
     if urlo.scheme == '':
         base_url = 'http://' + address + ':' + str(port)
         self.url = base_url + rpcpath
     else:
         if urlo.port:
             self.url = urlo.scheme + '://' + urlo.hostname + ':' + str(
                 urlo.port) + urlo.path
         else:
             self.url = urlo.scheme + '://' + urlo.hostname + urlo.path
         LOGGER.info('Using custom URL "' + self.url + '".')
         if urlo.username and urlo.password:
             user = urlo.username
             password = urlo.password
         elif urlo.username or urlo.password:
             LOGGER.warning(
                 'Either user or password missing, not using authentication.'
             )
     if http_handler is None:
         self.http_handler = DefaultHTTPHandler()
     else:
         if hasattr(http_handler, 'set_authentication') and hasattr(
                 http_handler, 'request'):
             self.http_handler = http_handler
         else:
             raise ValueError('Invalid HTTP handler.')
     if user and password:
         self.http_handler.set_authentication(self.url, user, password)
     elif user or password:
         LOGGER.warning(
             'Either user or password missing, not using authentication.')
     self._sequence = 0
     self.session = None
     self.session_id = 0
     self.server_version = None
     self.protocol_version = None
     self.get_session()
     self.torrent_get_arguments = get_arguments('torrent-get',
                                                self.rpc_version)
コード例 #3
0
ファイル: client.py プロジェクト: 0x022b/transmissionrpc-ng
 def __init__(
     self,
     address="localhost",
     port=DEFAULT_PORT,
     user=None,
     password=None,
     http_handler=None,
     timeout=None,
 ):
     if isinstance(timeout, (int, float)):
         self._query_timeout = float(timeout)
     else:
         self._query_timeout = DEFAULT_TIMEOUT
     urlo = urlparse(address)
     if urlo.scheme == "":
         base_url = "http://" + address + ":" + str(port)
         self.url = base_url + "/transmission/rpc"
     else:
         if urlo.port:
             self.url = (urlo.scheme + "://" + urlo.hostname + ":" +
                         str(urlo.port) + urlo.path)
         else:
             self.url = urlo.scheme + "://" + urlo.hostname + urlo.path
         LOGGER.info('Using custom URL "%s".', self.url)
         if urlo.username and urlo.password:
             user = urlo.username
             password = urlo.password
         elif urlo.username or urlo.password:
             LOGGER.warning(
                 "Either user or password missing, not using authentication."
             )
     if http_handler is None:
         self.http_handler = DefaultHTTPHandler()
     else:
         if hasattr(http_handler, "set_authentication") and hasattr(
                 http_handler, "request"):
             self.http_handler = http_handler
         else:
             raise ValueError("Invalid HTTP handler.")
     if user and password:
         self.http_handler.set_authentication(self.url, user, password)
     elif user or password:
         LOGGER.warning(
             "Either user or password missing, not using authentication.")
     self._sequence = 0
     self.session = None
     self.session_id = 0
     self.server_version = None
     self.protocol_version = None
     self.get_session()
     self.torrent_get_arguments = get_arguments("torrent-get",
                                                self.rpc_version)
コード例 #4
0
ファイル: client.py プロジェクト: fopina/Transmission-XBMC
 def __init__(
     self, address="localhost", port=DEFAULT_PORT, user=None, password=None, http_handler=None, timeout=None
 ):
     if isinstance(timeout, (int, long, float)):
         self._query_timeout = float(timeout)
     else:
         self._query_timeout = DEFAULT_TIMEOUT
     urlo = urlparse.urlparse(address)
     if urlo.scheme == "":
         base_url = "http://" + address + ":" + str(port)
         self.url = base_url + "/transmission/rpc"
     else:
         if urlo.port:
             self.url = urlo.scheme + "://" + urlo.hostname + ":" + str(urlo.port) + urlo.path
         else:
             self.url = urlo.scheme + "://" + urlo.hostname + urlo.path
         LOGGER.info('Using custom URL "' + self.url + '".')
         if urlo.username and urlo.password:
             user = urlo.username
             password = urlo.password
         elif urlo.username or urlo.password:
             LOGGER.warning("Either user or password missing, not using authentication.")
     if http_handler is None:
         self.http_handler = DefaultHTTPHandler()
     else:
         if hasattr(http_handler, "set_authentication") and hasattr(http_handler, "request"):
             self.http_handler = http_handler
         else:
             raise ValueError("Invalid HTTP handler.")
     if user and password:
         self.http_handler.set_authentication(self.url, user, password)
     elif user or password:
         LOGGER.warning("Either user or password missing, not using authentication.")
     self._sequence = 0
     self.session = Session()
     self.session_id = 0
     self.server_version = None
     self.protocol_version = None
     self.get_session()
     self.torrent_get_arguments = get_arguments("torrent-get", self.rpc_version)
コード例 #5
0
ファイル: transmission.py プロジェクト: bobbintb/tranny
    def torrent_list(self):
        """ Get a list of currently loaded torrents from the client

        :return:
        :rtype:
        """
        if not self._torrent_list_args:
            self._torrent_list_args = get_arguments('torrent-get',
                                                    self.client.rpc_version)
            self._torrent_list_args.extend([
                'seeders', 'peersKnown', 'peersGettingFromUs',
                'peersSendingToUs', 'isPrivate'
            ])
        torrents = self.client.get_torrents(arguments=self._torrent_list_args)
        torrent_data = list()
        for torrent in torrents:
            data = client.ClientTorrentData(
                info_hash=torrent.hashString,
                name=torrent.name,
                ratio=torrent.ratio,
                up_rate=torrent.rateUpload,
                dn_rate=torrent.rateDownload,
                up_total=torrent.uploadedEver,
                dn_total=torrent.downloadedEver,
                size=torrent.sizeWhenDone,
                size_completed=torrent.sizeWhenDone - torrent.leftUntilDone,
                # TODO peer values are wrong
                peers=torrent.peersGettingFromUs,
                total_peers=0,
                seeders=torrent.peersSendingToUs,
                total_seeders=0,
                priority=torrent.priority,
                private=torrent.isPrivate,
                state=torrent.status,
                progress=torrent.progress)
            torrent_data.append(data)
        return torrent_data
コード例 #6
0
ファイル: transmission.py プロジェクト: leighmacdonald/tranny
    def torrent_list(self):
        """ Get a list of currently loaded torrents from the client

        :return:
        :rtype:
        """
        if not self._torrent_list_args:
            self._torrent_list_args = get_arguments('torrent-get', self.client.rpc_version)
            self._torrent_list_args.extend(['seeders', 'peersKnown',
                                            'peersGettingFromUs', 'peersSendingToUs',
                                            'isPrivate'])
        torrents = self.client.get_torrents(arguments=self._torrent_list_args)
        torrent_data = list()
        for torrent in torrents:
            data = client.ClientTorrentData(
                info_hash=torrent.hashString,
                name=torrent.name,
                ratio=torrent.ratio,
                up_rate=torrent.rateUpload,
                dn_rate=torrent.rateDownload,
                up_total=torrent.uploadedEver,
                dn_total=torrent.downloadedEver,
                size=torrent.sizeWhenDone,
                size_completed=torrent.sizeWhenDone-torrent.leftUntilDone,
                # TODO peer values are wrong
                peers=torrent.peersGettingFromUs,
                total_peers=0,
                seeders=torrent.peersSendingToUs,
                total_seeders=0,
                priority=torrent.priority,
                private=torrent.isPrivate,
                state=torrent.status,
                progress=torrent.progress
            )
            torrent_data.append(data)
        return torrent_data