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
This commit is contained in:
clinton-hall
2013-04-26 16:03:20 +09:30
parent f2f43a2231
commit 92998bafc8
+25 -7
View File
@@ -1,7 +1,7 @@
from base64 import standard_b64encode from base64 import standard_b64encode
from couchpotato.core.downloaders.base import Downloader, StatusList from couchpotato.core.downloaders.base import Downloader, StatusList
from couchpotato.core.helpers.encoding import ss 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 couchpotato.core.logger import CPLog
from datetime import timedelta from datetime import timedelta
import re import re
@@ -52,7 +52,14 @@ class NZBGet(Downloader):
if xml_response: if xml_response:
log.info('NZB sent successfully to NZBGet') 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: else:
log.error('NZBGet could not add %s to the queue.', nzb_name) log.error('NZBGet could not add %s to the queue.', nzb_name)
return False return False
@@ -93,15 +100,19 @@ class NZBGet(Downloader):
for item in groups: for item in groups:
log.debug('Found %s in NZBGet download queue', item['NZBFilename']) 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({ statuses.append({
'id': item['NZBID'], 'id': NZB_ID,
'name': item['NZBFilename'], 'name': item['NZBFilename'],
'original_status': 'DOWNLOADING' if item['ActiveDownloads'] > 0 else 'QUEUED', '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 # 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, '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']) log.debug('Found %s in NZBGet postprocessing queue', item['NZBFilename'])
statuses.append({ statuses.append({
'id': item['NZBID'], 'id': item['NZBID'],
@@ -112,8 +123,12 @@ class NZBGet(Downloader):
for item in history: 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'])) 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({ statuses.append({
'id': item['NZBID'], 'id': NZB_ID,
'name': item['NZBFilename'], 'name': item['NZBFilename'],
'status': 'completed' if item['ParStatus'] == 'SUCCESS' and item['ScriptStatus'] == 'SUCCESS' else 'failed', 'status': 'completed' if item['ParStatus'] == 'SUCCESS' and item['ScriptStatus'] == 'SUCCESS' else 'failed',
'original_status': item['ParStatus'] + ', ' + item['ScriptStatus'], 'original_status': item['ParStatus'] + ', ' + item['ScriptStatus'],
@@ -147,8 +162,11 @@ class NZBGet(Downloader):
try: try:
history = rpc.history() history = rpc.history()
if rpc.editqueue('HistoryDelete', 0, "", [tryInt(item['id'])]): for hist in history:
path = [hist['DestDir'] for hist in history if hist['NZBID'] == item['id']][0] 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) shutil.rmtree(path, True)
except: except:
log.error('Failed deleting: %s', traceback.format_exc(0)) log.error('Failed deleting: %s', traceback.format_exc(0))