Private GIT

Skip to content
Snippets Groups Projects
Commit 57af5675 authored by PancakeZik's avatar PancakeZik Committed by Kfir Hadas
Browse files

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.
parent 53474edc
No related branches found
No related tags found
No related merge requests found
......@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment