예제 #1
0
    def get_torrent_status(self, idx):
        if not self.connected:
            ret = ClientRet(ret_type=-2)
            return ret

        try:
            torrent_obj = self.client.get_torrent(idx)
            is_finished = math.isclose(torrent_obj.progress, 100)
            torrent_status = TorrentStatus(torrent_id=torrent_obj.hashString,
                                           is_finished=is_finished,
                                           name=torrent_obj.name)

            ret = ClientRet(ret_type=6, ret_value=torrent_status)
        except:
            ret = ClientRet(ret_type=-6)
        finally:
            return ret
예제 #2
0
    def list_torrents(self):
        if not self.connected:
            return ClientRet(ret_type=-2)

        torrent_list = self.client.torrents()
        session_status = {}
        for torrent in torrent_list:
            is_finished = math.isclose(torrent['progress'], 1)
            torrent_status = TorrentStatus(torrent_id=torrent['hash'],
                                           is_finished=is_finished,
                                           name=torrent['name'])

            session_status[torrent['hash']] = torrent_status

        ret = ClientRet(ret_type=4, ret_value=session_status)

        return ret
예제 #3
0
    def get_torrent_status(self, idx):
        if not self.connected:
            return ClientRet(ret_type=-2)

        tlist = self.client.torrents()
        for torrent in tlist:
            if idx == torrent[
                    'hash']:  # No progress info in get_torrent() method, really...
                is_finished = math.isclose(torrent['progress'], 1)
                torrent_status = TorrentStatus(torrent_id=torrent['hash'],
                                               is_finished=is_finished,
                                               name=torrent['name'])

                ret = ClientRet(ret_type=6, ret_value=torrent_status)
                return ret

        return ClientRet(ret_type=-6)
예제 #4
0
    def get_torrent_status(
        self, idx
    ):  # All the value inputted and returned back should be string, not bytearray
        if not self.connected:
            ret = ClientRet(ret_type=-2)
            return ret

        idx = idx.encode()  # Convert to byte array for Deluge
        torrent_status_raw = self.client.core.get_torrent_status(
            torrent_id=idx, keys=bt_client.client_base.torrent_status_key)
        torrent_status = TorrentStatus(
            torrent_id=idx.decode(),
            is_finished=torrent_status_raw[
                'is_finished'.encode()],  # Decode bytearray to string
            name=torrent_status_raw[
                'name'.encode()].decode())  # Decode bytearray to string

        ret = ClientRet(ret_type=6, ret_value=torrent_status)
        return ret
예제 #5
0
    def list_torrents(self):
        if not self.connected:
            ret = ClientRet(ret_type=-2)
            return ret

        torrent_id_list = self.client.core.get_session_state()
        session_status = {}
        for idx in torrent_id_list:
            torrent_status_raw = self.client.core.get_torrent_status(
                torrent_id=idx, keys=bt_client.client_base.torrent_status_key)
            torrent_status = TorrentStatus(
                torrent_id=idx.decode(),
                is_finished=torrent_status_raw['is_finished'.encode()],
                name=torrent_status_raw['name'.encode()].decode())
            session_status[torrent_status.torrent_id] = torrent_status

        ret = ClientRet(ret_type=4, ret_value=session_status)

        return ret
예제 #6
0
    def list_torrents(self):
        if not self.connected:
            ret = ClientRet(ret_type=-2)
            return ret

        try:
            torrent_obj_list = self.client.get_torrents()
            session_status = {}
            for torrent_obj in torrent_obj_list:
                is_finished = math.isclose(torrent_obj.progress, 100)
                torrent_status = TorrentStatus(
                    torrent_id=torrent_obj.hashString,
                    is_finished=is_finished,
                    name=torrent_obj.name)

                session_status[torrent_obj.hashString] = torrent_status

            ret = ClientRet(ret_type=4, ret_value=session_status)
        except:
            ret = ClientRet(ret_type=-4)
        finally:
            return ret