From 57af56757acdedc2aef0a935928d36935ef0bf61 Mon Sep 17 00:00:00 2001 From: PancakeZik <jpbragatti@gmail.com> Date: Fri, 5 May 2017 00:56:32 +0100 Subject: [PATCH] qBittorrent: Verify torrent was added (#3706) Verify that torrent was added to client (similar to rTorrent), because the client API doesn't return result for adding torrents. --- sickbeard/clients/qbittorrent_client.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sickbeard/clients/qbittorrent_client.py b/sickbeard/clients/qbittorrent_client.py index 6442a3307..877807315 100644 --- a/sickbeard/clients/qbittorrent_client.py +++ b/sickbeard/clients/qbittorrent_client.py @@ -18,8 +18,11 @@ # You should have received a copy of the GNU General Public License # along with SickRage. If not, see <http://www.gnu.org/licenses/>. +from time import sleep + import sickbeard from sickbeard.clients.generic import GenericClient +from sickrage.helper.common import try_int from requests.auth import HTTPDigestAuth @@ -67,13 +70,17 @@ class qbittorrentAPI(GenericClient): self.url = self.host + 'command/download' data = {'urls': result.url} - return self._request(method='post', data=data, cookies=self.session.cookies) + if self._request(method='post', data=data, cookies=self.session.cookies): + return self._verify_added(result.hash) + return False def _add_torrent_file(self, result): self.url = self.host + 'command/upload' files = {'torrents': (result.name + '.torrent', result.content)} - return self._request(method='post', files=files, cookies=self.session.cookies) + if self._request(method='post', files=files, cookies=self.session.cookies): + return self._verify_added(result.hash) + return False def _set_torrent_label(self, result): @@ -81,7 +88,7 @@ class qbittorrentAPI(GenericClient): if result.show.is_anime: label = sickbeard.TORRENT_LABEL_ANIME - if self.api > 6 and self.api < 10 and label: + if 6 < self.api < 10 and label: self.url = self.host + 'command/setLabel' data = {'hashes': result.hash.lower(), 'label': label.replace(' ', '_')} return self._request(method='post', data=data, cookies=self.session.cookies) @@ -108,7 +115,16 @@ class qbittorrentAPI(GenericClient): if sickbeard.TORRENT_PAUSED: self.url = self.host + 'command/pause' - data = {'hash': result.hash} + data = {'hash': result.hash.lower()} return self._request(method='post', data=data, cookies=self.session.cookies) + def _verify_added(self, torrent_hash, attempts=5): + self.url = self.host + 'query/propertiesGeneral/' + torrent_hash.lower() + for i in range(attempts): + if self._request(method='get', cookies=self.session.cookies): + if try_int(self.response.headers.get('Content-Length')) > 0: + return True + sleep(2) + return False + api = qbittorrentAPI() -- GitLab