From 2954558004807c9d600c5f9b6dff8b89c2ddc4d5 Mon Sep 17 00:00:00 2001 From: Techmunk Date: Tue, 27 Aug 2013 20:13:29 +1000 Subject: [PATCH 1/3] Fix up deluge is Finished status matching. --- couchpotato/core/downloaders/deluge/main.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 83be6bfc..bc31d477 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -85,6 +85,10 @@ class Deluge(Downloader): log.debug('Checking Deluge download status.') + if not os.path.isdir(Env.setting('from', 'renamer')): + log.error('Renamer "from" folder doesn\'t to exist.') + return + if not self.connect(): return False @@ -92,7 +96,7 @@ class Deluge(Downloader): queue = self.drpc.get_alltorrents() - if not (queue and queue.get('torrents')): + if not (queue): log.debug('Nothing in queue or error') return False @@ -100,16 +104,15 @@ class Deluge(Downloader): item = queue[torrent_id] log.debug('name=%s / id=%s / save_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / conf_ratio=%s/ is_seed=%s / is_finished=%s', (item['name'], item['hash'], item['save_path'], item['hash'], item['progress'], item['state'], item['eta'], item['ratio'], self.conf('ratio'), item['is_seed'], item['is_finished'])) - if not os.path.isdir(Env.setting('from', 'renamer')): - log.error('Renamer "from" folder doesn\'t to exist.') - return - status = 'busy' - # Deluge seems to set both is_seed and is_finished once everything has been downloaded. - if item['is_seed'] or item['is_finished']: + if item['is_seed'] and tryFloat(item['ratio']) < tryFloat(item['stop_ratio']): + # We have item['seeding_time'] to work out what the seeding time is, but we do not + # have access to the downloader seed_time, as with deluge we have no way to pass it + # when the torrent is added. So Deluge will only look at the ratio. + # See above comment in download(). status = 'seeding' - elif item['is_seed'] and item['is_finished'] and item['paused']: - status = 'completed' + elif item['is_seed'] and item['is_finished'] and item['paused'] and item['state'] == 'Paused': + status = 'finished' download_dir = item['save_path'] if item['move_on_completed']: From 104e21b31403450c723dde7da1800ede0017f0c3 Mon Sep 17 00:00:00 2001 From: Techmunk Date: Wed, 28 Aug 2013 20:41:02 +1000 Subject: [PATCH 2/3] Fix for deluge downloading torrent files. --- couchpotato/core/downloaders/deluge/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index bc31d477..26b31d54 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -31,7 +31,6 @@ class Deluge(Downloader): return self.drpc def download(self, data, movie, filedata = None): - log.info('Sending "%s" (%s) to Deluge.', (data.get('name'), data.get('protocol'))) if not self.connect(): @@ -72,7 +71,8 @@ class Deluge(Downloader): if data.get('protocol') == 'torrent_magnet': remote_torrent = self.drpc.add_torrent_magnet(data.get('url'), options) else: - remote_torrent = self.drpc.add_torrent_file(movie, b64encode(filedata), options) + filename = self.createFileName(data, filedata, movie) + remote_torrent = self.drpc.add_torrent_file(filename, b64encode(filedata), options) if not remote_torrent: log.error('Failed sending torrent to Deluge') @@ -172,22 +172,22 @@ class DelugeRPC(object): if options['label']: self.client.label.set_torrent(torrent_id, options['label']).get() except Exception, err: - log.error('Failed to add torrent magnet: %s %s', (err, traceback.format_exc())) + log.error('Failed to add torrent magnet %s: %s %s', (torrent, err, traceback.format_exc())) finally: if self.client: self.disconnect() return torrent_id - def add_torrent_file(self, movie, torrent, options): + def add_torrent_file(self, filename, torrent, options): torrent_id = False try: self.connect() - torrent_id = self.client.core.add_torrent_file(movie, torrent, options).get() + torrent_id = self.client.core.add_torrent_file(filename, torrent, options).get() if options['label']: self.client.label.set_torrent(torrent_id, options['label']).get() except Exception, err: - log.error('Failed to add torrent file: %s %s', (err, traceback.format_exc())) + log.error('Failed to add torrent file %s: %s %s', (filename, err, traceback.format_exc())) finally: if self.client: self.disconnect() From 48be010f331d80d4e8f6ab954b1d77e2b256ac35 Mon Sep 17 00:00:00 2001 From: Techmunk Date: Fri, 30 Aug 2013 10:25:58 +1000 Subject: [PATCH 3/3] Fix up some debug messages, and the torrent completed status. --- couchpotato/core/downloaders/deluge/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 26b31d54..31a9debd 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -102,8 +102,10 @@ class Deluge(Downloader): for torrent_id in queue: item = queue[torrent_id] - log.debug('name=%s / id=%s / save_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / conf_ratio=%s/ is_seed=%s / is_finished=%s', (item['name'], item['hash'], item['save_path'], item['hash'], item['progress'], item['state'], item['eta'], item['ratio'], self.conf('ratio'), item['is_seed'], item['is_finished'])) + log.debug('name=%s / id=%s / save_path=%s / move_completed_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / stop_ratio=%s / is_seed=%s / is_finished=%s / paused=%s', (item['name'], item['hash'], item['save_path'], item['move_completed_path'], item['hash'], item['progress'], item['state'], item['eta'], item['ratio'], item['stop_ratio'], item['is_seed'], item['is_finished'], item['paused'])) + # Deluge has no easy way to work out if a torrent is stalled or failing. + #status = 'failed' status = 'busy' if item['is_seed'] and tryFloat(item['ratio']) < tryFloat(item['stop_ratio']): # We have item['seeding_time'] to work out what the seeding time is, but we do not @@ -112,7 +114,7 @@ class Deluge(Downloader): # See above comment in download(). status = 'seeding' elif item['is_seed'] and item['is_finished'] and item['paused'] and item['state'] == 'Paused': - status = 'finished' + status = 'completed' download_dir = item['save_path'] if item['move_on_completed']: