mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 13:23:18 -07:00
Use format()
instead of %
for string formatting
This commit is contained in:
parent
0c45961382
commit
51d2c73054
5 changed files with 148 additions and 148 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue