diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 2b9b3dfd..65a14d99 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -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': diff --git a/nzbToMedia.py b/nzbToMedia.py index 15f893bb..d7deddb2 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -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'] diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index 2c5c4694..2ae9ebcb 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -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) diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index 1c25db4c..e9005c92 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -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 _