add qbittorrent client. Fixes #1300

This commit is contained in:
clinton-hall 2018-01-22 08:41:44 +13:00
commit 12a7e3c5ce
5 changed files with 670 additions and 1 deletions

View file

@ -23,6 +23,7 @@ from core.linktastic import linktastic
from core.synchronousdeluge.client import DelugeClient
from core.utorrent.client import UTorrentClient
from core.transmissionrpc.client import Client as TransmissionClient
from core.qbittorrent.client import Client as qBittorrentClient
from core import logger, nzbToMediaDB
requests.packages.urllib3.disable_warnings()
@ -825,6 +826,14 @@ def create_torrent_class(clientAgent):
except:
logger.error("Failed to connect to Deluge")
if clientAgent == 'qbittorrent':
try:
logger.debug("Connecting to {0}: http://{1}:{2}".format(clientAgent, core.QBITTORRENTHOST, core.QBITTORRENTPORT))
tc = qBittorrentClient("http://{1}:{2}/".format(core.QBITTORRENTHOST, core.QBITTORRENTPORT))
tc.login(core.QBITTORRENTUSR, core.QBITTORRENTPWD)
except:
logger.error("Failed to connect to qBittorrent")
return tc
@ -837,6 +846,8 @@ def pause_torrent(clientAgent, inputHash, inputID, inputName):
core.TORRENT_CLASS.stop_torrent(inputID)
if clientAgent == 'deluge' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.core.pause_torrent([inputID])
if clientAgent == 'qbittorrent' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.pause(inputHash)
time.sleep(5)
except:
logger.warning("Failed to stop torrent {0} in {1}".format(inputName, clientAgent))
@ -853,6 +864,8 @@ def resume_torrent(clientAgent, inputHash, inputID, inputName):
core.TORRENT_CLASS.start_torrent(inputID)
if clientAgent == 'deluge' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.core.resume_torrent([inputID])
if clientAgent == 'qbittorrent' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.resume(inputHash)
time.sleep(5)
except:
logger.warning("Failed to start torrent {0} in {1}".format(inputName, clientAgent))
@ -869,6 +882,8 @@ def remove_torrent(clientAgent, inputHash, inputID, inputName):
core.TORRENT_CLASS.remove_torrent(inputID, True)
if clientAgent == 'deluge' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.core.remove_torrent(inputID, True)
if clientAgent == 'qbittorrent' and core.TORRENT_CLASS != "":
core.TORRENT_CLASS.delete(inputHash)
time.sleep(5)
except:
logger.warning("Failed to delete torrent {0} in {1}".format(inputName, clientAgent))
@ -891,6 +906,11 @@ def find_download(clientAgent, download_id):
return True
if clientAgent == 'deluge':
return False
if clientAgent == 'qbittorrent':
torrents = core.TORRENT_CLASS.torrents()
for torrent in torrents:
if torrent['infohash'] == download_id:
return True
if clientAgent == 'sabnzbd':
if "http" in core.SABNZBDHOST:
baseURL = "{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT)