From 6cc0d384833d1693c8c044f237a3d1530ee1ca46 Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 7 Apr 2014 03:48:12 -0700 Subject: [PATCH] Added in NzbDrone support! --- autoProcessMedia.cfg.sample | 1 + nzbToSickBeard.py | 2 +- nzbtomedia/autoProcess/autoProcessTV.py | 24 ++++++++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/autoProcessMedia.cfg.sample b/autoProcessMedia.cfg.sample index 47963470..4c9e323e 100644 --- a/autoProcessMedia.cfg.sample +++ b/autoProcessMedia.cfg.sample @@ -47,6 +47,7 @@ #### ndCategory - category that gets called for post-processing with NzbDrone [[tv]] enabled = 0 + apikey = host = localhost port = 8989 username = diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index b51a9754..3d6e814d 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -230,7 +230,7 @@ else: result = 0 # init sub-sections - subsections = config.get_subsections(["SickBeard", "NzbDrone"]) + subsections = config.get_subsections(["SickBeard"]) Logger.warn("MAIN: Invalid number of arguments received from client.") for section, subsection in subsections.items(): diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index 83479244..2324387e 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -1,4 +1,5 @@ import copy +import json import logging import os import socket @@ -47,6 +48,11 @@ class autoProcessTV: username = config()[section][inputCategory]["username"] password = config()[section][inputCategory]["password"] + try: + apikey = config()[section][inputCategory]["apikey"] + except: + apikey = "" + try: ssl = int(config()[section][inputCategory]["ssl"]) except: @@ -162,7 +168,7 @@ class autoProcessTV: [fork_params.pop(k) for k,v in fork_params.items() if v is None] if status == 0: - Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork) + Logger.info("The download succeeded. Sending process request to %s", section) elif fork in config.SICKBEARD_FAILED: Logger.info("The download failed. Sending 'failed' process request to SickBeard's %s branch", fork) else: @@ -184,17 +190,27 @@ class autoProcessTV: else: protocol = "http://" - url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork_params) + + url = None + if section == "SickBeard": + url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork_params) + elif section == "NzbDrone": + url = protocol + host + ":" + port + web_root + "/api/command" if clientAgent == "manual":delay = 0 - Logger.info("Waiting for %s seconds to allow SB to process newly extracted files", str(delay)) + Logger.info("Waiting for %s seconds to allow %s to process newly extracted files", str(delay), section) time.sleep(delay) Logger.debug("Opening URL: %s", url) try: - r = requests.get(url, auth=(username, password), stream=True) + if section == "SickBeard": + r = requests.get(url, auth=(username, password), stream=True) + elif section == "NzbDrone": + data = json.dumps({"name": "DownloadedEpisodesScan", "path": dirName}) + headers = {"X-Api-Key": apikey} + r = requests.get(url, data=data, headers=headers, stream=True) except requests.ConnectionError: Logger.exception("Unable to open URL") return 1 # failure