diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index b6894ed..71da65e 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -13,6 +13,7 @@ class Downloader(Provider): protocol = [] http_time_between_calls = 0 + status_support = True torrent_sources = [ 'http://torrage.com/torrent/%s.torrent', @@ -69,7 +70,7 @@ class Downloader(Provider): return def getAllDownloadStatus(self, ids): - return + return [] def _removeFailed(self, release_download): if self.isDisabled(manual = True, data = {}): @@ -133,6 +134,7 @@ class Downloader(Provider): def downloadReturnId(self, download_id): return { 'downloader': self.getName(), + 'status_support': self.status_support, 'id': download_id } diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index 5216370..8449d09 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -11,6 +11,7 @@ log = CPLog(__name__) class Blackhole(Downloader): protocol = ['nzb', 'torrent', 'torrent_magnet'] + status_support = False def download(self, data = None, media = None, filedata = None): if not media: media = {} diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 57c1958..70cb57c 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -91,7 +91,7 @@ class Deluge(Downloader): log.debug('Checking Deluge download status.') if not self.connect(): - return False + return [] release_downloads = ReleaseDownloadList(self) @@ -99,7 +99,7 @@ class Deluge(Downloader): if not queue: log.debug('Nothing in queue or error') - return False + return [] for torrent_id in queue: torrent = queue[torrent_id] diff --git a/couchpotato/core/downloaders/nzbget/main.py b/couchpotato/core/downloaders/nzbget/main.py index a2ee645..2dc6cfc 100644 --- a/couchpotato/core/downloaders/nzbget/main.py +++ b/couchpotato/core/downloaders/nzbget/main.py @@ -81,13 +81,13 @@ class NZBGet(Downloader): log.info('Successfully connected to NZBGet, but unable to send a message') except socket.error: log.error('NZBGet is not responding. Please ensure that NZBGet is running and host setting is correct.') - return False + return [] except xmlrpclib.ProtocolError, e: if e.errcode == 401: log.error('Password is incorrect.') else: log.error('Protocol Error: %s', e) - return False + return [] # Get NZBGet data try: @@ -97,7 +97,7 @@ class NZBGet(Downloader): history = rpc.history() except: log.error('Failed getting data: %s', traceback.format_exc(1)) - return False + return [] release_downloads = ReleaseDownloadList(self) diff --git a/couchpotato/core/downloaders/pneumatic/main.py b/couchpotato/core/downloaders/pneumatic/main.py index 863cdb0..d3fdad8 100644 --- a/couchpotato/core/downloaders/pneumatic/main.py +++ b/couchpotato/core/downloaders/pneumatic/main.py @@ -11,6 +11,7 @@ class Pneumatic(Downloader): protocol = ['nzb'] strm_syntax = 'plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=%s&nzbname=%s' + status_support = False def download(self, data = None, media = None, filedata = None): if not media: media = {} diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index 2cbfd90..926bb41 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -147,7 +147,7 @@ class rTorrent(Downloader): log.debug('Checking rTorrent download status.') if not self.connect(): - return False + return [] try: torrents = self.rt.get_torrents() @@ -182,7 +182,7 @@ class rTorrent(Downloader): except Exception, err: log.error('Failed to get status from rTorrent: %s', err) - return False + return [] def pause(self, release_download, pause = True): if not self.connect(): diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index 6b4123e..0519cf6 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -75,7 +75,7 @@ class Sabnzbd(Downloader): }) except: log.error('Failed getting queue: %s', traceback.format_exc(1)) - return False + return [] # Go through history items try: @@ -85,7 +85,7 @@ class Sabnzbd(Downloader): }) except: log.error('Failed getting history json: %s', traceback.format_exc(1)) - return False + return [] release_downloads = ReleaseDownloadList(self) diff --git a/couchpotato/core/downloaders/synology/main.py b/couchpotato/core/downloaders/synology/main.py index c08c55c..74bc449 100644 --- a/couchpotato/core/downloaders/synology/main.py +++ b/couchpotato/core/downloaders/synology/main.py @@ -11,6 +11,7 @@ log = CPLog(__name__) class Synology(Downloader): protocol = ['nzb', 'torrent', 'torrent_magnet'] + status_support = False def download(self, data = None, media = None, filedata = None): if not media: media = {} diff --git a/couchpotato/core/downloaders/transmission/main.py b/couchpotato/core/downloaders/transmission/main.py index b8b1f9d..66cceb2 100644 --- a/couchpotato/core/downloaders/transmission/main.py +++ b/couchpotato/core/downloaders/transmission/main.py @@ -88,7 +88,7 @@ class Transmission(Downloader): log.debug('Checking Transmission download status.') if not self.connect(): - return False + return [] release_downloads = ReleaseDownloadList(self) @@ -99,7 +99,7 @@ class Transmission(Downloader): queue = self.trpc.get_alltorrents(return_params) if not (queue and queue.get('torrents')): log.debug('Nothing in queue or error') - return False + return [] for torrent in queue['torrents']: if torrent['hashString'] in ids: diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index 056cd15..77cf2f9 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -24,6 +24,16 @@ class uTorrent(Downloader): protocol = ['torrent', 'torrent_magnet'] utorrent_api = None + status_flags = { + 'STARTED' : 1, + 'CHECKING' : 2, + 'CHECK-START' : 4, + 'CHECKED' : 8, + 'ERROR' : 16, + 'PAUSED' : 32, + 'QUEUED' : 64, + 'LOADED' : 128 + } def connect(self): # Load host from config and split out port. @@ -40,7 +50,7 @@ class uTorrent(Downloader): if not media: media = {} if not data: data = {} - log.debug('Sending "%s" (%s) to uTorrent.', (data.get('name'), data.get('protocol'))) + log.debug("Sending '%s' (%s) to uTorrent.", (data.get('name'), data.get('protocol'))) if not self.connect(): return False @@ -75,7 +85,7 @@ class uTorrent(Downloader): torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper() torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers) else: - info = bdecode(filedata)["info"] + info = bdecode(filedata)['info'] torrent_hash = sha1(benc(info)).hexdigest().upper() torrent_filename = self.createFileName(data, filedata, media) @@ -110,23 +120,23 @@ class uTorrent(Downloader): log.debug('Checking uTorrent download status.') if not self.connect(): - return False + return [] release_downloads = ReleaseDownloadList(self) data = self.utorrent_api.get_status() if not data: log.error('Error getting data from uTorrent') - return False + return [] queue = json.loads(data) if queue.get('error'): log.error('Error getting data from uTorrent: %s', queue.get('error')) - return False + return [] if not queue.get('torrents'): log.debug('Nothing in queue') - return False + return [] # Get torrents for torrent in queue['torrents']: @@ -140,21 +150,10 @@ class uTorrent(Downloader): except: log.debug('Failed getting files from torrent: %s', torrent[2]) - status_flags = { - "STARTED" : 1, - "CHECKING" : 2, - "CHECK-START" : 4, - "CHECKED" : 8, - "ERROR" : 16, - "PAUSED" : 32, - "QUEUED" : 64, - "LOADED" : 128 - } - status = 'busy' - if (torrent[1] & status_flags["STARTED"] or torrent[1] & status_flags["QUEUED"]) and torrent[4] == 1000: + if (torrent[1] & self.status_flags['STARTED'] or torrent[1] & self.status_flags['QUEUED']) and torrent[4] == 1000: status = 'seeding' - elif (torrent[1] & status_flags["ERROR"]): + elif (torrent[1] & self.status_flags['ERROR']): status = 'failed' elif torrent[4] == 1000: status = 'completed' @@ -224,7 +223,7 @@ class uTorrentAPI(object): if time.time() > self.last_time + 1800: self.last_time = time.time() self.token = self.get_token() - request = urllib2.Request(self.url + "?token=" + self.token + "&" + action, data) + request = urllib2.Request(self.url + '?token=' + self.token + '&' + action, data) try: open_request = self.opener.open(request) response = open_request.read() @@ -244,52 +243,52 @@ class uTorrentAPI(object): return False def get_token(self): - request = self.opener.open(self.url + "token.html") - token = re.findall("