From d2e3275562969e067b64167dc3d3b73a8b588842 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 12 Apr 2014 05:51:37 -0700 Subject: [PATCH] Fixed bugs in nzbTo* scripts. autoProcessTV now gets movie_id even for previously post-processed movies so that we can skip further post-processing gracefully. Code cleanup misc ... --- nzbToCouchPotato.py | 24 ++++++++++----------- nzbToGamez.py | 24 ++++++++++----------- nzbToHeadPhones.py | 24 ++++++++++----------- nzbToMylar.py | 16 +++++++------- nzbToNzbDrone.py | 24 ++++++++++----------- nzbToSickBeard.py | 24 ++++++++++----------- nzbtomedia/autoProcess/autoProcessComics.py | 2 -- nzbtomedia/autoProcess/autoProcessGames.py | 2 -- nzbtomedia/autoProcess/autoProcessMovie.py | 13 +++++++---- nzbtomedia/autoProcess/autoProcessMusic.py | 2 -- nzbtomedia/autoProcess/autoProcessTV.py | 2 -- 11 files changed, 77 insertions(+), 80 deletions(-) diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index 9f9f9632..4a51a3ed 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -210,20 +210,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessMovie().process(sys.argv[1], sys.argv[2], status=sys.argv[7], inputCategory=sys.argv[5], clientAgent = "sabnzbd", download_id='') else: result = 0 + section = "CouchPotato" logger.warning("Invalid number of arguments received from client.") - for section, subsection in nzbtomedia.SUBSECTIONS['CouchPotato'].items(): - for category in subsection: - if nzbtomedia.CFG[section][category].isenabled(): - dirNames = get_dirnames(section, category) - for dirName in dirNames: - logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessMovie().process(dirName, os.path.basename(dirName), 0, inputCategory=category) - if results != 0: - result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) - else: - logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) + for dirName in dirNames: + logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessMovie().process(dirName, os.path.basename(dirName), 0, inputCategory=subsection) + if results != 0: + result = results + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) + else: + logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The script completed successfully.") diff --git a/nzbToGamez.py b/nzbToGamez.py index 70fb4685..4c9d5179 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -144,20 +144,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessGames().process(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: result = 0 + section = "Gamez" logger.warning("Invalid number of arguments received from client.") - for section, subsection in nzbtomedia.SUBSECTIONS['Gamez'].items(): - for category in subsection: - if nzbtomedia.CFG[section][category].isenabled(): - dirNames = get_dirnames(section, category) - for dirName in dirNames: - logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessGames().process(dirName, os.path.basename(dirName), 0, inputCategory=category) - if results != 0: - result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) - else: - logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) + for dirName in dirNames: + logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessGames().process(dirName, os.path.basename(dirName), 0, inputCategory=subsection) + if results != 0: + result = results + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) + else: + logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The script completed successfully.") diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index 98e64132..a6244ac8 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -154,20 +154,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessMusic().process(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: result = 0 + section = "HeadPhones" logger.warning("Invalid number of arguments received from client.") - for section, subsection in nzbtomedia.SUBSECTIONS['HeadPhones'].items(): - for category in subsection: - if nzbtomedia.CFG[section][category].isenabled(): - dirNames = get_dirnames(section, category) - for dirName in dirNames: - logger.postprocess("nzbToHeadPhones running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessMusic().process(dirName, os.path.basename(dirName), 0, inputCategory=category) - if results != 0: - result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) - else: - logger.postprocess("nzbToHeadPhones %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) + for dirName in dirNames: + logger.postprocess("nzbToHeadPhones running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessMusic().process(dirName, os.path.basename(dirName), 0, inputCategory=subsection) + if results != 0: + result = results + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) + else: + logger.postprocess("nzbToHeadPhones %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The autoProcessMusic script completed successfully.") diff --git a/nzbToMylar.py b/nzbToMylar.py index 2752eb53..37444783 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -151,20 +151,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessComics().processEpisode(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: result = 0 + section = "Mylar" logger.warning("Invalid number of arguments received from client.") - section = "Mylar" - for category in nzbtomedia.SUBSECTIONS[section]: - if nzbtomedia.SUBSECTIONS[section][category].isenabled(): - dirNames = get_dirnames(section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) for dirName in dirNames: - logger.postprocess("nzbToMylar running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessComics().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=category) + logger.postprocess("nzbToMylar running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessComics().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=subsection) if results != 0: result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) else: - logger.postprocess("nzbToMylar %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + logger.postprocess("nzbToMylar %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The autoProcessComics script completed successfully.") diff --git a/nzbToNzbDrone.py b/nzbToNzbDrone.py index c28849e1..4193a3e5 100755 --- a/nzbToNzbDrone.py +++ b/nzbToNzbDrone.py @@ -181,20 +181,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessTV().processEpisode(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: result = 0 + section = "NzbDrone" logger.warning("Invalid number of arguments received from client.") - for section, subsection in nzbtomedia.SUBSECTIONS['NzbDrone'].items(): - for category in subsection: - if nzbtomedia.CFG[section][category].isenabled(): - dirNames = get_dirnames(section, category) - for dirName in dirNames: - logger.postprocess("nzbToNzbDrone running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessTV().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=category) - if results != 0: - result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) - else: - logger.postprocess("nzbToNzbDrone %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) + for dirName in dirNames: + logger.postprocess("nzbToNzbDrone running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessTV().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=subsection) + if results != 0: + result = results + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) + else: + logger.postprocess("nzbToNzbDrone %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The autoProcessTV script completed successfully.") diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 8a25990f..901f2f71 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -214,20 +214,20 @@ elif len(sys.argv) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: result = autoProcessTV().processEpisode(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent, sys.argv[5]) else: result = 0 + section = "SickBeard" logger.warning("Invalid number of arguments received from client.") - for section, subsection in nzbtomedia.SUBSECTIONS['SickBeard'].items(): - for category in subsection: - if nzbtomedia.CFG[section][category].isenabled(): - dirNames = get_dirnames(section, category) - for dirName in dirNames: - logger.postprocess("nzbToSickBeard running %s:%s as a manual run on folder %s ...", section, category, dirName) - results = autoProcessTV().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=category) - if results != 0: - result = results - logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, category, dirName) - else: - logger.postprocess("nzbToSickBeard %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category) + for subsection in nzbtomedia.CFG[section]: + if nzbtomedia.CFG[section][subsection].isenabled(): + dirNames = get_dirnames(section, subsection) + for dirName in dirNames: + logger.postprocess("nzbToSickBeard running %s:%s as a manual run on folder %s ...", section, subsection, dirName) + results = autoProcessTV().processEpisode(dirName, os.path.basename(dirName), 0, inputCategory=subsection) + if results != 0: + result = results + logger.error("A problem was reported when trying to manually run %s:%s on folder %s ...", section, subsection, dirName) + else: + logger.postprocess("nzbToSickBeard %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, subsection) if result == 0: logger.postprocess("The autoProcessTV script completed successfully.") diff --git a/nzbtomedia/autoProcess/autoProcessComics.py b/nzbtomedia/autoProcess/autoProcessComics.py index 64a0a74d..3690e238 100644 --- a/nzbtomedia/autoProcess/autoProcessComics.py +++ b/nzbtomedia/autoProcess/autoProcessComics.py @@ -18,8 +18,6 @@ class autoProcessComics: "We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory) return 1 - logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE) - host = nzbtomedia.CFG[section][inputCategory]["host"] port = nzbtomedia.CFG[section][inputCategory]["port"] username = nzbtomedia.CFG[section][inputCategory]["username"] diff --git a/nzbtomedia/autoProcess/autoProcessGames.py b/nzbtomedia/autoProcess/autoProcessGames.py index 318054ca..364ed88f 100644 --- a/nzbtomedia/autoProcess/autoProcessGames.py +++ b/nzbtomedia/autoProcess/autoProcessGames.py @@ -17,8 +17,6 @@ class autoProcessGames: "We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory) return 1 - logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE) - status = int(status) host = nzbtomedia.CFG[section][inputCategory]["host"] diff --git a/nzbtomedia/autoProcess/autoProcessMovie.py b/nzbtomedia/autoProcess/autoProcessMovie.py index c6c59349..3aab0df4 100644 --- a/nzbtomedia/autoProcess/autoProcessMovie.py +++ b/nzbtomedia/autoProcess/autoProcessMovie.py @@ -52,7 +52,7 @@ class autoProcessMovie: return movie_id, imdbid, download_id, movie_status, release_status while True: - url = baseURL + "media.list/?status=active&release_status=snatched&limit_offset=50," + str(offset) + url = baseURL + "media.list/?limit_offset=50," + str(offset) logger.debug("Opening URL: %s", url) @@ -90,13 +90,16 @@ class autoProcessMovie: releaselist1 = [item for item in release[index] if item["status"] == "snatched" and "download_info" in item] if download_id: releaselist = [item for item in releaselist1 if item["download_info"]["id"].lower() == download_id.lower()] - else: + elif len(releaselist1) > 0: releaselist = releaselist1 + else: + releaselist = [item for item in release[index] if item["status"] == "downloaded" and "download_info" in item] if imdbid and library[index] == imdbid: movie_id = str(movieid[index]) movie_status = str(moviestatus[index]) logger.postprocess("Found movie id %s with status %s in CPS database for movie %s", movie_id, movie_status, imdbid) + if not download_id and len(releaselist) == 1: download_id = releaselist[0]["download_info"]["id"] @@ -169,8 +172,6 @@ class autoProcessMovie: "We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory) return 1 - logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE) - status = int(status) host = nzbtomedia.CFG[section][inputCategory]["host"] @@ -219,6 +220,10 @@ class autoProcessMovie: movie_id, imdbid, download_id, initial_status, initial_release_status = self.get_movie_postprocess(baseURL, imdbid, download_id) # get the CPS database movie id for this movie. + if initial_release_status == "downloaded": + logger.postprocess("This movie has already been post-processed by CouchPotatoServer, skipping ...") + return 0 + process_all_exceptions(nzbName.lower(), dirName) nzbName, dirName = convert_to_ascii(nzbName, dirName) diff --git a/nzbtomedia/autoProcess/autoProcessMusic.py b/nzbtomedia/autoProcess/autoProcessMusic.py index 3ac698b0..8a071203 100644 --- a/nzbtomedia/autoProcess/autoProcessMusic.py +++ b/nzbtomedia/autoProcess/autoProcessMusic.py @@ -20,8 +20,6 @@ class autoProcessMusic: "We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory) return 1 - logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE) - status = int(status) host = nzbtomedia.CFG[section][inputCategory]["host"] diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index b429191d..c42dbdaf 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -28,8 +28,6 @@ class autoProcessTV: # auto-detect correct fork fork, fork_params = autoFork(inputCategory) - logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE) - status = int(failed) host = nzbtomedia.CFG[section][inputCategory]["host"]