Beispiel #1
0
 def connect(self):
     self.client = DelugeClient()
     self.client.connect(self.host, int(self.port), self.username,
                         self.password)
Beispiel #2
0
 def connect(self):
     self.client = DelugeClient()
     self.client.connect(self.host, int(self.port), self.username, self.password)
Beispiel #3
0
class DelugeRPC(object):
    host = 'localhost'
    port = 58846
    username = None
    password = None
    client = None

    def __init__(self,
                 host='localhost',
                 port=58846,
                 username=None,
                 password=None):
        super(DelugeRPC, self).__init__()

        self.host = host
        self.port = port
        self.username = username
        self.password = password

    def connect(self):
        self.client = DelugeClient()
        self.client.connect(self.host, int(self.port), self.username,
                            self.password)

    def test(self):
        try:
            self.connect()
        except Exception:
            return False
        return True

    def add_torrent_magnet(self, torrent, options, torrent_hash):
        torrent_id = False
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            torrent_id = self.client.core.add_torrent_magnet(torrent,
                                                             options).get()
            if not torrent_id:
                torrent_id = self._check_torrent(torrent_hash)
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()

        return torrent_id

    def add_torrent_file(self, filename, torrent, options, torrent_hash):
        torrent_id = False
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            torrent_id = self.client.core.add_torrent_file(
                filename, b64encode(torrent), options).get()
            if not torrent_id:
                torrent_id = self._check_torrent(torrent_hash)
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()

        return torrent_id

    def set_torrent_label(self, torrent_id, label):
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            self.client.label.set_torrent(torrent_id, label).get()
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()
        return True

    def set_torrent_path(self, torrent_id, path):
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            self.client.core.set_torrent_move_completed_path(torrent_id,
                                                             path).get()
            # noinspection PyUnresolvedReferences
            self.client.core.set_torrent_move_completed(torrent_id, 1).get()
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()
        return True

    def set_torrent_priority(self, torrent_ids, priority):
        try:
            self.connect()
            if priority:
                # noinspection PyUnresolvedReferences
                self.client.core.queue_top([torrent_ids]).get()
        except Exception, err:
            return False
        finally:
Beispiel #4
0
class DelugeRPC(object):
    host = "localhost"
    port = 58846
    username = None
    password = None
    client = None

    def __init__(self, host="localhost", port=58846, username=None, password=None):
        super(DelugeRPC, self).__init__()

        self.host = host
        self.port = port
        self.username = username
        self.password = password

    def connect(self):
        self.client = DelugeClient()
        self.client.connect(self.host, int(self.port), self.username, self.password)

    def test(self):
        try:
            self.connect()
        except Exception:
            return False
        return True

    def add_torrent_magnet(self, torrent, options, torrent_hash):
        torrent_id = False
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            torrent_id = self.client.core.add_torrent_magnet(torrent, options).get()
            if not torrent_id:
                torrent_id = self._check_torrent(torrent_hash)
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()

        return torrent_id

    def add_torrent_file(self, filename, torrent, options, torrent_hash):
        torrent_id = False
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            torrent_id = self.client.core.add_torrent_file(filename, b64encode(torrent), options).get()
            if not torrent_id:
                torrent_id = self._check_torrent(torrent_hash)
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()

        return torrent_id

    def set_torrent_label(self, torrent_id, label):
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            self.client.label.set_torrent(torrent_id, label).get()
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()
        return True

    def set_torrent_path(self, torrent_id, path):
        try:
            self.connect()
            # noinspection PyUnresolvedReferences
            self.client.core.set_torrent_move_completed_path(torrent_id, path).get()
            # noinspection PyUnresolvedReferences
            self.client.core.set_torrent_move_completed(torrent_id, 1).get()
        except Exception:
            return False
        finally:
            if self.client:
                self.disconnect()
        return True

    def set_torrent_priority(self, torrent_ids, priority):
        try:
            self.connect()
            if priority:
                # noinspection PyUnresolvedReferences
                self.client.core.queue_top([torrent_ids]).get()
        except Exception, err:
            return False
        finally: