add download id. Fixes #583

Ref. https://github.com/Sonarr/Sonarr/pull/130
This commit is contained in:
clinton-hall 2014-11-04 11:06:28 +10:30
commit 13a45b6aab
4 changed files with 35 additions and 6 deletions

View file

@ -206,7 +206,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
inputCategory)
elif sectionName in ['SickBeard','NzbDrone']:
result = nzbtomedia.autoProcessTV().processEpisode(sectionName,outputDestination, inputName, status, clientAgent,
inputCategory)
inputHash.upper(), inputCategory)
elif sectionName == 'HeadPhones':
result = nzbtomedia.autoProcessMusic().process(sectionName,outputDestination, inputName, status, clientAgent, inputCategory)
elif sectionName == 'Mylar':

View file

@ -506,6 +506,9 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
inputDirectory))
return [-1, ""]
if not download_id and clientAgent == 'sabnzbd':
download_id = get_nzoid(inputName)
if clientAgent != 'manual' and not nzbtomedia.DOWNLOADINFO:
logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory))
@ -580,7 +583,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
inputCategory, failureLink)
elif sectionName in ["SickBeard", "NzbDrone"]:
result = autoProcessTV().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent,
inputCategory, failureLink)
download_id, inputCategory, failureLink)
elif sectionName == "HeadPhones":
result = autoProcessMusic().process(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory)
elif sectionName == "Mylar":
@ -667,6 +670,8 @@ def main(args, section=None):
failureLink = None
if os.environ.has_key('NZBPR_COUCHPOTATO'):
download_id = os.environ['NZBPR_COUCHPOTATO']
elif os.environ.has_key('NZBPR_DRONE'):
download_id = os.environ['NZBPR_DRONE']
if os.environ.has_key('NZBPR__DNZB_FAILURE'):
failureLink = os.environ['NZBPR__DNZB_FAILURE']

View file

@ -48,7 +48,7 @@ class autoProcessTV:
except:
return False
def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent = "manual", inputCategory=None, failureLink=None):
def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent = "manual", download_id=None, inputCategory=None, failureLink=None):
host = nzbtomedia.CFG[section][inputCategory]["host"]
port = nzbtomedia.CFG[section][inputCategory]["port"]
try:
@ -251,11 +251,14 @@ class autoProcessTV:
params = {'sortKey': 'series.title', 'page': 1, 'pageSize': 1, 'sortDir': 'asc'}
if remote_path:
logger.debug("remote_path: %s" % (remoteDir(dirName)),section)
data = json.dumps({"name": "DownloadedEpisodesScan", "path": remoteDir(dirName)})
data = {"name": "DownloadedEpisodesScan", "path": remoteDir(dirName), "downloadClientId": download_id}
else:
logger.debug("path: %s" % (dirName),section)
data = json.dumps({"name": "DownloadedEpisodesScan", "path": dirName})
data = {"name": "DownloadedEpisodesScan", "path": dirName, "downloadClientId": download_id}
if not download_id:
data.pop("downloadClientId")
data = json.dumps(data)
try:
if section == "SickBeard":
logger.debug("Opening URL: %s with params: %s" % (url, str(fork_params)), section)

View file

@ -809,6 +809,27 @@ def find_download(clientAgent, download_id):
return True
return False
def get_nzoid(inputName):
nzoid = None
logger.debug("Searching for nzoid from SAbnzbd ...")
baseURL = "http://%s:%s/api" % (nzbtomedia.SABNZBDHOST, nzbtomedia.SABNZBDPORT)
url = baseURL
params = {}
params['apikey'] = nzbtomedia.SABNZBDAPIKEY
params['mode'] = "queue"
params['output'] = 'json'
try:
r = requests.get(url, params=params, verify=False)
except requests.ConnectionError:
logger.error("Unable to open URL")
return nzoid # failure
result = r.json()
for slot in result['slots']:
if slot['filename'] == inputName:
nzoid = slot['nzo_id']
break
return nzoid
def cleanFileName(filename):
"""Cleans up nzb name by removing any . and _