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
This commit is contained in:
Labrys 2016-05-31 11:59:25 -04:00
parent 0a1fe84306
commit 38ed3350ac
5 changed files with 97 additions and 95 deletions

View file

@ -13,8 +13,8 @@ requests.packages.urllib3.disable_warnings()
class autoProcessComics(object): class autoProcessComics(object):
def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None):
if int(status) != 0: if int(status) != 0:
logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.",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) ] return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section)]
host = core.CFG[section][inputCategory]["host"] host = core.CFG[section][inputCategory]["host"]
port = core.CFG[section][inputCategory]["port"] 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) url = "%s%s:%s%s/post_process" % (protocol, host, port, web_root)
if not server_responding(url): if not server_responding(url):
logger.error("Server did not respond. Exiting", section) 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) inputName, dirName = convert_to_ascii(inputName, dirName)
clean_name, ext = os.path.splitext(inputName) 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)) r = requests.get(url, auth=(username, password), params=params, stream=True, verify=False, timeout=(30, 300))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL", section) 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(): for line in r.iter_lines():
if line: logger.postprocess("%s" % (line), section) if line:
if "Post Processing SUCCESSFUL" in line: success = True 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]: 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) 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: if success:
logger.postprocess("SUCCESS: This issue has been processed successfully",section) logger.postprocess("SUCCESS: This issue has been processed successfully", section)
return [0, "%s: Successfully post-processed %s" % (section, inputName) ] return [0, "%s: Successfully post-processed %s" % (section, inputName)]
else: else:
logger.warning("The issue does not appear to have successfully processed. Please check your Logs",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) ] return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)]

View file

@ -39,13 +39,13 @@ class autoProcessGames(object):
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): if not server_responding(url):
logger.error("Server did not respond. Exiting", section) 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) inputName, dirName = convert_to_ascii(inputName, dirName)
fields = inputName.split("-") fields = inputName.split("-")
gamezID = fields[0].replace("[","").replace("]","").replace(" ","") gamezID = fields[0].replace("[", "").replace("]", "").replace(" ", "")
downloadStatus = 'Wanted' downloadStatus = 'Wanted'
if status == 0: if status == 0:
@ -57,33 +57,33 @@ class autoProcessGames(object):
params['db_id'] = gamezID params['db_id'] = gamezID
params['status'] = downloadStatus params['status'] = downloadStatus
logger.debug("Opening URL: %s" % (url),section) logger.debug("Opening URL: %s" % (url), section)
try: try:
r = requests.get(url, params=params, verify=False, timeout=(30, 300)) r = requests.get(url, params=params, verify=False, timeout=(30, 300))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL") 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() result = r.json()
logger.postprocess("%s" % (result),section) logger.postprocess("%s" % (result), section)
if library: if library:
logger.postprocess("moving files to library: %s" % (library),section) logger.postprocess("moving files to library: %s" % (library), section)
try: try:
shutil.move(dirName, os.path.join(library, inputName)) shutil.move(dirName, os.path.join(library, inputName))
except: except:
logger.error("Unable to move %s to %s" % (dirName, os.path.join(library, inputName)), section) 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: else:
logger.error("No library specified to move files to. Please edit your configuration.", section) 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]: 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) 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']: elif result['success']:
logger.postprocess("SUCCESS: Status for %s has been set to %s in Gamez" % (gamezID, downloadStatus),section) 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) ] return [0, "%s: Successfully post-processed %s" % (section, inputName)]
else: else:
logger.error("FAILED: Status for %s has NOT been updated in Gamez" % (gamezID),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) ] return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)]

View file

@ -40,7 +40,7 @@ class autoProcessMovie(object):
except: except:
logger.error("CouchPotato returned the following non-json data") logger.error("CouchPotato returned the following non-json data")
for line in r.iter_lines(): for line in r.iter_lines():
logger.error("%s" %(line)) logger.error("%s" % (line))
return results return results
if not result['success']: if not result['success']:
@ -56,7 +56,8 @@ class autoProcessMovie(object):
id = result[section]['_id'] id = result[section]['_id']
results[id] = result[section] results[id] = result[section]
return results return results
except:pass except:
pass
# Gather release info and proceed with trying to narrow results to one release choice # 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) baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey)
if not server_responding(baseURL): if not server_responding(baseURL):
logger.error("Server did not respond. Exiting", section) 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) imdbid = find_imdbid(dirName, inputName)
release = self.get_release(baseURL, imdbid, download_id) release = self.get_release(baseURL, imdbid, download_id)
@ -155,7 +156,7 @@ class autoProcessMovie(object):
except: except:
pass 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] dirName = os.path.split(os.path.normpath(dirName))[0]
SpecificPath = os.path.join(dirName, str(inputName)) SpecificPath = os.path.join(dirName, str(inputName))
@ -210,7 +211,7 @@ class autoProcessMovie(object):
dirName = newDirName dirName = newDirName
else: else:
logger.error("Transcoding failed for files in %s" % (dirName), section) 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): 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 not ".cp(tt" in video and imdbid:
videoName, videoExt = os.path.splitext(video) videoName, videoExt = os.path.splitext(video)
@ -244,20 +245,20 @@ class autoProcessMovie(object):
r = requests.get(url, params=params, verify=False, timeout=(30, 1800)) r = requests.get(url, params=params, verify=False, timeout=(30, 1800))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL", section) 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() result = r.json()
if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: 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) 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']: elif result['success']:
logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section)
if method == "manage": if method == "manage":
return [0, "%s: Successfully post-processed %s" % (section, inputName) ] return [0, "%s: Successfully post-processed %s" % (section, inputName)]
else: else:
logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName),
section) 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: else:
core.FAILED = True core.FAILED = True
@ -272,7 +273,7 @@ class autoProcessMovie(object):
if not release_id and not media_id: 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 %s, exiting!" % inputName,
section) 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: if release_id:
logger.postprocess("Setting failed release %s to ignored ..." % (inputName), section) 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)) r = requests.get(url, params=params, verify=False, timeout=(30, 120))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL %s" % (url), section) 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() result = r.json()
if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: 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) 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']: elif result['success']:
logger.postprocess("SUCCESS: %s has been set to ignored ..." % (inputName), section) logger.postprocess("SUCCESS: %s has been set to ignored ..." % (inputName), section)
else: else:
logger.warning("FAILED: Unable to set %s to ignored!" % (inputName), section) 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) 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)) r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL %s" % (url), section) 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() result = r.json()
if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: 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) 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']: elif result['success']:
logger.postprocess("SUCCESS: Snatched the next highest release ...", section) 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: else:
logger.postprocess("SUCCESS: Unable to find a new release to snatch now. CP will keep searching!", section) 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. # Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list.
if not release: if not release:
@ -333,24 +334,24 @@ class autoProcessMovie(object):
try: try:
if release_id is None and release_status_old is None: # we didn't have a release before, but now we do. 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) 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'] release_status_new = release[release_id]['status']
if release_status_new != release_status_old: 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 %s has now been marked with a status of [%s]" % (
inputName, str(release_status_new).upper()), section) 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: except:
pass pass
if not os.path.isdir(dirName): if not os.path.isdir(dirName):
logger.postprocess("SUCCESS: Input Directory [%s] has been processed and removed" % ( logger.postprocess("SUCCESS: Input Directory [%s] has been processed and removed" % (
dirName), section) 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): 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 [%s] has no remaining media files. This has been fully processed." % (
dirName), section) 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 # pause and let CouchPotatoServer catch its breath
time.sleep(10 * wait_for) time.sleep(10 * wait_for)
@ -359,4 +360,4 @@ class autoProcessMovie(object):
logger.warning( logger.warning(
"%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for), "%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for),
section) 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)]

View file

@ -32,7 +32,7 @@ class autoProcessMusic(object):
result = r.json() result = r.json()
for album in result: for album in result:
if os.path.basename(dirName) == album['FolderName']: if os.path.basename(dirName) == album['FolderName']:
return album["Status"].lower() return album["Status"].lower()
except: except:
return None return None
@ -66,13 +66,12 @@ class autoProcessMusic(object):
else: else:
protocol = "http://" 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): if not server_responding(url):
logger.error("Server did not respond. Exiting", section) 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] dirName = os.path.split(os.path.normpath(dirName))[0]
SpecificPath = os.path.join(dirName, str(inputName)) SpecificPath = os.path.join(dirName, str(inputName))
@ -106,43 +105,43 @@ class autoProcessMusic(object):
release_status = self.get_status(url, apikey, dirName) release_status = self.get_status(url, apikey, dirName)
if not release_status: 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) logger.debug("Opening URL: %s with PARAMS: %s" % (url, params), section)
try: try:
r = requests.get(url, params=params, verify=False, timeout=(30, 300)) r = requests.get(url, params=params, verify=False, timeout=(30, 300))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL %s" % (url) ,section) 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)]
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]: 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) 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": 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: else:
logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName),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) ] return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section)]
else: else:
logger.warning("FAILED DOWNLOAD DETECTED", section) 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. # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
timeout = time.time() + 60 * wait_for timeout = time.time() + 60 * wait_for
while time.time() < timeout: while time.time() < timeout:
current_status = self.get_status(url, apikey, dirName) 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. 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) logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status), section)
return [0, "%s: Successfully post-processed %s" % (section, inputName) ] return [0, "%s: Successfully post-processed %s" % (section, inputName)]
if not os.path.isdir(dirName): if not os.path.isdir(dirName):
logger.postprocess("SUCCESS: The input directory %s has been removed Processing must have finished." % (dirName),section) 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) ] return [0, "%s: Successfully post-processed %s" % (section, inputName)]
time.sleep(10 * wait_for) time.sleep(10 * wait_for)
# The status hasn't changed. uTorrent can resume seeding now. # 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) 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) ] return [1, "%s: Failed to post-process - No change in wanted status" % (section)]

View file

@ -51,7 +51,7 @@ class autoProcessTV(object):
except: except:
return False 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"] host = core.CFG[section][inputCategory]["host"]
port = core.CFG[section][inputCategory]["port"] port = core.CFG[section][inputCategory]["port"]
try: try:
@ -66,9 +66,9 @@ class autoProcessTV(object):
web_root = core.CFG[section][inputCategory]["web_root"] web_root = core.CFG[section][inputCategory]["web_root"]
except: except:
web_root = "" 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) 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 # auto-detect correct fork
fork, fork_params = autoFork(section, inputCategory) fork, fork_params = autoFork(section, inputCategory)
@ -116,7 +116,7 @@ class autoProcessTV(object):
except: except:
extract = 0 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] dirName = os.path.split(os.path.normpath(dirName))[0]
SpecificPath = os.path.join(dirName, str(inputName)) SpecificPath = os.path.join(dirName, str(inputName))
@ -136,7 +136,7 @@ class autoProcessTV(object):
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
raise 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: if inputName:
process_all_exceptions(inputName, dirName) process_all_exceptions(inputName, dirName)
inputName, dirName = convert_to_ascii(inputName, dirName) inputName, dirName = convert_to_ascii(inputName, dirName)
@ -175,7 +175,7 @@ class autoProcessTV(object):
failureLink = failureLink + '&corrupt=true' failureLink = failureLink + '&corrupt=true'
elif clientAgent == "manual": 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 %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": elif nzbExtractionBy == "Destination":
logger.info("Check for media files ignored because nzbExtractionBy is set to Destination.") logger.info("Check for media files ignored because nzbExtractionBy is set to Destination.")
if int(failed) == 0: if int(failed) == 0:
@ -183,9 +183,9 @@ class autoProcessTV(object):
status = 0 status = 0
failed = 0 failed = 0
else: else:
logger.info("Downloader reported an error during download or verification. Processing this as a failed download.") logger.info("Downloader reported an error during download or verification. Processing this as a failed download.")
status = 1 status = 1
failed = 1 failed = 1
else: 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 %s. Processing this as a failed download" % (dirName), section)
status = 1 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': if os.environ.has_key('NZBOP_VERSION') and os.environ['NZBOP_VERSION'][0:5] >= '14.0':
print('[NZB] MARK=BAD') 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) result, newDirName = transcoder.Transcode_directory(dirName)
if result == 0: if result == 0:
logger.debug("SUCCESS: Transcoding succeeded for files in %s" % (dirName), section) logger.debug("SUCCESS: Transcoding succeeded for files in %s" % (dirName), section)
dirName = newDirName dirName = newDirName
else: else:
logger.error("FAILED: Transcoding failed for files in %s" % (dirName), section) 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 # configure SB params to pass
fork_params['quiet'] = 1 fork_params['quiet'] = 1
@ -235,7 +235,7 @@ class autoProcessTV(object):
del fork_params[param] del fork_params[param]
# delete any unused params so we don't pass them to SB by mistake # 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: if status == 0:
logger.postprocess("SUCCESS: The download succeeded, sending a post-process request", section) 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) logger.postprocess("FAILED: The download failed. Sending 'failed' process request to %s branch" % (fork), section)
elif section == "NzbDrone": elif section == "NzbDrone":
logger.postprocess("FAILED: The download failed. Sending failed download to %s for CDH processing" % (fork), section) 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: 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. %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: 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 %s" % (dirName), section)
rmDir(dirName) 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 url = None
if section == "SickBeard": 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": elif section == "NzbDrone":
url = "%s%s:%s%s/api/command" % (protocol, host, port, web_root) 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) url2 = "%s%s:%s%s/api/config/downloadClient" % (protocol, host, port, web_root)
headers = {"X-Api-Key": apikey} 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: 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} data = {"name": "DownloadedEpisodesScan", "path": remoteDir(dirName), "downloadClientId": download_id}
else: else:
logger.debug("path: %s" % (dirName),section) logger.debug("path: %s" % (dirName), section)
data = {"name": "DownloadedEpisodesScan", "path": dirName, "downloadClientId": download_id} data = {"name": "DownloadedEpisodesScan", "path": dirName, "downloadClientId": download_id}
if not download_id: if not download_id:
data.pop("downloadClientId") data.pop("downloadClientId")
@ -277,7 +277,7 @@ class autoProcessTV(object):
if section == "SickBeard": if section == "SickBeard":
logger.debug("Opening URL: %s with params: %s" % (url, str(fork_params)), section) logger.debug("Opening URL: %s with params: %s" % (url, str(fork_params)), section)
s = requests.Session() 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} login_params = {'username': username, 'password': password}
s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) 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)) 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)) r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
except requests.ConnectionError: except requests.ConnectionError:
logger.error("Unable to open URL: %s" % (url), section) 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]: 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) 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 Success = False
Started = False Started = False
@ -314,11 +314,11 @@ class autoProcessTV(object):
Started = False Started = False
if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: 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) rmDir(dirName)
if Success: 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: elif section == "NzbDrone" and Started:
n = 0 n = 0
params = {} params = {}
@ -327,24 +327,24 @@ class autoProcessTV(object):
time.sleep(10 * wait_for) time.sleep(10 * wait_for)
command_status = self.command_complete(url, params, headers, section) 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 break
n += 1 n += 1
if command_status: if command_status:
logger.debug("The Scan command return status: %s" % (command_status), section) logger.debug("The Scan command return status: %s" % (command_status), section)
if not os.path.exists(dirName): if not os.path.exists(dirName):
logger.debug("The directory %s has been removed. Renaming was successful." % (dirName), section) 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']: elif command_status and command_status in ['completed']:
logger.debug("The Scan command has completed successfully. Renaming was successful.", section) 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']: elif command_status and command_status in ['failed']:
logger.debug("The Scan command has failed. Renaming was not successful.", section) 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): 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) 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: else:
logger.warning("The Scan command did not return a valid status. Renaming was not successful.", section) 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: 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.