diff --git a/autoremovetorrents/client/qbittorrent.py b/autoremovetorrents/client/qbittorrent.py index c09ca59..2161b4e 100644 --- a/autoremovetorrents/client/qbittorrent.py +++ b/autoremovetorrents/client/qbittorrent.py @@ -1,6 +1,7 @@ #-*- coding:utf-8 -*- import requests import time +from packaging import version from .. import logger from ..torrent import Torrent from ..clientstatus import ClientStatus @@ -135,6 +136,21 @@ def __init__(self, host): if self._request_handler is None: raise IncompatibleAPIVersion('Incompatible qbittorrent client. The current API version may be unsupported.') + # Workaround for https://github.com/qbittorrent/qBittorrent/issues/18097 + if self._request_handler.api_major_version() == "v2": + if version.parse(self._request_handler.client_version().text) >= version.parse("4.5.0"): + def new_delete_torrents(self, torrent_hash_list): + return self._session.post(self._host + '/api/v2/torrents/delete', + data={'hashes': '|'.join(torrent_hash_list), 'deleteFiles': False}) + + self.qBittorrentAPIHandlerV2.delete_torrents = new_delete_torrents + + def new_delete_torrents_and_data(self, torrent_hash_list): + return self._session.post(self._host + '/api/v2/torrents/delete', + data={'hashes': '|'.join(torrent_hash_list), 'deleteFiles': True}) + + self.qBittorrentAPIHandlerV2.delete_torrents_and_data = new_delete_torrents_and_data + # Login to qBittorrent def login(self, username, password): try: diff --git a/setup.py b/setup.py index 118c1af..5660cb7 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ install_requires = [ 'deluge-client', 'enum34', + 'packaging', 'ply', '' if SUPPORT_SHUTIL else 'psutil', PYYAML_VERSION,