From f2f43a223142785db739cf80fd75d03a31471fd5 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Tue, 16 Apr 2013 11:10:50 +0930 Subject: [PATCH 1/2] Wont delete the "from" (sub)folders, "movie" folder or "destination" folder at this time. These should be deleted after the renaming... at this stage we should only be deleting any "older releases" --- couchpotato/core/plugins/renamer/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 87d9aaf3..8ad7ddc2 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -421,7 +421,7 @@ class Renamer(Plugin): os.remove(src) parent_dir = os.path.normpath(os.path.dirname(src)) - if delete_folders.count(parent_dir) == 0 and os.path.isdir(parent_dir) and destination != parent_dir: + if delete_folders.count(parent_dir) == 0 and os.path.isdir(parent_dir) and not parent_dir in [destination, movie_folder] and not self.conf('from') in parent_dir: delete_folders.append(parent_dir) except: From 92998bafc836ff021f647a5d65063716c47eefbe Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sat, 20 Apr 2013 11:49:10 +0930 Subject: [PATCH 2/2] write unique id to nzbget params My mistake. Fixed now. Yeah... sorry ;) This does work for check_snatched... Marks as busy, or failed etc. keep consistent release table format fix check_snatched correctly parse the NZBGet Parameters and Pass status.downloader remove downloader and fix id My mistake. Fixed now. Yeah... sorry ;) This does work for check_snatched... Marks as busy, or failed etc. keep consistent release table format fix check_snatched correctly parse the NZBGet Parameters and Pass status.downloader remove downloader and fix id --- couchpotato/core/downloaders/nzbget/main.py | 32 ++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/downloaders/nzbget/main.py b/couchpotato/core/downloaders/nzbget/main.py index 78e2b957..5478a3cb 100644 --- a/couchpotato/core/downloaders/nzbget/main.py +++ b/couchpotato/core/downloaders/nzbget/main.py @@ -1,7 +1,7 @@ from base64 import standard_b64encode from couchpotato.core.downloaders.base import Downloader, StatusList from couchpotato.core.helpers.encoding import ss -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, md5 from couchpotato.core.logger import CPLog from datetime import timedelta import re @@ -52,7 +52,14 @@ class NZBGet(Downloader): if xml_response: log.info('NZB sent successfully to NZBGet') - return True + nzb_id = md5(data['url']) # about as unique as they come ;) + couchpotato_id = "couchpotato=" + nzb_id + groups = rpc.listgroups() + file_id = [item['LastID'] for item in groups if item['NZBFilename'] == nzb_name] + confirmed = rpc.editqueue("GroupSetParameter", 0, couchpotato_id, file_id) + if confirmed: + log.debug('couchpotato parameter set in nzbget download') + return self.downloadReturnId(nzb_id) else: log.error('NZBGet could not add %s to the queue.', nzb_name) return False @@ -93,15 +100,19 @@ class NZBGet(Downloader): for item in groups: log.debug('Found %s in NZBGet download queue', item['NZBFilename']) + try: + NZB_ID = [param['Value'] for param in item['Parameters'] if param['Name'] == 'couchpotato'][0] + except: + NZB_ID = item['NZBID'], statuses.append({ - 'id': item['NZBID'], + 'id': NZB_ID, 'name': item['NZBFilename'], 'original_status': 'DOWNLOADING' if item['ActiveDownloads'] > 0 else 'QUEUED', # Seems to have no native API function for time left. This will return the time left after NZBGet started downloading this item 'timeleft': str(timedelta(seconds = item['RemainingSizeMB'] / status['DownloadRate'] * 2 ^ 20)) if item['ActiveDownloads'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']) else -1, }) - for item in queue: + for item in queue: # 'Parameters' is not passed in rpc.postqueue log.debug('Found %s in NZBGet postprocessing queue', item['NZBFilename']) statuses.append({ 'id': item['NZBID'], @@ -112,8 +123,12 @@ class NZBGet(Downloader): for item in history: log.debug('Found %s in NZBGet history. ParStatus: %s, ScriptStatus: %s, Log: %s', (item['NZBFilename'] , item['ParStatus'], item['ScriptStatus'] , item['Log'])) + try: + NZB_ID = [param['Value'] for param in item['Parameters'] if param['Name'] == 'couchpotato'][0] + except: + NZB_ID = item['NZBID'], statuses.append({ - 'id': item['NZBID'], + 'id': NZB_ID, 'name': item['NZBFilename'], 'status': 'completed' if item['ParStatus'] == 'SUCCESS' and item['ScriptStatus'] == 'SUCCESS' else 'failed', 'original_status': item['ParStatus'] + ', ' + item['ScriptStatus'], @@ -147,8 +162,11 @@ class NZBGet(Downloader): try: history = rpc.history() - if rpc.editqueue('HistoryDelete', 0, "", [tryInt(item['id'])]): - path = [hist['DestDir'] for hist in history if hist['NZBID'] == item['id']][0] + for hist in history: + if hist['Parameters'] and hist['Parameters']['couchpotato'] and hist['Parameters']['couchpotato'] == item['id']: + NZBID = hist['ID'] + path = hist['DestDir'] + if rpc.editqueue('HistoryDelete', 0, "", [tryInt(NZBID)]): shutil.rmtree(path, True) except: log.error('Failed deleting: %s', traceback.format_exc(0))