def method_get_torrents(self, hashes=None): fields = ['name', 'comment', 'hash', 'save_path'] result = self.query(self.build_request_payload('webapi.get_torrents', [hashes, fields])) for torrent_info in result['torrents']: self.normalize_field_names(torrent_info) return result['torrents'] def method_add_torrent(self, torrent, download_to=None): torrent_dump = base64encode(torrent).decode('utf-8') return self.query( self.build_request_payload( 'webapi.add_torrent', [torrent_dump, {'download_location': download_to}] ) ) def method_remove_torrent(self, hash_str, with_data=False): return self.query(self.build_request_payload('webapi.remove_torrent', [hash_str, with_data])) def method_get_version(self): return self.query(self.build_request_payload('webapi.get_api_version')) class DelugeRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(DelugeRPC)
for torrent_info in result['torrents']: self.normalize_field_names(torrent_info) return result['torrents'] def method_add_torrent(self, torrent, download_to=None): args = { 'metainfo': base64encode(torrent), } if download_to is not None: args['download-dir'] = download_to return self.query(self.build_request_payload('torrent-add', args)) # torrent-added def method_remove_torrent(self, hash_str, with_data=False): args = { 'ids': [hash_str], 'delete-local-data': with_data } self.query(self.build_request_payload('torrent-remove', args)) return True def method_get_version(self): result = self.query(self.build_request_payload('session-get', ['rpc-version-minimum'])) return result['rpc-version-minimum'] class TransmissionRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(TransmissionRPC)
result = self.query(self.build_request_payload('torrent-get', args)) for torrent_info in result['torrents']: self.normalize_field_names(torrent_info) return result['torrents'] def method_add_torrent(self, torrent, download_to=None): args = { 'metainfo': base64encode(torrent), } if download_to is not None: args['download-dir'] = download_to return self.query(self.build_request_payload('torrent-add', args)) # torrent-added def method_remove_torrent(self, hash_str, with_data=False): args = {'ids': [hash_str], 'delete-local-data': with_data} self.query(self.build_request_payload('torrent-remove', args)) return True def method_get_version(self): result = self.query( self.build_request_payload('session-get', ['rpc-version-minimum'])) return result['rpc-version-minimum'] class TransmissionRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(TransmissionRPC)
torrents_info[torrent_data[0]] = { 'hash': torrent_data[0], 'name': torrent_data[2], 'download_to': torrent_data[26] } return torrents_info def method_add_torrent(self, torrent, download_to=None): # NB: `download_to` is ignored, as existing API approach to it is crippled. file_data = {'torrent_file': ('from_torrt.torrent', torrent)} return self.query(self.build_params(action='add-file'), file_data) def method_remove_torrent(self, hash_str, with_data=False): action = 'remove' if with_data: action = 'removedata' self.query(self.build_params(action=action, params={'hash': hash_str})) return True def method_get_version(self): result = self.query(self.build_params(action='getversion')) return result['version']['ui_version'] class UTorrentRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(UTorrentRPC)
def method_add_torrent(self, torrent, download_to=None): file_data = {'torrents': torrent} if download_to is not None: file_data.update({'savepath': download_to}) return self.auth_query(self.build_params(action='add_torrent'), file_data) def method_remove_torrent(self, hash_str, with_data=False): action = 'rem_torrent' if with_data: action = 'rem_torrent_with_data' data = { 'hashes': hash_str } self.auth_query(self.build_params(action, {'data': data})) return True def method_get_version(self): result = self.auth_query(self.build_params(action='api_version_path')) return result.text class QBittorrentRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(QBittorrentRPC)
[hashes, fields])) for torrent_info in result['torrents']: self.normalize_field_names(torrent_info) return result['torrents'] def method_add_torrent(self, torrent, download_to=None): torrent_dump = base64encode(torrent).decode('utf-8') return self.query( self.build_request_payload( 'webapi.add_torrent', [torrent_dump, { 'download_location': download_to }])) def method_remove_torrent(self, hash_str, with_data=False): return self.query( self.build_request_payload('webapi.remove_torrent', [hash_str, with_data])) def method_get_version(self): return self.query(self.build_request_payload('webapi.get_api_version')) class DelugeRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(DelugeRPC)
return torrents_info def method_add_torrent(self, torrent, download_to=None): file_data = {'torrents': torrent} if download_to is not None: file_data.update({'savepath': download_to}) return self.auth_query(self.build_params(action='add_torrent'), file_data) def method_remove_torrent(self, hash_str, with_data=False): action = 'rem_torrent' if with_data: action = 'rem_torrent_with_data' data = {'hashes': hash_str} self.auth_query(self.build_params(action, {'data': data})) return True def method_get_version(self): result = self.auth_query(self.build_params(action='api_version_path')) return result.text class QBittorrentRPCException(TorrtRPCException): """""" RPCClassesRegistry.add(QBittorrentRPC)