Browse Source

Merge pull request #6383 from agentxan/develop

Fix authenticating and connecting to qBittorrent
pull/6414/head
Ruud Burger 9 years ago
parent
commit
33add26df3
  1. 41
      couchpotato/core/downloaders/qbittorrent_.py

41
couchpotato/core/downloaders/qbittorrent_.py

@ -1,5 +1,6 @@
from base64 import b16encode, b32decode from base64 import b16encode, b32decode
from hashlib import sha1 from hashlib import sha1
from datetime import timedelta
import os import os
from bencode import bencode, bdecode from bencode import bencode, bdecode
@ -23,12 +24,12 @@ class qBittorrent(DownloaderBase):
def __init__(self): def __init__(self):
super(qBittorrent, self).__init__() super(qBittorrent, self).__init__()
def connect(self): def connect(self, reconnect = False):
if self.qb is not None: if not reconnect and self.qb is not None:
return self.qb return self.qb
url = cleanHost(self.conf('host'), protocol = True, ssl = False) url = cleanHost(self.conf('host'), protocol = True, ssl = False)
if self.conf('username') and self.conf('password'): if self.conf('username') and self.conf('password'):
self.qb = QBittorrentClient(url) self.qb = QBittorrentClient(url)
self.qb.login(username=self.conf('username'),password=self.conf('password')) self.qb.login(username=self.conf('username'),password=self.conf('password'))
@ -41,7 +42,9 @@ class qBittorrent(DownloaderBase):
""" Check if connection works """ Check if connection works
:return: bool :return: bool
""" """
self.connect(True)
return self.qb._is_authenticated return self.qb._is_authenticated
def download(self, data = None, media = None, filedata = None): def download(self, data = None, media = None, filedata = None):
@ -98,10 +101,10 @@ class qBittorrent(DownloaderBase):
def getTorrentStatus(self, torrent): def getTorrentStatus(self, torrent):
if torrent.state in ('uploading', 'queuedUP', 'stalledUP'): if torrent['state'] in ('uploading', 'queuedUP', 'stalledUP'):
return 'seeding' return 'seeding'
if torrent.progress == 1: if torrent['progress'] == 1:
return 'completed' return 'completed'
return 'busy' return 'busy'
@ -121,39 +124,39 @@ class qBittorrent(DownloaderBase):
return [] return []
try: try:
torrents = self.qb.torrents(label=self.conf('label')) torrents = self.qb.torrents(status='all', label=self.conf('label'))
release_downloads = ReleaseDownloadList(self) release_downloads = ReleaseDownloadList(self)
for torrent in torrents: for torrent in torrents:
if torrent.hash in ids: if torrent['hash'] in ids:
torrent_filelist = self.qb.get_torrent_files(torrent.hash) torrent_filelist = self.qb.get_torrent_files(torrent['hash'])
torrent_files = [] torrent_files = []
torrent_dir = os.path.join(torrent.save_path, torrent.name) torrent_dir = os.path.join(torrent['save_path'], torrent['name'])
if os.path.isdir(torrent_dir): if os.path.isdir(torrent_dir):
torrent.save_path = torrent_dir torrent['save_path'] = torrent_dir
if len(torrent_filelist) > 1 and os.path.isdir(torrent_dir): # multi file torrent, path.isdir check makes sure we're not in the root download folder if len(torrent_filelist) > 1 and os.path.isdir(torrent_dir): # multi file torrent, path.isdir check makes sure we're not in the root download folder
for root, _, files in os.walk(torrent.save_path): for root, _, files in os.walk(torrent['save_path']):
for f in files: for f in files:
torrent_files.append(sp(os.path.join(root, f))) torrent_files.append(sp(os.path.join(root, f)))
else: # multi or single file placed directly in torrent.save_path else: # multi or single file placed directly in torrent.save_path
for f in torrent_filelist: for f in torrent_filelist:
file_path = os.path.join(torrent.save_path, f.name) file_path = os.path.join(torrent['save_path'], f['name'])
if os.path.isfile(file_path): if os.path.isfile(file_path):
torrent_files.append(sp(file_path)) torrent_files.append(sp(file_path))
release_downloads.append({ release_downloads.append({
'id': torrent.hash, 'id': torrent['hash'],
'name': torrent.name, 'name': torrent['name'],
'status': self.getTorrentStatus(torrent), 'status': self.getTorrentStatus(torrent),
'seed_ratio': torrent.ratio, 'seed_ratio': torrent['ratio'],
'original_status': torrent.state, 'original_status': torrent['state'],
'timeleft': torrent.progress * 100 if torrent.progress else -1, # percentage 'timeleft': str(timedelta(seconds = torrent['eta'])),
'folder': sp(torrent.save_path), 'folder': sp(torrent['save_path']),
'files': torrent_files 'files': torrent_files
}) })

Loading…
Cancel
Save