From 0e1437eb7eaedc8bac3ac78574a693fac605f0fd Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 11:52:43 -0400 Subject: [PATCH 01/17] Add encoding declaaration --- core/autoProcess/autoProcessComics.py | 2 ++ core/autoProcess/autoProcessGames.py | 2 ++ core/autoProcess/autoProcessMovie.py | 2 ++ core/autoProcess/autoProcessMusic.py | 2 ++ core/autoProcess/autoProcessTV.py | 2 ++ 5 files changed, 10 insertions(+) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 89060b62..7ca93957 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import os import time import core diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 7fa14227..7119a64b 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import core import requests import shutil diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 87dc2604..bd9b774d 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import os import time import requests diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 98fc390f..a60f3236 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import os import time import requests diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 7fa9abd5..76432fb2 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import copy import os import time From b7c7ec000b4d63879bb819cc37ea996b8ff0f415 Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 11:55:36 -0400 Subject: [PATCH 02/17] Add missing os import --- core/autoProcess/autoProcessGames.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 7119a64b..cdf972a8 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -1,5 +1,6 @@ # coding=utf-8 +import os import core import requests import shutil From d15fa76fc979a2b31f404d9667d2d11920bec1f8 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 04:26:09 -0400 Subject: [PATCH 03/17] Remove unused imports, unused variables, and redundant parentheses --- core/autoProcess/autoProcessComics.py | 3 --- core/autoProcess/autoProcessGames.py | 1 - core/autoProcess/autoProcessMovie.py | 2 +- core/autoProcess/autoProcessMusic.py | 2 +- core/autoProcess/autoProcessTV.py | 20 ++++++++------------ 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 7ca93957..d7b19089 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -1,13 +1,10 @@ # coding=utf-8 import os -import time import core import requests -import time from core.nzbToMediaUtil import convert_to_ascii, remoteDir, server_responding -from core.nzbToMediaSceneExceptions import process_all_exceptions from core import logger requests.packages.urllib3.disable_warnings() diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index cdf972a8..3c6d705b 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -6,7 +6,6 @@ import requests import shutil from core.nzbToMediaUtil import convert_to_ascii, server_responding -from core.nzbToMediaSceneExceptions import process_all_exceptions from core import logger requests.packages.urllib3.disable_warnings() diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index bd9b774d..df191a97 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -325,7 +325,7 @@ class autoProcessMovie: # we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. timeout = time.time() + 60 * wait_for - while (time.time() < timeout): # only wait 2 (default) minutes, then return. + while time.time() < timeout: # only wait 2 (default) minutes, then return. logger.postprocess("Checking for status change, please stand by ...", section) release = self.get_release(baseURL, imdbid, download_id, release_id) if release: diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index a60f3236..cd9ce649 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -132,7 +132,7 @@ class autoProcessMusic: # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing. timeout = time.time() + 60 * wait_for - while (time.time() < timeout): + while time.time() < timeout: current_status = self.get_status(url, apikey, dirName) if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie. logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status),section) diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 76432fb2..cdc081ef 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -18,7 +18,6 @@ requests.packages.urllib3.disable_warnings() class autoProcessTV: def command_complete(self, url, params, headers, section): - r = None try: r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: @@ -36,7 +35,6 @@ class autoProcessTV: return None def CDH(self, url2, headers): - r = None try: r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: @@ -150,8 +148,8 @@ class autoProcessTV: inputName, dirName = convert_to_ascii(inputName, dirName) if listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): # Check that a video exists. if not, assume failed. - flatten(dirName) - + flatten(dirName) + # Check video files for corruption status = int(failed) good_files = 0 @@ -161,7 +159,7 @@ class autoProcessTV: if transcoder.isVideoGood(video, status): good_files += 1 import_subs(video) - if num_files > 0: + if num_files > 0: if good_files == num_files and not status == 0: logger.info('Found Valid Videos. Setting status Success') status = 0 @@ -263,7 +261,7 @@ class autoProcessTV: url = "%s%s:%s%s/api/command" % (protocol, host, port, web_root) url2 = "%s%s:%s%s/api/config/downloadClient" % (protocol, host, port, web_root) headers = {"X-Api-Key": apikey} - params = {'sortKey': 'series.title', 'page': 1, 'pageSize': 1, 'sortDir': 'asc'} + # params = {'sortKey': 'series.title', 'page': 1, 'pageSize': 1, 'sortDir': 'asc'} if remote_path: logger.debug("remote_path: %s" % (remoteDir(dirName)),section) data = {"name": "DownloadedEpisodesScan", "path": remoteDir(dirName), "downloadClientId": download_id} @@ -273,11 +271,10 @@ class autoProcessTV: 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) - r = None s = requests.Session() login = "%s%s:%s%s/login" % (protocol,host,port,web_root) login_params = {'username': username, 'password': password} @@ -285,7 +282,6 @@ class autoProcessTV: r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800)) elif section == "NzbDrone": logger.debug("Opening URL: %s with data: %s" % (url, str(data)), section) - r = None r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800)) except requests.ConnectionError: logger.error("Unable to open URL: %s" % (url), section) @@ -299,7 +295,7 @@ class autoProcessTV: Started = False if section == "SickBeard": for line in r.iter_lines(): - if line: + if line: logger.postprocess("%s" % (line), section) if "Moving file from" in line: inputName = os.path.split(line)[1] @@ -329,7 +325,7 @@ class autoProcessTV: while n < 6: # set up wait_for minutes to see if command completes.. time.sleep(10 * wait_for) command_status = self.command_complete(url, params, headers, section) - if command_status and command_status in ['completed', 'failed']: + if command_status and command_status in ['completed', 'failed']: break n += 1 if command_status: @@ -345,7 +341,7 @@ class autoProcessTV: #return [1, "%s: Failed to post-process %s" % (section, inputName) ] if self.CDH(url2, headers): logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to %s." % (section), section) - return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section) ] + return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section) ] else: logger.warning("The Scan command did not return a valid status. Renaming was not successful.", section) return [1, "%s: Failed to post-process %s" % (section, inputName) ] From 230cc794d0f7a488d7826a821aa5539bf5203ab7 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:44:44 -0400 Subject: [PATCH 04/17] Fix spelling --- core/autoProcess/autoProcessComics.py | 2 +- core/autoProcess/autoProcessMovie.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index d7b19089..5a6b5039 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -44,7 +44,7 @@ class autoProcessComics: inputName, dirName = convert_to_ascii(inputName, dirName) clean_name, ext = os.path.splitext(inputName) - if len(ext) == 4: # we assume this was a standrard extension. + if len(ext) == 4: # we assume this was a standard extension. inputName = clean_name params = {} diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index df191a97..d5652bb3 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -17,7 +17,7 @@ class autoProcessMovie: results = {} params = {} - # determin cmd and params to send to CouchPotato to get our results + # determine cmd and params to send to CouchPotato to get our results section = 'movies' cmd = "/media.list" if release_id or imdbid: @@ -319,7 +319,7 @@ class autoProcessMovie: logger.postprocess("SUCCESS: Unable to find a new release to snatch now. CP will keep searching!", section) return [0, "%s: No new release found now. %s will keep searching" % (section, section) ] - # Added a releease that was not in the wanted list so confirm rename successful by finding this movie media.list. + # Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list. if not release: download_id = None # we don't want to filter new releases based on this. @@ -354,7 +354,7 @@ class autoProcessMovie: # pause and let CouchPotatoServer catch its breath time.sleep(10 * wait_for) - # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. + # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now. logger.warning( "%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for), section) From c7defa37daaf0c0f79006c6eac62c324040036ec Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 11:15:14 -0400 Subject: [PATCH 05/17] Fix faulty logic in conditional --- core/autoProcess/autoProcessComics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 5a6b5039..a6329de2 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -66,7 +66,7 @@ class autoProcessComics: return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] for line in r.iter_lines(): if line: logger.postprocess("%s" % (line), section) - if ("Post Processing SUCCESSFUL!" or "Post Processing SUCCESSFULL!")in line: success = True + if "Post Processing SUCCESSFUL" in line: success = True if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) From 0a1fe843062e2aa8dc1f9af5c52b786cb1f474b3 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:38:54 -0400 Subject: [PATCH 06/17] Convert to new-style class by inheriting from object --- core/autoProcess/autoProcessComics.py | 3 ++- core/autoProcess/autoProcessGames.py | 3 ++- core/autoProcess/autoProcessMovie.py | 7 ++++--- core/autoProcess/autoProcessMusic.py | 5 +++-- core/autoProcess/autoProcessTV.py | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index a6329de2..528eff25 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -9,7 +9,8 @@ from core import logger requests.packages.urllib3.disable_warnings() -class autoProcessComics: + +class autoProcessComics(object): def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): if int(status) != 0: logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.",section) diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 3c6d705b..1bce13aa 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -10,7 +10,8 @@ from core import logger requests.packages.urllib3.disable_warnings() -class autoProcessGames: + +class autoProcessGames(object): def process(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): status = int(status) diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index d5652bb3..6f62096e 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -12,7 +12,8 @@ from core.transcoder import transcoder requests.packages.urllib3.disable_warnings() -class autoProcessMovie: + +class autoProcessMovie(object): def get_release(self, baseURL, imdbid=None, download_id=None, release_id=None): results = {} params = {} @@ -46,7 +47,7 @@ class autoProcessMovie: if 'error' in result: logger.error(str(result['error'])) else: - logger.error("no media found for id %s" % (params['id'])) + logger.error("no media found for id %s" % (params['id'])) return results # Gather release info and return it back, no need to narrow results @@ -210,7 +211,7 @@ class autoProcessMovie: else: logger.error("Transcoding failed for files in %s" % (dirName), section) return [1, "%s: Failed to post-process - Transcoding failed" % (section) ] - for video in listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): + for video in listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): if not release and not ".cp(tt" in video and imdbid: videoName, videoExt = os.path.splitext(video) video2 = "%s.cp(%s)%s" % (videoName, imdbid, videoExt) diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index cd9ce649..ccebe177 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -11,7 +11,8 @@ from core import logger requests.packages.urllib3.disable_warnings() -class autoProcessMusic: + +class autoProcessMusic(object): def get_status(self, url, apikey, dirName): logger.debug("Attempting to get current status for release:%s" % (os.path.basename(dirName))) @@ -121,7 +122,7 @@ class autoProcessMusic: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] elif r.text == "OK": - logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName),section) + logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName),section) else: logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName),section) return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index cdc081ef..4237c101 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -16,7 +16,8 @@ from core.transcoder import transcoder requests.packages.urllib3.disable_warnings() -class autoProcessTV: + +class autoProcessTV(object): def command_complete(self, url, params, headers, section): try: r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60)) From 38ed3350ac43240b01d0f40785995cf960063d4a Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 11:59:25 -0400 Subject: [PATCH 07/17] PEP8: Fix formatting * Remove redundant backslash between brackets * Fix multiple statements on one line * Fix missing/excess whitespace * Fix comments not starting with a single `#` and a space * Convert tabs to spaces --- core/autoProcess/autoProcessComics.py | 24 ++++++----- core/autoProcess/autoProcessGames.py | 26 ++++++------ core/autoProcess/autoProcessMovie.py | 45 +++++++++++---------- core/autoProcess/autoProcessMusic.py | 39 +++++++++--------- core/autoProcess/autoProcessTV.py | 58 +++++++++++++-------------- 5 files changed, 97 insertions(+), 95 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 528eff25..f2f75f50 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -13,8 +13,8 @@ requests.packages.urllib3.disable_warnings() class autoProcessComics(object): def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): if int(status) != 0: - logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.",section) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] + logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.", section) + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] host = core.CFG[section][inputCategory]["host"] port = core.CFG[section][inputCategory]["port"] @@ -41,7 +41,7 @@ class autoProcessComics(object): url = "%s%s:%s%s/post_process" % (protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section) ] + return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] inputName, dirName = convert_to_ascii(inputName, dirName) clean_name, ext = os.path.splitext(inputName) @@ -64,18 +64,20 @@ class autoProcessComics(object): r = requests.get(url, auth=(username, password), params=params, stream=True, verify=False, timeout=(30, 300)) except requests.ConnectionError: logger.error("Unable to open URL", section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] for line in r.iter_lines(): - if line: logger.postprocess("%s" % (line), section) - if "Post Processing SUCCESSFUL" in line: success = True + if line: + logger.postprocess("%s" % (line), section) + if "Post Processing SUCCESSFUL" in line: + success = True if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] if success: - logger.postprocess("SUCCESS: This issue has been processed successfully",section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + logger.postprocess("SUCCESS: This issue has been processed successfully", section) + return [0, "%s: Successfully post-processed %s" % (section, inputName)] else: - logger.warning("The issue does not appear to have successfully processed. Please check your Logs",section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] + logger.warning("The issue does not appear to have successfully processed. Please check your Logs", section) + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 1bce13aa..2056cbbb 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -39,13 +39,13 @@ class autoProcessGames(object): url = "%s%s:%s%s/api" % (protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section) ] + return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] inputName, dirName = convert_to_ascii(inputName, dirName) fields = inputName.split("-") - gamezID = fields[0].replace("[","").replace("]","").replace(" ","") + gamezID = fields[0].replace("[", "").replace("]", "").replace(" ", "") downloadStatus = 'Wanted' if status == 0: @@ -57,33 +57,33 @@ class autoProcessGames(object): params['db_id'] = gamezID params['status'] = downloadStatus - logger.debug("Opening URL: %s" % (url),section) + logger.debug("Opening URL: %s" % (url), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 300)) except requests.ConnectionError: logger.error("Unable to open URL") - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() - logger.postprocess("%s" % (result),section) + logger.postprocess("%s" % (result), section) if library: - logger.postprocess("moving files to library: %s" % (library),section) + logger.postprocess("moving files to library: %s" % (library), section) try: shutil.move(dirName, os.path.join(library, inputName)) except: logger.error("Unable to move %s to %s" % (dirName, os.path.join(library, inputName)), section) - return [1, "%s: Failed to post-process - Unable to move files" % (section) ] + return [1, "%s: Failed to post-process - Unable to move files" % (section)] else: logger.error("No library specified to move files to. Please edit your configuration.", section) - return [1, "%s: Failed to post-process - No library defined in %s" % (section, section) ] + return [1, "%s: Failed to post-process - No library defined in %s" % (section, section)] if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: - logger.postprocess("SUCCESS: Status for %s has been set to %s in Gamez" % (gamezID, downloadStatus),section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + logger.postprocess("SUCCESS: Status for %s has been set to %s in Gamez" % (gamezID, downloadStatus), section) + return [0, "%s: Successfully post-processed %s" % (section, inputName)] else: - logger.error("FAILED: Status for %s has NOT been updated in Gamez" % (gamezID),section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] + logger.error("FAILED: Status for %s has NOT been updated in Gamez" % (gamezID), section) + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 6f62096e..42af0787 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -40,7 +40,7 @@ class autoProcessMovie(object): except: logger.error("CouchPotato returned the following non-json data") for line in r.iter_lines(): - logger.error("%s" %(line)) + logger.error("%s" % (line)) return results if not result['success']: @@ -56,7 +56,8 @@ class autoProcessMovie(object): id = result[section]['_id'] results[id] = result[section] return results - except:pass + except: + pass # Gather release info and proceed with trying to narrow results to one release choice @@ -135,7 +136,7 @@ class autoProcessMovie(object): baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey) if not server_responding(baseURL): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section) ] + return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] imdbid = find_imdbid(dirName, inputName) release = self.get_release(baseURL, imdbid, download_id) @@ -155,7 +156,7 @@ class autoProcessMovie(object): except: pass - if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. + if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] SpecificPath = os.path.join(dirName, str(inputName)) @@ -210,7 +211,7 @@ class autoProcessMovie(object): dirName = newDirName else: logger.error("Transcoding failed for files in %s" % (dirName), section) - return [1, "%s: Failed to post-process - Transcoding failed" % (section) ] + return [1, "%s: Failed to post-process - Transcoding failed" % (section)] for video in listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): if not release and not ".cp(tt" in video and imdbid: videoName, videoExt = os.path.splitext(video) @@ -244,20 +245,20 @@ class autoProcessMovie(object): r = requests.get(url, params=params, verify=False, timeout=(30, 1800)) except requests.ConnectionError: logger.error("Unable to open URL", section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) if method == "manage": - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] else: logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), section) - return [1, "%s: Failed to post-process - Server did not return success" % (section) ] + return [1, "%s: Failed to post-process - Server did not return success" % (section)] else: core.FAILED = True @@ -272,7 +273,7 @@ class autoProcessMovie(object): if not release_id and not media_id: logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % inputName, section) - return [1, "%s: Failed to post-process - Failed download not found in %s" % (section, section) ] + return [1, "%s: Failed to post-process - Failed download not found in %s" % (section, section)] if release_id: logger.postprocess("Setting failed release %s to ignored ..." % (inputName), section) @@ -286,17 +287,17 @@ class autoProcessMovie(object): r = requests.get(url, params=params, verify=False, timeout=(30, 120)) except requests.ConnectionError: logger.error("Unable to open URL %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: logger.postprocess("SUCCESS: %s has been set to ignored ..." % (inputName), section) else: logger.warning("FAILED: Unable to set %s to ignored!" % (inputName), section) - return [1, "%s: Failed to post-process - Unable to set %s to ignored" % (section, inputName) ] + return [1, "%s: Failed to post-process - Unable to set %s to ignored" % (section, inputName)] logger.postprocess("Trying to snatch the next highest ranked release.", section) @@ -307,18 +308,18 @@ class autoProcessMovie(object): r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600)) except requests.ConnectionError: logger.error("Unable to open URL %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: logger.postprocess("SUCCESS: Snatched the next highest release ...", section) - return [0, "%s: Successfully snatched next highest release" % (section) ] + return [0, "%s: Successfully snatched next highest release" % (section)] else: logger.postprocess("SUCCESS: Unable to find a new release to snatch now. CP will keep searching!", section) - return [0, "%s: No new release found now. %s will keep searching" % (section, section) ] + return [0, "%s: No new release found now. %s will keep searching" % (section, section)] # Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list. if not release: @@ -333,24 +334,24 @@ class autoProcessMovie(object): try: if release_id is None and release_status_old is None: # we didn't have a release before, but now we do. logger.postprocess("SUCCESS: Movie %s has now been added to CouchPotato" % (imdbid), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] release_status_new = release[release_id]['status'] if release_status_new != release_status_old: logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % ( inputName, str(release_status_new).upper()), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] except: pass if not os.path.isdir(dirName): logger.postprocess("SUCCESS: Input Directory [%s] has been processed and removed" % ( dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] elif not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=True): logger.postprocess("SUCCESS: Input Directory [%s] has no remaining media files. This has been fully processed." % ( dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] # pause and let CouchPotatoServer catch its breath time.sleep(10 * wait_for) @@ -359,4 +360,4 @@ class autoProcessMovie(object): logger.warning( "%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for), section) - return [1, "%s: Failed to post-process - No change in status" % (section) ] + return [1, "%s: Failed to post-process - No change in status" % (section)] diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index ccebe177..2936f9d4 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -32,7 +32,7 @@ class autoProcessMusic(object): result = r.json() for album in result: if os.path.basename(dirName) == album['FolderName']: - return album["Status"].lower() + return album["Status"].lower() except: return None @@ -66,13 +66,12 @@ class autoProcessMusic(object): else: protocol = "http://" - - url = "%s%s:%s%s/api" % (protocol,host,port,web_root) + url = "%s%s:%s%s/api" % (protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section) ] + return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] - if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. + if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] SpecificPath = os.path.join(dirName, str(inputName)) @@ -106,43 +105,43 @@ class autoProcessMusic(object): release_status = self.get_status(url, apikey, dirName) if not release_status: - logger.error("Could not find a status for %s, is it in the wanted list ?" % (inputName),section) + logger.error("Could not find a status for %s, is it in the wanted list ?" % (inputName), section) logger.debug("Opening URL: %s with PARAMS: %s" % (url, params), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 300)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % (url) ,section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + logger.error("Unable to open URL %s" % (url), section) + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] - logger.debug("Result: %s" % (r.text),section) + logger.debug("Result: %s" % (r.text), section) if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif r.text == "OK": - logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName),section) + logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName), section) else: - logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName),section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] + logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName), section) + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] else: logger.warning("FAILED DOWNLOAD DETECTED", section) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing. timeout = time.time() + 60 * wait_for while time.time() < timeout: current_status = self.get_status(url, apikey, dirName) if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie. - logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status),section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status), section) + return [0, "%s: Successfully post-processed %s" % (section, inputName)] if not os.path.isdir(dirName): - logger.postprocess("SUCCESS: The input directory %s has been removed Processing must have finished." % (dirName),section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + logger.postprocess("SUCCESS: The input directory %s has been removed Processing must have finished." % (dirName), section) + return [0, "%s: Successfully post-processed %s" % (section, inputName)] time.sleep(10 * wait_for) # The status hasn't changed. uTorrent can resume seeding now. - logger.warning("The music album does not appear to have changed status after %s minutes. Please check your Logs" % (wait_for),section) - return [1, "%s: Failed to post-process - No change in wanted status" % (section) ] + logger.warning("The music album does not appear to have changed status after %s minutes. Please check your Logs" % (wait_for), section) + return [1, "%s: Failed to post-process - No change in wanted status" % (section)] diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 4237c101..ac3005a6 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -51,7 +51,7 @@ class autoProcessTV(object): except: return False - def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent = "manual", download_id=None, inputCategory=None, failureLink=None): + def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent="manual", download_id=None, inputCategory=None, failureLink=None): host = core.CFG[section][inputCategory]["host"] port = core.CFG[section][inputCategory]["port"] try: @@ -66,9 +66,9 @@ class autoProcessTV(object): web_root = core.CFG[section][inputCategory]["web_root"] except: web_root = "" - if not server_responding("%s%s:%s%s" % (protocol,host,port,web_root)): + if not server_responding("%s%s:%s%s" % (protocol, host, port, web_root)): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section) ] + return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] # auto-detect correct fork fork, fork_params = autoFork(section, inputCategory) @@ -116,7 +116,7 @@ class autoProcessTV(object): except: extract = 0 - if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. + if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] SpecificPath = os.path.join(dirName, str(inputName)) @@ -136,7 +136,7 @@ class autoProcessTV(object): if e.errno != errno.EEXIST: raise - if not 'process_method' in fork_params or (clientAgent in ['nzbget','sabnzbd'] and nzbExtractionBy != "Destination"): + if not 'process_method' in fork_params or (clientAgent in ['nzbget', 'sabnzbd'] and nzbExtractionBy != "Destination"): if inputName: process_all_exceptions(inputName, dirName) inputName, dirName = convert_to_ascii(inputName, dirName) @@ -175,7 +175,7 @@ class autoProcessTV(object): failureLink = failureLink + '&corrupt=true' elif clientAgent == "manual": logger.warning("No media files found in directory %s to manually process." % (dirName), section) - return [0, ""] # Success (as far as this script is concerned) + return [0, ""] # Success (as far as this script is concerned) elif nzbExtractionBy == "Destination": logger.info("Check for media files ignored because nzbExtractionBy is set to Destination.") if int(failed) == 0: @@ -183,9 +183,9 @@ class autoProcessTV(object): status = 0 failed = 0 else: - logger.info("Downloader reported an error during download or verification. Processing this as a failed download.") - status = 1 - failed = 1 + logger.info("Downloader reported an error during download or verification. Processing this as a failed download.") + status = 1 + failed = 1 else: logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) status = 1 @@ -193,14 +193,14 @@ class autoProcessTV(object): if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') - if status == 0 and core.TRANSCODE == 1: # only transcode successful downloads + if status == 0 and core.TRANSCODE == 1: # only transcode successful downloads result, newDirName = transcoder.Transcode_directory(dirName) if result == 0: logger.debug("SUCCESS: Transcoding succeeded for files in %s" % (dirName), section) dirName = newDirName else: logger.error("FAILED: Transcoding failed for files in %s" % (dirName), section) - return [1, "%s: Failed to post-process - Transcoding failed" % (section) ] + return [1, "%s: Failed to post-process - Transcoding failed" % (section)] # configure SB params to pass fork_params['quiet'] = 1 @@ -235,7 +235,7 @@ class autoProcessTV(object): del fork_params[param] # delete any unused params so we don't pass them to SB by mistake - [fork_params.pop(k) for k,v in fork_params.items() if v is None] + [fork_params.pop(k) for k, v in fork_params.items() if v is None] if status == 0: logger.postprocess("SUCCESS: The download succeeded, sending a post-process request", section) @@ -247,27 +247,27 @@ class autoProcessTV(object): logger.postprocess("FAILED: The download failed. Sending 'failed' process request to %s branch" % (fork), section) elif section == "NzbDrone": logger.postprocess("FAILED: The download failed. Sending failed download to %s for CDH processing" % (fork), section) - return [1, "%s: Downlaod Failed. Sending back to %s" % (section, section) ] # Return as failed to flag this in the downloader. + return [1, "%s: Downlaod Failed. Sending back to %s" % (section, section)] # Return as failed to flag this in the downloader. else: logger.postprocess("FAILED: The download failed. %s branch does not handle failed downloads. Nothing to process" % (fork), section) if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: logger.postprocess("Deleting failed files and folder %s" % (dirName), section) rmDir(dirName) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] # Return as failed to flag this in the downloader. + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] # Return as failed to flag this in the downloader. url = None if section == "SickBeard": - url = "%s%s:%s%s/home/postprocess/processEpisode" % (protocol,host,port,web_root) + url = "%s%s:%s%s/home/postprocess/processEpisode" % (protocol, host, port, web_root) elif section == "NzbDrone": url = "%s%s:%s%s/api/command" % (protocol, host, port, web_root) url2 = "%s%s:%s%s/api/config/downloadClient" % (protocol, host, port, web_root) headers = {"X-Api-Key": apikey} # params = {'sortKey': 'series.title', 'page': 1, 'pageSize': 1, 'sortDir': 'asc'} if remote_path: - logger.debug("remote_path: %s" % (remoteDir(dirName)),section) + logger.debug("remote_path: %s" % (remoteDir(dirName)), section) data = {"name": "DownloadedEpisodesScan", "path": remoteDir(dirName), "downloadClientId": download_id} else: - logger.debug("path: %s" % (dirName),section) + logger.debug("path: %s" % (dirName), section) data = {"name": "DownloadedEpisodesScan", "path": dirName, "downloadClientId": download_id} if not download_id: data.pop("downloadClientId") @@ -277,7 +277,7 @@ class autoProcessTV(object): if section == "SickBeard": logger.debug("Opening URL: %s with params: %s" % (url, str(fork_params)), section) s = requests.Session() - login = "%s%s:%s%s/login" % (protocol,host,port,web_root) + login = "%s%s:%s%s/login" % (protocol, host, port, web_root) login_params = {'username': username, 'password': password} s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800)) @@ -286,11 +286,11 @@ class autoProcessTV(object): r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800)) except requests.ConnectionError: logger.error("Unable to open URL: %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] Success = False Started = False @@ -314,11 +314,11 @@ class autoProcessTV(object): Started = False if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: - logger.postprocess("Deleting failed files and folder %s" % (dirName),section) + logger.postprocess("Deleting failed files and folder %s" % (dirName), section) rmDir(dirName) if Success: - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] elif section == "NzbDrone" and Started: n = 0 params = {} @@ -327,24 +327,24 @@ class autoProcessTV(object): time.sleep(10 * wait_for) command_status = self.command_complete(url, params, headers, section) if command_status and command_status in ['completed', 'failed']: - break + break n += 1 if command_status: logger.debug("The Scan command return status: %s" % (command_status), section) if not os.path.exists(dirName): logger.debug("The directory %s has been removed. Renaming was successful." % (dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] elif command_status and command_status in ['completed']: logger.debug("The Scan command has completed successfully. Renaming was successful.", section) - return [0, "%s: Successfully post-processed %s" % (section, inputName) ] + return [0, "%s: Successfully post-processed %s" % (section, inputName)] elif command_status and command_status in ['failed']: logger.debug("The Scan command has failed. Renaming was not successful.", section) - #return [1, "%s: Failed to post-process %s" % (section, inputName) ] + # return [1, "%s: Failed to post-process %s" % (section, inputName) ] if self.CDH(url2, headers): logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to %s." % (section), section) - return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section) ] + return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section)] else: logger.warning("The Scan command did not return a valid status. Renaming was not successful.", section) - return [1, "%s: Failed to post-process %s" % (section, inputName) ] + return [1, "%s: Failed to post-process %s" % (section, inputName)] else: - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] # We did not receive Success confirmation. + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] # We did not receive Success confirmation. From 061a167b56722ef4b42ea4caaa86c2beb1b97edd Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:25:16 -0400 Subject: [PATCH 08/17] PEP8: Test for membership should be 'not in' --- core/autoProcess/autoProcessComics.py | 2 +- core/autoProcess/autoProcessGames.py | 2 +- core/autoProcess/autoProcessMovie.py | 8 ++++---- core/autoProcess/autoProcessMusic.py | 2 +- core/autoProcess/autoProcessTV.py | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index f2f75f50..10fe6ec9 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -71,7 +71,7 @@ class autoProcessComics(object): if "Post Processing SUCCESSFUL" in line: success = True - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 2056cbbb..a08a8675 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -78,7 +78,7 @@ class autoProcessGames(object): logger.error("No library specified to move files to. Please edit your configuration.", section) return [1, "%s: Failed to post-process - No library defined in %s" % (section, section)] - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 42af0787..773fda93 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -213,7 +213,7 @@ class autoProcessMovie(object): logger.error("Transcoding failed for files in %s" % (dirName), section) return [1, "%s: Failed to post-process - Transcoding failed" % (section)] for video in listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): - if not release and not ".cp(tt" in video and imdbid: + if not release and ".cp(tt" not in video and imdbid: videoName, videoExt = os.path.splitext(video) video2 = "%s.cp(%s)%s" % (videoName, imdbid, videoExt) if not (clientAgent in [core.TORRENT_CLIENTAGENT, 'manual'] and core.USELINK == 'move-sym'): @@ -248,7 +248,7 @@ class autoProcessMovie(object): return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: @@ -290,7 +290,7 @@ class autoProcessMovie(object): return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: @@ -311,7 +311,7 @@ class autoProcessMovie(object): return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] result = r.json() - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif result['success']: diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 2936f9d4..d5b79134 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -117,7 +117,7 @@ class autoProcessMusic(object): logger.debug("Result: %s" % (r.text), section) - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] elif r.text == "OK": diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index ac3005a6..a701f688 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -24,7 +24,7 @@ class autoProcessTV(object): except requests.ConnectionError: logger.error("Unable to open URL: %s" % (url1), section) return None - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return None else: @@ -41,7 +41,7 @@ class autoProcessTV(object): except requests.ConnectionError: logger.error("Unable to open URL: %s" % (url2), section) return False - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return False else: @@ -136,7 +136,7 @@ class autoProcessTV(object): if e.errno != errno.EEXIST: raise - if not 'process_method' in fork_params or (clientAgent in ['nzbget', 'sabnzbd'] and nzbExtractionBy != "Destination"): + if 'process_method' not in fork_params or (clientAgent in ['nzbget', 'sabnzbd'] and nzbExtractionBy != "Destination"): if inputName: process_all_exceptions(inputName, dirName) inputName, dirName = convert_to_ascii(inputName, dirName) @@ -288,7 +288,7 @@ class autoProcessTV(object): logger.error("Unable to open URL: %s" % (url), section) return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] - if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] From 948ead5408b1fc080f7dbbccc2cd5a405f727578 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:26:59 -0400 Subject: [PATCH 09/17] PEP8: comparison to None should be 'if cond is not None:' --- core/autoProcess/autoProcessComics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 10fe6ec9..9ac9e9f2 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -54,7 +54,7 @@ class autoProcessComics(object): if remote_path: params['nzb_folder'] = remoteDir(dirName) - if inputName != None: + if inputName is not None: params['nzb_name'] = inputName success = False From c5c5279a8b111beb7b720cff2e4a5ad2bb123769 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:33:50 -0400 Subject: [PATCH 10/17] PEP8: .has_key() is deprecated, use 'in' --- core/autoProcess/autoProcessMovie.py | 4 ++-- core/autoProcess/autoProcessTV.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 773fda93..79c01604 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -189,7 +189,7 @@ class autoProcessMovie(object): status = 0 elif num_files > 0 and good_files < num_files: logger.info("Status shown as success from Downloader, but corrupt video files found. Setting as failed.", section) - if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0': + if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if failureLink: failureLink = failureLink + '&corrupt=true' @@ -200,7 +200,7 @@ class autoProcessMovie(object): else: logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) status = 1 - if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0': + if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if status == 0: diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index a701f688..ab8a4247 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -169,7 +169,7 @@ class autoProcessTV(object): logger.info('Found corrupt videos. Setting status Failed') status = 1 failed = 1 - if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0': + if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if failureLink: failureLink = failureLink + '&corrupt=true' @@ -190,7 +190,7 @@ class autoProcessTV(object): logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) status = 1 failed = 1 - if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0': + if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if status == 0 and core.TRANSCODE == 1: # only transcode successful downloads From 03fa8bc973303ee0fcf1b286c5d7b38efe312f0e Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:35:25 -0400 Subject: [PATCH 11/17] Replace assignment with augmented assignment --- core/autoProcess/autoProcessMovie.py | 2 +- core/autoProcess/autoProcessTV.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 79c01604..0166db2e 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -192,7 +192,7 @@ class autoProcessMovie(object): if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if failureLink: - failureLink = failureLink + '&corrupt=true' + failureLink += '&corrupt=true' status = 1 elif clientAgent == "manual": logger.warning("No media files found in directory %s to manually process." % (dirName), section) diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index ab8a4247..1e7b7fbd 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -172,7 +172,7 @@ class autoProcessTV(object): if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') if failureLink: - failureLink = failureLink + '&corrupt=true' + failureLink += '&corrupt=true' elif clientAgent == "manual": logger.warning("No media files found in directory %s to manually process." % (dirName), section) return [0, ""] # Success (as far as this script is concerned) From 4a4087180b64601a5564738395b3baa5c2913ff1 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:40:30 -0400 Subject: [PATCH 12/17] Python 3: Convert 'except exceptClass, Target' to 'except exceptClass as Target' --- core/autoProcess/autoProcessMusic.py | 2 +- core/autoProcess/autoProcessTV.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index d5b79134..2255ac60 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -24,7 +24,7 @@ class autoProcessMusic(object): try: r = requests.get(url, params=params, verify=False, timeout=(30, 120)) - except Exception, e: + except Exception as e: logger.error("Unable to open URL") return None diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 1e7b7fbd..00d89538 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -131,7 +131,7 @@ class autoProcessTV(object): # won't process the directory because it doesn't exist. try: os.makedirs(dirName) # Attempt to create the directory - except OSError, e: + except OSError as e: # Re-raise the error if it wasn't about the directory not existing if e.errno != errno.EEXIST: raise From 8235134fad52af05ec26ed8a7492c6f9481a4efd Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:44:33 -0400 Subject: [PATCH 13/17] Rewrite dictionary creation as a dictionary literal --- core/autoProcess/autoProcessComics.py | 8 +++----- core/autoProcess/autoProcessGames.py | 11 ++++++----- core/autoProcess/autoProcessMusic.py | 19 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 9ac9e9f2..74ab1a78 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -48,11 +48,9 @@ class autoProcessComics(object): if len(ext) == 4: # we assume this was a standard extension. inputName = clean_name - params = {} - params['nzb_folder'] = dirName - - if remote_path: - params['nzb_folder'] = remoteDir(dirName) + params = { + 'nzb_folder': remoteDir(dirName) if remote_path else dirName, + } if inputName is not None: params['nzb_name'] = inputName diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index a08a8675..17c4ccf6 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -51,11 +51,12 @@ class autoProcessGames(object): if status == 0: downloadStatus = 'Downloaded' - params = {} - params['api_key'] = apikey - params['mode'] = 'UPDATEREQUESTEDSTATUS' - params['db_id'] = gamezID - params['status'] = downloadStatus + params = { + 'api_key': apikey, + 'mode': 'UPDATEREQUESTEDSTATUS', + 'db_id': gamezID, + 'status': downloadStatus + } logger.debug("Opening URL: %s" % (url), section) diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 2255ac60..501aa0f3 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -16,9 +16,10 @@ class autoProcessMusic(object): def get_status(self, url, apikey, dirName): logger.debug("Attempting to get current status for release:%s" % (os.path.basename(dirName))) - params = {} - params['apikey'] = apikey - params['cmd'] = "getHistory" + params = { + 'apikey': apikey, + 'cmd': "getHistory" + } logger.debug("Opening URL: %s with PARAMS: %s" % (url, params)) @@ -95,13 +96,11 @@ class autoProcessMusic(object): if status == 0: - params = {} - params['apikey'] = apikey - params['cmd'] = "forceProcess" - - params['dir'] = os.path.dirname(dirName) - if remote_path: - params['dir'] = remoteDir(os.path.dirname(dirName)) + params = { + 'apikey': apikey, + 'cmd': "forceProcess", + 'dir': remoteDir(os.path.dirname(dirName)) if remote_path else os.path.dirname(dirName) + } release_status = self.get_status(url, apikey, dirName) if not release_status: From 8880d11e8af761177e3811eacf633425e4225689 Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 03:49:34 -0400 Subject: [PATCH 14/17] Too broad exceptions. * Use .get() with default value instead. * Use ValueError to catch JSONDecodeError from simplejson and ValueError from json standard lib * Use request.RequestException instead. --- core/autoProcess/autoProcessComics.py | 15 ++---- core/autoProcess/autoProcessGames.py | 15 ++---- core/autoProcess/autoProcessMovie.py | 24 +++------ core/autoProcess/autoProcessMusic.py | 33 ++++-------- core/autoProcess/autoProcessTV.py | 77 ++++++++------------------- 5 files changed, 44 insertions(+), 120 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 74ab1a78..f7262985 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -20,18 +20,9 @@ class autoProcessComics(object): port = core.CFG[section][inputCategory]["port"] username = core.CFG[section][inputCategory]["username"] password = core.CFG[section][inputCategory]["password"] - try: - ssl = int(core.CFG[section][inputCategory]["ssl"]) - except: - ssl = 0 - try: - web_root = core.CFG[section][inputCategory]["web_root"] - except: - web_root = "" - try: - remote_path = int(core.CFG[section][inputCategory]["remote_path"]) - except: - remote_path = 0 + ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) + web_root = core.CFG[section][inputCategory].get("web_root", "") + remote_path = int(core.CFG[section][inputCategory].get("remote_path"), 0) if ssl: protocol = "https://" diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 17c4ccf6..fe0bc890 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -18,18 +18,9 @@ class autoProcessGames(object): host = core.CFG[section][inputCategory]["host"] port = core.CFG[section][inputCategory]["port"] apikey = core.CFG[section][inputCategory]["apikey"] - try: - library = core.CFG[section][inputCategory]["library"] - except: - library = None - try: - ssl = int(core.CFG[section][inputCategory]["ssl"]) - except: - ssl = 0 - try: - web_root = core.CFG[section][inputCategory]["web_root"] - except: - web_root = "" + library = core.CFG[section][inputCategory].get("library") + ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) + web_root = core.CFG[section][inputCategory].get("web_root", "") if ssl: protocol = "https://" diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 0166db2e..93180a71 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -37,7 +37,8 @@ class autoProcessMovie(object): try: result = r.json() - except: + except ValueError: + # ValueError catches simplejson's JSONDecodeError and json's ValueError logger.error("CouchPotato returned the following non-json data") for line in r.iter_lines(): logger.error("%s" % (line)) @@ -110,23 +111,10 @@ class autoProcessMovie(object): method = core.CFG[section][inputCategory]["method"] delete_failed = int(core.CFG[section][inputCategory]["delete_failed"]) wait_for = int(core.CFG[section][inputCategory]["wait_for"]) - - try: - ssl = int(core.CFG[section][inputCategory]["ssl"]) - except: - ssl = 0 - try: - web_root = core.CFG[section][inputCategory]["web_root"] - except: - web_root = "" - try: - remote_path = int(core.CFG[section][inputCategory]["remote_path"]) - except: - remote_path = 0 - try: - extract = int(section[inputCategory]["extract"]) - except: - extract = 0 + ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) + web_root = core.CFG[section][inputCategory].get("web_root", "") + remote_path = int(core.CFG[section][inputCategory].get("remote_path", 0)) + extract = int(section[inputCategory].get("extract", 0)) if ssl: protocol = "https://" diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 501aa0f3..65294eeb 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -25,18 +25,20 @@ class autoProcessMusic(object): try: r = requests.get(url, params=params, verify=False, timeout=(30, 120)) - except Exception as e: + except requests.RequestException: logger.error("Unable to open URL") return None try: result = r.json() - for album in result: - if os.path.basename(dirName) == album['FolderName']: - return album["Status"].lower() - except: + except ValueError: + # ValueError catches simplejson's JSONDecodeError and json's ValueError return None + for album in result: + if os.path.basename(dirName) == album['FolderName']: + return album["Status"].lower() + def process(self, section, dirName, inputName=None, status=0, clientAgent="manual", inputCategory=None): status = int(status) @@ -44,23 +46,10 @@ class autoProcessMusic(object): port = core.CFG[section][inputCategory]["port"] apikey = core.CFG[section][inputCategory]["apikey"] wait_for = int(core.CFG[section][inputCategory]["wait_for"]) - - try: - ssl = int(core.CFG[section][inputCategory]["ssl"]) - except: - ssl = 0 - try: - web_root = core.CFG[section][inputCategory]["web_root"] - except: - web_root = "" - try: - remote_path = int(core.CFG[section][inputCategory]["remote_path"]) - except: - remote_path = 0 - try: - extract = int(section[inputCategory]["extract"]) - except: - extract = 0 + ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) + web_root = core.CFG[section][inputCategory].get("web_root", "") + remote_path = int(core.CFG[section][inputCategory].get("remote_path", 0)) + extract = int(section[inputCategory].get("extract", 0)) if ssl: protocol = "https://" diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 00d89538..42b3d5ab 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -29,9 +29,9 @@ class autoProcessTV(object): return None else: try: - res = json.loads(r.content) - return res['state'] - except: + return r.json()['state'] + except (ValueError, KeyError): + # ValueError catches simplejson's JSONDecodeError and json's ValueError logger.error("%s did not return expected json data." % section, section) return None @@ -46,26 +46,22 @@ class autoProcessTV(object): return False else: try: - res = json.loads(r.content) - return res["enableCompletedDownloadHandling"] - except: + return r.json().get("enableCompletedDownloadHandling", False) + except ValueError: + # ValueError catches simplejson's JSONDecodeError and json's ValueError return False def processEpisode(self, section, dirName, inputName=None, failed=False, clientAgent="manual", download_id=None, inputCategory=None, failureLink=None): host = core.CFG[section][inputCategory]["host"] port = core.CFG[section][inputCategory]["port"] - try: - ssl = int(core.CFG[section][inputCategory]["ssl"]) - except: - ssl = 0 + ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) + web_root = core.CFG[section][inputCategory].get("web_root", "") + if ssl: protocol = "https://" else: protocol = "http://" - try: - web_root = core.CFG[section][inputCategory]["web_root"] - except: - web_root = "" + if not server_responding("%s%s:%s%s" % (protocol, host, port, web_root)): logger.error("Server did not respond. Exiting", section) return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] @@ -73,48 +69,17 @@ class autoProcessTV(object): # auto-detect correct fork fork, fork_params = autoFork(section, inputCategory) - try: - username = core.CFG[section][inputCategory]["username"] - password = core.CFG[section][inputCategory]["password"] - except: - username = "" - password = "" - try: - apikey = core.CFG[section][inputCategory]["apikey"] - except: - apikey = "" - try: - delete_failed = int(core.CFG[section][inputCategory]["delete_failed"]) - except: - delete_failed = 0 - try: - nzbExtractionBy = core.CFG[section][inputCategory]["nzbExtractionBy"] - except: - nzbExtractionBy = "Downloader" - try: - process_method = core.CFG[section][inputCategory]["process_method"] - except: - process_method = None - try: - remote_path = int(core.CFG[section][inputCategory]["remote_path"]) - except: - remote_path = 0 - try: - wait_for = int(core.CFG[section][inputCategory]["wait_for"]) - except: - wait_for = 2 - try: - force = int(core.CFG[section][inputCategory]["force"]) - except: - force = 0 - try: - delete_on = int(core.CFG[section][inputCategory]["delete_on"]) - except: - delete_on = 0 - try: - extract = int(section[inputCategory]["extract"]) - except: - extract = 0 + username = core.CFG[section][inputCategory].get("username", "") + password = core.CFG[section][inputCategory].get("password", "") + apikey = core.CFG[section][inputCategory].get("apikey", "") + delete_failed = int(core.CFG[section][inputCategory].get("delete_failed", 0)) + nzbExtractionBy = core.CFG[section][inputCategory].get("nzbExtractionBy", "Downloader") + process_method = core.CFG[section][inputCategory].get("process_method") + remote_path = int(core.CFG[section][inputCategory].get("remote_path", 0)) + wait_for = int(core.CFG[section][inputCategory].get("wait_for", 2)) + force = int(core.CFG[section][inputCategory].get("force", 0)) + delete_on = int(core.CFG[section][inputCategory].get("delete_on", 0)) + extract = int(section[inputCategory].get("extract", 0)) if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] From 88c9d742065e6c8ce379a28ac5a91b4f916af42f Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 04:09:14 -0400 Subject: [PATCH 15/17] Fix log message: * Renamed url1 to url * Added `section` argument to CDH * Removed undefined variable `good_files` --- core/autoProcess/autoProcessMusic.py | 2 +- core/autoProcess/autoProcessTV.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 65294eeb..be0be9c1 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -80,7 +80,7 @@ class autoProcessMusic(object): inputName, dirName = convert_to_ascii(inputName, dirName) if listMediaFiles(dirName, media=False, audio=True, meta=False, archives=False) and status: - logger.info("Status shown as failed from Downloader, but %s valid video files found. Setting as successful." % (str(good_files)), section) + logger.info("Status shown as failed from Downloader, but valid video files found. Setting as successful.", section) status = 0 if status == 0: diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 42b3d5ab..e261435e 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -22,7 +22,7 @@ class autoProcessTV(object): try: r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: - logger.error("Unable to open URL: %s" % (url1), section) + logger.error("Unable to open URL: %s" % url, section) return None if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) @@ -35,7 +35,7 @@ class autoProcessTV(object): logger.error("%s did not return expected json data." % section, section) return None - def CDH(self, url2, headers): + def CDH(self, url2, headers, section="MAIN"): try: r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: @@ -305,8 +305,8 @@ class autoProcessTV(object): elif command_status and command_status in ['failed']: logger.debug("The Scan command has failed. Renaming was not successful.", section) # return [1, "%s: Failed to post-process %s" % (section, inputName) ] - if self.CDH(url2, headers): - logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to %s." % (section), section) + if self.CDH(url2, headers, section=section): + logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to %s." % section, section) return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section)] else: logger.warning("The Scan command did not return a valid status. Renaming was not successful.", section) From 0c459613820bf3b971a70e5fc457bb7c52908cad Mon Sep 17 00:00:00 2001 From: labrys Date: Tue, 31 May 2016 04:42:49 -0400 Subject: [PATCH 16/17] Streamline variable assignment --- core/autoProcess/autoProcessComics.py | 6 +----- core/autoProcess/autoProcessGames.py | 10 ++-------- core/autoProcess/autoProcessMovie.py | 10 ++-------- core/autoProcess/autoProcessMusic.py | 6 +----- core/autoProcess/autoProcessTV.py | 6 +----- 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index f7262985..1a0fb43f 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -23,11 +23,7 @@ class autoProcessComics(object): ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) web_root = core.CFG[section][inputCategory].get("web_root", "") remote_path = int(core.CFG[section][inputCategory].get("remote_path"), 0) - - if ssl: - protocol = "https://" - else: - protocol = "http://" + protocol = "https://" if ssl else "http://" url = "%s%s:%s%s/post_process" % (protocol, host, port, web_root) if not server_responding(url): diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index fe0bc890..336c48b3 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -21,11 +21,7 @@ class autoProcessGames(object): library = core.CFG[section][inputCategory].get("library") ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) web_root = core.CFG[section][inputCategory].get("web_root", "") - - if ssl: - protocol = "https://" - else: - protocol = "http://" + protocol = "https://" if ssl else "http://" url = "%s%s:%s%s/api" % (protocol, host, port, web_root) if not server_responding(url): @@ -38,9 +34,7 @@ class autoProcessGames(object): gamezID = fields[0].replace("[", "").replace("]", "").replace(" ", "") - downloadStatus = 'Wanted' - if status == 0: - downloadStatus = 'Downloaded' + downloadStatus = 'Downloaded' if status == 0 else 'Wanted' params = { 'api_key': apikey, diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 93180a71..3ded9d24 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -115,11 +115,7 @@ class autoProcessMovie(object): web_root = core.CFG[section][inputCategory].get("web_root", "") remote_path = int(core.CFG[section][inputCategory].get("remote_path", 0)) extract = int(section[inputCategory].get("extract", 0)) - - if ssl: - protocol = "https://" - else: - protocol = "http://" + protocol = "https://" if ssl else "http://" baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey) if not server_responding(baseURL): @@ -213,9 +209,7 @@ class autoProcessMovie(object): params['downloader'] = downloader or clientAgent params['download_id'] = download_id - params['media_folder'] = dirName - if remote_path: - params['media_folder'] = remoteDir(dirName) + params['media_folder'] = remoteDir(dirName) if remote_path else dirName if method == "manage": command = "/manage.update" diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index be0be9c1..8ea22a3c 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -50,11 +50,7 @@ class autoProcessMusic(object): web_root = core.CFG[section][inputCategory].get("web_root", "") remote_path = int(core.CFG[section][inputCategory].get("remote_path", 0)) extract = int(section[inputCategory].get("extract", 0)) - - if ssl: - protocol = "https://" - else: - protocol = "http://" + protocol = "https://" if ssl else "http://" url = "%s%s:%s%s/api" % (protocol, host, port, web_root) if not server_responding(url): diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index e261435e..34d10df2 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -56,11 +56,7 @@ class autoProcessTV(object): port = core.CFG[section][inputCategory]["port"] ssl = int(core.CFG[section][inputCategory].get("ssl", 0)) web_root = core.CFG[section][inputCategory].get("web_root", "") - - if ssl: - protocol = "https://" - else: - protocol = "http://" + protocol = "https://" if ssl else "http://" if not server_responding("%s%s:%s%s" % (protocol, host, port, web_root)): logger.error("Server did not respond. Exiting", section) From 51d2c730543028d85c60c9fd0bad53995f392d9e Mon Sep 17 00:00:00 2001 From: Labrys Date: Tue, 31 May 2016 12:02:40 -0400 Subject: [PATCH 17/17] Use `format()` instead of `%` for string formatting --- core/autoProcess/autoProcessComics.py | 20 ++--- core/autoProcess/autoProcessGames.py | 30 +++---- core/autoProcess/autoProcessMovie.py | 112 +++++++++++++------------- core/autoProcess/autoProcessMusic.py | 44 +++++----- core/autoProcess/autoProcessTV.py | 90 ++++++++++----------- 5 files changed, 148 insertions(+), 148 deletions(-) diff --git a/core/autoProcess/autoProcessComics.py b/core/autoProcess/autoProcessComics.py index 1a0fb43f..b6e5b6ee 100644 --- a/core/autoProcess/autoProcessComics.py +++ b/core/autoProcess/autoProcessComics.py @@ -14,7 +14,7 @@ class autoProcessComics(object): def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): if int(status) != 0: logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.", section) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] + return [1, "{0}: Failed to post-process. {1} does not support failed downloads".format(section, section)] host = core.CFG[section][inputCategory]["host"] port = core.CFG[section][inputCategory]["port"] @@ -25,10 +25,10 @@ class autoProcessComics(object): remote_path = int(core.CFG[section][inputCategory].get("remote_path"), 0) protocol = "https://" if ssl else "http://" - url = "%s%s:%s%s/post_process" % (protocol, host, port, web_root) + url = "{0}{1}:{2}{3}/post_process".format(protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] + return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)] inputName, dirName = convert_to_ascii(inputName, dirName) clean_name, ext = os.path.splitext(inputName) @@ -44,25 +44,25 @@ class autoProcessComics(object): success = False - logger.debug("Opening URL: %s" % (url), section) + logger.debug("Opening URL: {0}".format(url), section) try: r = requests.get(url, auth=(username, password), params=params, stream=True, verify=False, timeout=(30, 300)) except requests.ConnectionError: logger.error("Unable to open URL", section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] for line in r.iter_lines(): if line: - logger.postprocess("%s" % (line), section) + logger.postprocess("{0}".format(line), section) if "Post Processing SUCCESSFUL" in line: success = True if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] if success: logger.postprocess("SUCCESS: This issue has been processed successfully", section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] else: logger.warning("The issue does not appear to have successfully processed. Please check your Logs", section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] + return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] diff --git a/core/autoProcess/autoProcessGames.py b/core/autoProcess/autoProcessGames.py index 336c48b3..ada32b11 100644 --- a/core/autoProcess/autoProcessGames.py +++ b/core/autoProcess/autoProcessGames.py @@ -23,10 +23,10 @@ class autoProcessGames(object): web_root = core.CFG[section][inputCategory].get("web_root", "") protocol = "https://" if ssl else "http://" - url = "%s%s:%s%s/api" % (protocol, host, port, web_root) + url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] + return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)] inputName, dirName = convert_to_ascii(inputName, dirName) @@ -43,33 +43,33 @@ class autoProcessGames(object): 'status': downloadStatus } - logger.debug("Opening URL: %s" % (url), section) + logger.debug("Opening URL: {0}".format(url), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 300)) except requests.ConnectionError: logger.error("Unable to open URL") - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] result = r.json() - logger.postprocess("%s" % (result), section) + logger.postprocess("{0}".format(result), section) if library: - logger.postprocess("moving files to library: %s" % (library), section) + logger.postprocess("moving files to library: {0}".format(library), section) try: shutil.move(dirName, os.path.join(library, inputName)) except: - logger.error("Unable to move %s to %s" % (dirName, os.path.join(library, inputName)), section) - return [1, "%s: Failed to post-process - Unable to move files" % (section)] + logger.error("Unable to move {0} to {1}".format(dirName, os.path.join(library, inputName)), section) + return [1, "{0}: Failed to post-process - Unable to move files".format(section)] else: logger.error("No library specified to move files to. Please edit your configuration.", section) - return [1, "%s: Failed to post-process - No library defined in %s" % (section, section)] + return [1, "{0}: Failed to post-process - No library defined in {1}".format(section, section)] if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] elif result['success']: - logger.postprocess("SUCCESS: Status for %s has been set to %s in Gamez" % (gamezID, downloadStatus), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + logger.postprocess("SUCCESS: Status for {0} has been set to {1} in Gamez".format(gamezID, downloadStatus), section) + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] else: - logger.error("FAILED: Status for %s has NOT been updated in Gamez" % (gamezID), section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] + logger.error("FAILED: Status for {0} has NOT been updated in Gamez".format(gamezID), section) + return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 3ded9d24..2c7dce17 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -27,12 +27,12 @@ class autoProcessMovie(object): params['id'] = release_id or imdbid url = baseURL + cmd - logger.debug("Opening URL: %s with PARAMS: %s" % (url, params)) + logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params)) try: r = requests.get(url, params=params, verify=False, timeout=(30, 60)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % url) + logger.error("Unable to open URL {0}".format(url)) return results try: @@ -41,14 +41,14 @@ class autoProcessMovie(object): # ValueError catches simplejson's JSONDecodeError and json's ValueError logger.error("CouchPotato returned the following non-json data") for line in r.iter_lines(): - logger.error("%s" % (line)) + logger.error("{0}".format(line)) return results if not result['success']: if 'error' in result: logger.error(str(result['error'])) else: - logger.error("no media found for id %s" % (params['id'])) + logger.error("no media found for id {0}".format(params['id'])) return results # Gather release info and return it back, no need to narrow results @@ -117,10 +117,10 @@ class autoProcessMovie(object): extract = int(section[inputCategory].get("extract", 0)) protocol = "https://" if ssl else "http://" - baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey) + baseURL = "{0}{1}:{2}{3}/api/{4}".format(protocol, host, port, web_root, apikey) if not server_responding(baseURL): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] + return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)] imdbid = find_imdbid(dirName, inputName) release = self.get_release(baseURL, imdbid, download_id) @@ -154,7 +154,7 @@ class autoProcessMovie(object): inputName, dirName = convert_to_ascii(inputName, dirName) if not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False) and listMediaFiles(dirName, media=False, audio=False, meta=False, archives=True) and extract: - logger.debug('Checking for archives to extract in directory: %s' % (dirName)) + logger.debug('Checking for archives to extract in directory: {0}'.format(dirName)) core.extractFiles(dirName) inputName, dirName = convert_to_ascii(inputName, dirName) @@ -169,7 +169,7 @@ class autoProcessMovie(object): good_files += 1 if num_files > 0 and good_files == num_files: if status: - logger.info("Status shown as failed from Downloader, but %s valid video files found. Setting as success." % (str(good_files)), section) + logger.info("Status shown as failed from Downloader, but {0} valid video files found. Setting as success.".format(good_files), section) status = 0 elif num_files > 0 and good_files < num_files: logger.info("Status shown as success from Downloader, but corrupt video files found. Setting as failed.", section) @@ -179,10 +179,10 @@ class autoProcessMovie(object): failureLink += '&corrupt=true' status = 1 elif clientAgent == "manual": - logger.warning("No media files found in directory %s to manually process." % (dirName), section) + logger.warning("No media files found in directory {0} to manually process.".format(dirName), section) return [0, ""] # Success (as far as this script is concerned) else: - logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) + logger.warning("No media files found in directory {0}. Processing this as a failed download".format(dirName), section) status = 1 if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': print('[NZB] MARK=BAD') @@ -191,17 +191,17 @@ class autoProcessMovie(object): if core.TRANSCODE == 1: result, newDirName = transcoder.Transcode_directory(dirName) if result == 0: - logger.debug("Transcoding succeeded for files in %s" % (dirName), section) + logger.debug("Transcoding succeeded for files in {0}".format(dirName), section) dirName = newDirName else: - logger.error("Transcoding failed for files in %s" % (dirName), section) - return [1, "%s: Failed to post-process - Transcoding failed" % (section)] + logger.error("Transcoding failed for files in {0}".format(dirName), section) + return [1, "{0}: Failed to post-process - Transcoding failed".format(section)] for video in listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): if not release and ".cp(tt" not in video and imdbid: videoName, videoExt = os.path.splitext(video) - video2 = "%s.cp(%s)%s" % (videoName, imdbid, videoExt) + video2 = "{0}.cp({1}){2}".format(videoName, imdbid, videoExt) if not (clientAgent in [core.TORRENT_CLIENTAGENT, 'manual'] and core.USELINK == 'move-sym'): - logger.debug('Renaming: %s to: %s' % (video, video2)) + logger.debug('Renaming: {0} to: {1}'.format(video, video2)) os.rename(video, video2) params = {} @@ -217,91 +217,91 @@ class autoProcessMovie(object): else: command = "/renamer.scan" - url = "%s%s" % (baseURL, command) + url = "{0}{1}".format(baseURL, command) - logger.debug("Opening URL: %s with PARAMS: %s" % (url, params), section) + logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section) - logger.postprocess("Starting %s scan for %s" % (method, inputName), section) + logger.postprocess("Starting {0} scan for {1}".format(method, inputName), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 1800)) except requests.ConnectionError: logger.error("Unable to open URL", section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] result = r.json() if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] elif result['success']: - logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) + logger.postprocess("SUCCESS: Finished {0} scan for folder {1}".format(method, dirName), section) if method == "manage": - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] else: - logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), + logger.error("FAILED: {0} scan was unable to finish for folder {1}. exiting!".format(method, dirName), section) - return [1, "%s: Failed to post-process - Server did not return success" % (section)] + return [1, "{0}: Failed to post-process - Server did not return success".format(section)] else: core.FAILED = True - logger.postprocess("FAILED DOWNLOAD DETECTED FOR %s" % (inputName), section) + logger.postprocess("FAILED DOWNLOAD DETECTED FOR {0}".format(inputName), section) if failureLink: reportNzb(failureLink, clientAgent) if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: - logger.postprocess("Deleting failed files and folder %s" % dirName, section) + logger.postprocess("Deleting failed files and folder {0}".format(dirName), section) rmDir(dirName) if not release_id and not media_id: - logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % inputName, + logger.error("Could not find a downloaded movie in the database matching {0}, exiting!".format(inputName), section) - return [1, "%s: Failed to post-process - Failed download not found in %s" % (section, section)] + return [1, "{0}: Failed to post-process - Failed download not found in {1}".format(section, section)] if release_id: - logger.postprocess("Setting failed release %s to ignored ..." % (inputName), section) + logger.postprocess("Setting failed release {0} to ignored ...".format(inputName), section) url = baseURL + "/release.ignore" params = {'id': release_id} - logger.debug("Opening URL: %s with PARAMS: %s" % (url, params), section) + logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 120)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + logger.error("Unable to open URL {0}".format(url), section) + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] result = r.json() if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] elif result['success']: - logger.postprocess("SUCCESS: %s has been set to ignored ..." % (inputName), section) + logger.postprocess("SUCCESS: {0} has been set to ignored ...".format(inputName), section) else: - logger.warning("FAILED: Unable to set %s to ignored!" % (inputName), section) - return [1, "%s: Failed to post-process - Unable to set %s to ignored" % (section, inputName)] + logger.warning("FAILED: Unable to set {0} to ignored!".format(inputName), section) + return [1, "{0}: Failed to post-process - Unable to set {1} to ignored".format(section, inputName)] logger.postprocess("Trying to snatch the next highest ranked release.", section) - url = "%s/movie.searcher.try_next" % (baseURL) - logger.debug("Opening URL: %s" % (url), section) + url = "{0}/movie.searcher.try_next".format(baseURL) + logger.debug("Opening URL: {0}".format(url), section) try: r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + logger.error("Unable to open URL {0}".format(url), section) + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] result = r.json() if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] elif result['success']: logger.postprocess("SUCCESS: Snatched the next highest release ...", section) - return [0, "%s: Successfully snatched next highest release" % (section)] + return [0, "{0}: Successfully snatched next highest release".format(section)] else: logger.postprocess("SUCCESS: Unable to find a new release to snatch now. CP will keep searching!", section) - return [0, "%s: No new release found now. %s will keep searching" % (section, section)] + return [0, "{0}: No new release found now. {1} will keep searching".format(section, section)] # Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list. if not release: @@ -315,31 +315,31 @@ class autoProcessMovie(object): if release: try: if release_id is None and release_status_old is None: # we didn't have a release before, but now we do. - logger.postprocess("SUCCESS: Movie %s has now been added to CouchPotato" % (imdbid), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + logger.postprocess("SUCCESS: Movie {0} has now been added to CouchPotato".format(imdbid), section) + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] release_status_new = release[release_id]['status'] if release_status_new != release_status_old: - logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % ( + logger.postprocess("SUCCESS: Release {0} has now been marked with a status of [{1}]".format( inputName, str(release_status_new).upper()), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] except: pass if not os.path.isdir(dirName): - logger.postprocess("SUCCESS: Input Directory [%s] has been processed and removed" % ( + logger.postprocess("SUCCESS: Input Directory [{0}] has been processed and removed".format( dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] elif not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=True): - logger.postprocess("SUCCESS: Input Directory [%s] has no remaining media files. This has been fully processed." % ( + logger.postprocess("SUCCESS: Input Directory [{0}] has no remaining media files. This has been fully processed.".format( dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] # pause and let CouchPotatoServer catch its breath time.sleep(10 * wait_for) # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now. logger.warning( - "%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for), + "{0} does not appear to have changed status after {1} minutes, Please check your logs.".format(inputName, wait_for), section) - return [1, "%s: Failed to post-process - No change in status" % (section)] + return [1, "{0}: Failed to post-process - No change in status".format(section)] diff --git a/core/autoProcess/autoProcessMusic.py b/core/autoProcess/autoProcessMusic.py index 8ea22a3c..f4ec185b 100644 --- a/core/autoProcess/autoProcessMusic.py +++ b/core/autoProcess/autoProcessMusic.py @@ -14,14 +14,14 @@ requests.packages.urllib3.disable_warnings() class autoProcessMusic(object): def get_status(self, url, apikey, dirName): - logger.debug("Attempting to get current status for release:%s" % (os.path.basename(dirName))) + logger.debug("Attempting to get current status for release:{0}".format(os.path.basename(dirName))) params = { 'apikey': apikey, 'cmd': "getHistory" } - logger.debug("Opening URL: %s with PARAMS: %s" % (url, params)) + logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params)) try: r = requests.get(url, params=params, verify=False, timeout=(30, 120)) @@ -52,10 +52,10 @@ class autoProcessMusic(object): extract = int(section[inputCategory].get("extract", 0)) protocol = "https://" if ssl else "http://" - url = "%s%s:%s%s/api" % (protocol, host, port, web_root) + url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root) if not server_responding(url): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] + return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)] if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] @@ -71,7 +71,7 @@ class autoProcessMusic(object): inputName, dirName = convert_to_ascii(inputName, dirName) if not listMediaFiles(dirName, media=False, audio=True, meta=False, archives=False) and listMediaFiles(dirName, media=False, audio=False, meta=False, archives=True) and extract: - logger.debug('Checking for archives to extract in directory: %s' % (dirName)) + logger.debug('Checking for archives to extract in directory: {0}'.format(dirName)) core.extractFiles(dirName) inputName, dirName = convert_to_ascii(inputName, dirName) @@ -89,43 +89,43 @@ class autoProcessMusic(object): release_status = self.get_status(url, apikey, dirName) if not release_status: - logger.error("Could not find a status for %s, is it in the wanted list ?" % (inputName), section) + logger.error("Could not find a status for {0}, is it in the wanted list ?".format(inputName), section) - logger.debug("Opening URL: %s with PARAMS: %s" % (url, params), section) + logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section) try: r = requests.get(url, params=params, verify=False, timeout=(30, 300)) except requests.ConnectionError: - logger.error("Unable to open URL %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + logger.error("Unable to open URL {0}".format(url), section) + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] - logger.debug("Result: %s" % (r.text), section) + logger.debug("Result: {0}".format(r.text), section) if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] elif r.text == "OK": - logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName), section) + logger.postprocess("SUCCESS: Post-Processing started for {0} in folder {1} ...".format(inputName, dirName), section) else: - logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName), section) - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] + logger.error("FAILED: Post-Processing has NOT started for {0} in folder {1}. exiting!".format(inputName, dirName), section) + return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] else: logger.warning("FAILED DOWNLOAD DETECTED", section) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] + return [1, "{0}: Failed to post-process. {1} does not support failed downloads".format(section, section)] # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing. timeout = time.time() + 60 * wait_for while time.time() < timeout: current_status = self.get_status(url, apikey, dirName) if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie. - logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + logger.postprocess("SUCCESS: This release is now marked as status [{0}]".format(current_status), section) + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] if not os.path.isdir(dirName): - logger.postprocess("SUCCESS: The input directory %s has been removed Processing must have finished." % (dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + logger.postprocess("SUCCESS: The input directory {0} has been removed Processing must have finished.".format(dirName), section) + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] time.sleep(10 * wait_for) # The status hasn't changed. uTorrent can resume seeding now. - logger.warning("The music album does not appear to have changed status after %s minutes. Please check your Logs" % (wait_for), section) - return [1, "%s: Failed to post-process - No change in wanted status" % (section)] + logger.warning("The music album does not appear to have changed status after {0} minutes. Please check your Logs".format(wait_for), section) + return [1, "{0}: Failed to post-process - No change in wanted status".format(section)] diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 34d10df2..030588a9 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -22,27 +22,27 @@ class autoProcessTV(object): try: r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: - logger.error("Unable to open URL: %s" % url, section) + logger.error("Unable to open URL: {0}".format(url), section) return None if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) + logger.error("Server returned status {0}".format(r.status_code), section) return None else: try: return r.json()['state'] except (ValueError, KeyError): # ValueError catches simplejson's JSONDecodeError and json's ValueError - logger.error("%s did not return expected json data." % section, section) + logger.error("{0} did not return expected json data.".format(section), section) return None def CDH(self, url2, headers, section="MAIN"): try: r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60)) except requests.ConnectionError: - logger.error("Unable to open URL: %s" % (url2), section) + logger.error("Unable to open URL: {0}".format(url2), section) return False if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) + logger.error("Server returned status {0}".format(r.status_code), section) return False else: try: @@ -58,9 +58,9 @@ class autoProcessTV(object): web_root = core.CFG[section][inputCategory].get("web_root", "") protocol = "https://" if ssl else "http://" - if not server_responding("%s%s:%s%s" % (protocol, host, port, web_root)): + if not server_responding("{0}{1}:{2}{3}".format(protocol, host, port, web_root)): logger.error("Server did not respond. Exiting", section) - return [1, "%s: Failed to post-process - %s did not respond." % (section, section)] + return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)] # auto-detect correct fork fork, fork_params = autoFork(section, inputCategory) @@ -105,7 +105,7 @@ class autoProcessTV(object): # Now check if tv files exist in destination. if not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): if listMediaFiles(dirName, media=False, audio=False, meta=False, archives=True) and extract: - logger.debug('Checking for archives to extract in directory: %s' % (dirName)) + logger.debug('Checking for archives to extract in directory: {0}'.format(dirName)) core.extractFiles(dirName) inputName, dirName = convert_to_ascii(inputName, dirName) @@ -135,7 +135,7 @@ class autoProcessTV(object): if failureLink: failureLink += '&corrupt=true' elif clientAgent == "manual": - logger.warning("No media files found in directory %s to manually process." % (dirName), section) + logger.warning("No media files found in directory {0} to manually process.".format(dirName), section) return [0, ""] # Success (as far as this script is concerned) elif nzbExtractionBy == "Destination": logger.info("Check for media files ignored because nzbExtractionBy is set to Destination.") @@ -148,7 +148,7 @@ class autoProcessTV(object): status = 1 failed = 1 else: - logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) + logger.warning("No media files found in directory {0}. Processing this as a failed download".format(dirName), section) status = 1 failed = 1 if 'NZBOP_VERSION' in os.environ and os.environ['NZBOP_VERSION'][0:5] >= '14.0': @@ -157,11 +157,11 @@ class autoProcessTV(object): if status == 0 and core.TRANSCODE == 1: # only transcode successful downloads result, newDirName = transcoder.Transcode_directory(dirName) if result == 0: - logger.debug("SUCCESS: Transcoding succeeded for files in %s" % (dirName), section) + logger.debug("SUCCESS: Transcoding succeeded for files in {0}".format(dirName), section) dirName = newDirName else: - logger.error("FAILED: Transcoding failed for files in %s" % (dirName), section) - return [1, "%s: Failed to post-process - Transcoding failed" % (section)] + logger.error("FAILED: Transcoding failed for files in {0}".format(dirName), section) + return [1, "{0}: Failed to post-process - Transcoding failed".format(section)] # configure SB params to pass fork_params['quiet'] = 1 @@ -205,30 +205,30 @@ class autoProcessTV(object): if failureLink: reportNzb(failureLink, clientAgent) if 'failed' in fork_params: - logger.postprocess("FAILED: The download failed. Sending 'failed' process request to %s branch" % (fork), section) + logger.postprocess("FAILED: The download failed. Sending 'failed' process request to {0} branch".format(fork), section) elif section == "NzbDrone": - logger.postprocess("FAILED: The download failed. Sending failed download to %s for CDH processing" % (fork), section) - return [1, "%s: Downlaod Failed. Sending back to %s" % (section, section)] # Return as failed to flag this in the downloader. + logger.postprocess("FAILED: The download failed. Sending failed download to {0} for CDH processing".format(fork), section) + return [1, "{0}: Downlaod Failed. Sending back to {1}".format(section, section)] # Return as failed to flag this in the downloader. else: - logger.postprocess("FAILED: The download failed. %s branch does not handle failed downloads. Nothing to process" % (fork), section) + logger.postprocess("FAILED: The download failed. {0} branch does not handle failed downloads. Nothing to process".format(fork), section) if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: - logger.postprocess("Deleting failed files and folder %s" % (dirName), section) + logger.postprocess("Deleting failed files and folder {0}".format(dirName), section) rmDir(dirName) - return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)] # Return as failed to flag this in the downloader. + return [1, "{0}: Failed to post-process. {1} does not support failed downloads".format(section, section)] # Return as failed to flag this in the downloader. url = None if section == "SickBeard": - url = "%s%s:%s%s/home/postprocess/processEpisode" % (protocol, host, port, web_root) + url = "{0}{1}:{2}{3}/home/postprocess/processEpisode".format(protocol, host, port, web_root) elif section == "NzbDrone": - url = "%s%s:%s%s/api/command" % (protocol, host, port, web_root) - url2 = "%s%s:%s%s/api/config/downloadClient" % (protocol, host, port, web_root) + url = "{0}{1}:{2}{3}/api/command".format(protocol, host, port, web_root) + url2 = "{0}{1}:{2}{3}/api/config/downloadClient".format(protocol, host, port, web_root) headers = {"X-Api-Key": apikey} # params = {'sortKey': 'series.title', 'page': 1, 'pageSize': 1, 'sortDir': 'asc'} if remote_path: - logger.debug("remote_path: %s" % (remoteDir(dirName)), section) + logger.debug("remote_path: {0}".format(remoteDir(dirName)), section) data = {"name": "DownloadedEpisodesScan", "path": remoteDir(dirName), "downloadClientId": download_id} else: - logger.debug("path: %s" % (dirName), section) + logger.debug("path: {0}".format(dirName), section) data = {"name": "DownloadedEpisodesScan", "path": dirName, "downloadClientId": download_id} if not download_id: data.pop("downloadClientId") @@ -236,29 +236,29 @@ class autoProcessTV(object): try: if section == "SickBeard": - logger.debug("Opening URL: %s with params: %s" % (url, str(fork_params)), section) + logger.debug("Opening URL: {0} with params: {1}".format(url, fork_params), section) s = requests.Session() - login = "%s%s:%s%s/login" % (protocol, host, port, web_root) + login = "{0}{1}:{2}{3}/login".format(protocol, host, port, web_root) login_params = {'username': username, 'password': password} s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800)) elif section == "NzbDrone": - logger.debug("Opening URL: %s with data: %s" % (url, str(data)), section) + logger.debug("Opening URL: {0} with data: {1}".format(url, data), section) r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800)) except requests.ConnectionError: - logger.error("Unable to open URL: %s" % (url), section) - return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section)] + logger.error("Unable to open URL: {0}".format(url), section) + return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)] if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: - logger.error("Server returned status %s" % (str(r.status_code)), section) - return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code))] + logger.error("Server returned status {0}".format(r.status_code), section) + return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)] Success = False Started = False if section == "SickBeard": for line in r.iter_lines(): if line: - logger.postprocess("%s" % (line), section) + logger.postprocess("{0}".format(line), section) if "Moving file from" in line: inputName = os.path.split(line)[1] if "Processing succeeded" in line or "Successfully processed" in line: @@ -267,23 +267,23 @@ class autoProcessTV(object): try: res = json.loads(r.content) scan_id = int(res['id']) - logger.debug("Scan started with id: %s" % (str(scan_id)), section) + logger.debug("Scan started with id: {0}".format(scan_id), section) Started = True except Exception as e: - logger.warning("No scan id was returned due to: %s" % (e), section) + logger.warning("No scan id was returned due to: {0}".format(e), section) scan_id = None Started = False if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: - logger.postprocess("Deleting failed files and folder %s" % (dirName), section) + logger.postprocess("Deleting failed files and folder {0}".format(dirName), section) rmDir(dirName) if Success: - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] elif section == "NzbDrone" and Started: n = 0 params = {} - url = url + "/" + str(scan_id) + url = "{0}/{1}".format(url, scan_id) while n < 6: # set up wait_for minutes to see if command completes.. time.sleep(10 * wait_for) command_status = self.command_complete(url, params, headers, section) @@ -291,21 +291,21 @@ class autoProcessTV(object): break n += 1 if command_status: - logger.debug("The Scan command return status: %s" % (command_status), section) + logger.debug("The Scan command return status: {0}".format(command_status), section) if not os.path.exists(dirName): - logger.debug("The directory %s has been removed. Renaming was successful." % (dirName), section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + logger.debug("The directory {0} has been removed. Renaming was successful.".format(dirName), section) + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] elif command_status and command_status in ['completed']: logger.debug("The Scan command has completed successfully. Renaming was successful.", section) - return [0, "%s: Successfully post-processed %s" % (section, inputName)] + return [0, "{0}: Successfully post-processed {1}".format(section, inputName)] elif command_status and command_status in ['failed']: logger.debug("The Scan command has failed. Renaming was not successful.", section) # return [1, "%s: Failed to post-process %s" % (section, inputName) ] if self.CDH(url2, headers, section=section): - logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to %s." % section, section) - return [status, "%s: Complete DownLoad Handling is enabled. Passing back to %s" % (section, section)] + logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section) + return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)] else: logger.warning("The Scan command did not return a valid status. Renaming was not successful.", section) - return [1, "%s: Failed to post-process %s" % (section, inputName)] + return [1, "{0}: Failed to post-process {1}".format(section, inputName)] else: - return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)] # We did not receive Success confirmation. + return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)] # We did not receive Success confirmation.