mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Use format()
instead of %
for string formatting
This commit is contained in:
parent
94e8a45c62
commit
1cd073cd52
21 changed files with 317 additions and 287 deletions
|
@ -18,7 +18,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
uniquePath = 1
|
uniquePath = 1
|
||||||
|
|
||||||
if clientAgent != 'manual' and not core.DOWNLOADINFO:
|
if clientAgent != 'manual' and not core.DOWNLOADINFO:
|
||||||
logger.debug('Adding TORRENT download info for directory %s to database' % (inputDirectory))
|
logger.debug('Adding TORRENT download info for directory {0} to database'.format(inputDirectory))
|
||||||
|
|
||||||
myDB = nzbToMediaDB.DBConnection()
|
myDB = nzbToMediaDB.DBConnection()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
}
|
}
|
||||||
myDB.upsert("downloads", newValueDict, controlValueDict)
|
myDB.upsert("downloads", newValueDict, controlValueDict)
|
||||||
|
|
||||||
logger.debug("Received Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory))
|
logger.debug("Received Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory))
|
||||||
|
|
||||||
inputDirectory, inputName, inputCategory, root = core.category_search(inputDirectory, inputName,
|
inputDirectory, inputName, inputCategory, root = core.category_search(inputDirectory, inputName,
|
||||||
inputCategory, root,
|
inputCategory, root,
|
||||||
|
@ -58,7 +58,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
inputDirectory = inputDirectory.encode(core.SYS_ENCODING)
|
inputDirectory = inputDirectory.encode(core.SYS_ENCODING)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory))
|
logger.debug("Determined Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory))
|
||||||
|
|
||||||
# auto-detect section
|
# auto-detect section
|
||||||
section = core.CFG.findsection(inputCategory).isenabled()
|
section = core.CFG.findsection(inputCategory).isenabled()
|
||||||
|
@ -66,7 +66,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
section = core.CFG.findsection("ALL").isenabled()
|
section = core.CFG.findsection("ALL").isenabled()
|
||||||
if section is None:
|
if section is None:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % (
|
'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format(
|
||||||
inputCategory))
|
inputCategory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
else:
|
else:
|
||||||
|
@ -74,15 +74,15 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
|
|
||||||
if len(section) > 1:
|
if len(section) > 1:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % (
|
'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format(
|
||||||
usercat, section.keys()))
|
usercat, section.keys()))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
if section:
|
if section:
|
||||||
sectionName = section.keys()[0]
|
sectionName = section.keys()[0]
|
||||||
logger.info('Auto-detected SECTION:%s' % (sectionName))
|
logger.info('Auto-detected SECTION:{0}'.format(sectionName))
|
||||||
else:
|
else:
|
||||||
logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % (
|
logger.error("Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!".format(
|
||||||
inputCategory))
|
inputCategory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
|
@ -129,15 +129,15 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
if outputDestination in inputDirectory:
|
if outputDestination in inputDirectory:
|
||||||
outputDestination = inputDirectory
|
outputDestination = inputDirectory
|
||||||
|
|
||||||
logger.info("Output directory set to: %s" % (outputDestination))
|
logger.info("Output directory set to: {0}".format(outputDestination))
|
||||||
|
|
||||||
if core.SAFE_MODE and outputDestination == core.TORRENT_DEFAULTDIR:
|
if core.SAFE_MODE and outputDestination == core.TORRENT_DEFAULTDIR:
|
||||||
logger.error(
|
logger.error(
|
||||||
'The output directory:[%s] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting' % (
|
'The output directory:[{0}] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting'.format(
|
||||||
inputDirectory))
|
inputDirectory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
logger.debug("Scanning files in directory: %s" % (inputDirectory))
|
logger.debug("Scanning files in directory: {0}".format(inputDirectory))
|
||||||
|
|
||||||
if sectionName == 'HeadPhones':
|
if sectionName == 'HeadPhones':
|
||||||
core.NOFLATTEN.extend(
|
core.NOFLATTEN.extend(
|
||||||
|
@ -149,7 +149,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
inputFiles = core.listMediaFiles(inputDirectory, archives=False)
|
inputFiles = core.listMediaFiles(inputDirectory, archives=False)
|
||||||
else:
|
else:
|
||||||
inputFiles = core.listMediaFiles(inputDirectory)
|
inputFiles = core.listMediaFiles(inputDirectory)
|
||||||
logger.debug("Found %s files in %s" % (str(len(inputFiles)), inputDirectory))
|
logger.debug("Found {0} files in {1}".format(len(inputFiles), inputDirectory))
|
||||||
for inputFile in inputFiles:
|
for inputFile in inputFiles:
|
||||||
filePath = os.path.dirname(inputFile)
|
filePath = os.path.dirname(inputFile)
|
||||||
fileName, fileExt = os.path.splitext(os.path.basename(inputFile))
|
fileName, fileExt = os.path.splitext(os.path.basename(inputFile))
|
||||||
|
@ -161,17 +161,17 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
targetFile = core.os.path.join(
|
targetFile = core.os.path.join(
|
||||||
core.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName)
|
core.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Setting outputDestination to %s to preserve folder structure" % (os.path.dirname(targetFile)))
|
"Setting outputDestination to {0} to preserve folder structure".format(os.path.dirname(targetFile)))
|
||||||
try:
|
try:
|
||||||
targetFile = targetFile.encode(core.SYS_ENCODING)
|
targetFile = targetFile.encode(core.SYS_ENCODING)
|
||||||
except: pass
|
except: pass
|
||||||
if root == 1:
|
if root == 1:
|
||||||
if not foundFile:
|
if not foundFile:
|
||||||
logger.debug("Looking for %s in: %s" % (inputName, inputFile))
|
logger.debug("Looking for {0} in: {1}".format(inputName, inputFile))
|
||||||
if (core.sanitizeName(inputName) in core.sanitizeName(inputFile)) or (
|
if (core.sanitizeName(inputName) in core.sanitizeName(inputFile)) or (
|
||||||
core.sanitizeName(fileName) in core.sanitizeName(inputName)):
|
core.sanitizeName(fileName) in core.sanitizeName(inputName)):
|
||||||
foundFile = True
|
foundFile = True
|
||||||
logger.debug("Found file %s that matches Torrent Name %s" % (fullFileName, inputName))
|
logger.debug("Found file {0} that matches Torrent Name {1}".format(fullFileName, inputName))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
logger.debug("Looking for files with modified/created dates less than 5 minutes old.")
|
logger.debug("Looking for files with modified/created dates less than 5 minutes old.")
|
||||||
if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)):
|
if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)):
|
||||||
foundFile = True
|
foundFile = True
|
||||||
logger.debug("Found file %s with date modifed/created less than 5 minutes ago." % (fullFileName))
|
logger.debug("Found file {0} with date modifed/created less than 5 minutes ago.".format(fullFileName))
|
||||||
else:
|
else:
|
||||||
continue # This file has not been recently moved or created, skip it
|
continue # This file has not been recently moved or created, skip it
|
||||||
|
|
||||||
|
@ -192,12 +192,12 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
core.copy_link(inputFile, targetFile, core.USELINK)
|
core.copy_link(inputFile, targetFile, core.USELINK)
|
||||||
core.rmReadOnly(targetFile)
|
core.rmReadOnly(targetFile)
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to link: %s to %s" % (inputFile, targetFile))
|
logger.error("Failed to link: {0} to {1}".format(inputFile, targetFile))
|
||||||
|
|
||||||
inputName, outputDestination = convert_to_ascii(inputName, outputDestination)
|
inputName, outputDestination = convert_to_ascii(inputName, outputDestination)
|
||||||
|
|
||||||
if extract == 1:
|
if extract == 1:
|
||||||
logger.debug('Checking for archives to extract in directory: %s' % (inputDirectory))
|
logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory))
|
||||||
core.extractFiles(inputDirectory, outputDestination, keep_archive)
|
core.extractFiles(inputDirectory, outputDestination, keep_archive)
|
||||||
|
|
||||||
if not inputCategory in core.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later.
|
if not inputCategory in core.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later.
|
||||||
|
@ -208,19 +208,19 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
numVideos = len(
|
numVideos = len(
|
||||||
core.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False))
|
core.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False))
|
||||||
if numVideos > 0:
|
if numVideos > 0:
|
||||||
logger.info("Found %s media files in %s" % (numVideos, outputDestination))
|
logger.info("Found {0} media files in {1}".format(numVideos, outputDestination))
|
||||||
status = 0
|
status = 0
|
||||||
elif extract != 1:
|
elif extract != 1:
|
||||||
logger.info("Found no media files in %s. Sending to %s to process" % (outputDestination, sectionName))
|
logger.info("Found no media files in {0}. Sending to {1} to process".format(outputDestination, sectionName))
|
||||||
status = 0
|
status = 0
|
||||||
else:
|
else:
|
||||||
logger.warning("Found no media files in %s" % outputDestination)
|
logger.warning("Found no media files in {0}".format(outputDestination))
|
||||||
|
|
||||||
# Only these sections can handling failed downloads so make sure everything else gets through without the check for failed
|
# Only these sections can handling failed downloads so make sure everything else gets through without the check for failed
|
||||||
if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']:
|
if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']:
|
||||||
status = 0
|
status = 0
|
||||||
|
|
||||||
logger.info("Calling %s:%s to post-process:%s" % (sectionName, usercat, inputName))
|
logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, usercat, inputName))
|
||||||
|
|
||||||
if core.TORRENT_CHMOD_DIRECTORY:
|
if core.TORRENT_CHMOD_DIRECTORY:
|
||||||
core.rchmod(outputDestination, core.TORRENT_CHMOD_DIRECTORY)
|
core.rchmod(outputDestination, core.TORRENT_CHMOD_DIRECTORY)
|
||||||
|
@ -262,10 +262,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
|
|
||||||
# remove torrent
|
# remove torrent
|
||||||
if core.USELINK == 'move-sym' and not core.DELETE_ORIGINAL == 1:
|
if core.USELINK == 'move-sym' and not core.DELETE_ORIGINAL == 1:
|
||||||
logger.debug('Checking for sym-links to re-direct in: %s' % (inputDirectory))
|
logger.debug('Checking for sym-links to re-direct in: {0}'.format(inputDirectory))
|
||||||
for dirpath, dirs, files in os.walk(inputDirectory):
|
for dirpath, dirs, files in os.walk(inputDirectory):
|
||||||
for file in files:
|
for file in files:
|
||||||
logger.debug('Checking symlink: %s' % (os.path.join(dirpath,file)))
|
logger.debug('Checking symlink: {0}'.format(os.path.join(dirpath,file)))
|
||||||
core.replace_links(os.path.join(dirpath,file))
|
core.replace_links(os.path.join(dirpath,file))
|
||||||
core.remove_torrent(clientAgent, inputHash, inputID, inputName)
|
core.remove_torrent(clientAgent, inputHash, inputID, inputName)
|
||||||
|
|
||||||
|
@ -284,11 +284,11 @@ def main(args):
|
||||||
clientAgent = core.TORRENT_CLIENTAGENT
|
clientAgent = core.TORRENT_CLIENTAGENT
|
||||||
|
|
||||||
logger.info("#########################################################")
|
logger.info("#########################################################")
|
||||||
logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__))
|
logger.info("## ..::[{0}]::.. ##".format(os.path.basename(__file__)))
|
||||||
logger.info("#########################################################")
|
logger.info("#########################################################")
|
||||||
|
|
||||||
# debug command line options
|
# debug command line options
|
||||||
logger.debug("Options passed into TorrentToMedia: %s" % (args))
|
logger.debug("Options passed into TorrentToMedia: {0}".format(args))
|
||||||
|
|
||||||
# Post-Processing Result
|
# Post-Processing Result
|
||||||
result = [ 0, "" ]
|
result = [ 0, "" ]
|
||||||
|
@ -310,16 +310,16 @@ def main(args):
|
||||||
if not core.CFG[section][subsection].isenabled():
|
if not core.CFG[section][subsection].isenabled():
|
||||||
continue
|
continue
|
||||||
for dirName in core.getDirs(section, subsection, link='hard'):
|
for dirName in core.getDirs(section, subsection, link='hard'):
|
||||||
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName))
|
logger.info("Starting manual run for {0}:{1} - Folder:{2}".format(section, subsection, dirName))
|
||||||
|
|
||||||
logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName)))
|
logger.info("Checking database for download info for {0} ...".format(os.path.basename(dirName)))
|
||||||
core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0)
|
core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0)
|
||||||
if core.DOWNLOADINFO:
|
if core.DOWNLOADINFO:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Found download info for %s, setting variables now ..." % (os.path.basename(dirName)))
|
"Found download info for {0}, setting variables now ...".format(os.path.basename(dirName)))
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Unable to locate download info for %s, continuing to try and process this release ...' % (
|
'Unable to locate download info for {0}, continuing to try and process this release ...'.format(
|
||||||
os.path.basename(dirName))
|
os.path.basename(dirName))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -350,14 +350,14 @@ def main(args):
|
||||||
results = processTorrent(dirName, inputName, subsection, inputHash, inputID,
|
results = processTorrent(dirName, inputName, subsection, inputHash, inputID,
|
||||||
clientAgent)
|
clientAgent)
|
||||||
if results[0] != 0:
|
if results[0] != 0:
|
||||||
logger.error("A problem was reported when trying to perform a manual run for %s:%s." % (
|
logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format(
|
||||||
section, subsection))
|
section, subsection))
|
||||||
result = results
|
result = results
|
||||||
|
|
||||||
if result[0] == 0:
|
if result[0] == 0:
|
||||||
logger.info("The %s script completed successfully." % (args[0]))
|
logger.info("The {0} script completed successfully.".format(args[0]))
|
||||||
else:
|
else:
|
||||||
logger.error("A problem was reported in the %s script." % (args[0]))
|
logger.error("A problem was reported in the {0} script.".format(args[0]))
|
||||||
del core.MYAPP
|
del core.MYAPP
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ def initialize(section=None):
|
||||||
|
|
||||||
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
||||||
if not config.migrate():
|
if not config.migrate():
|
||||||
logger.error("Unable to migrate config file %s, exiting ..." % (CONFIG_FILE))
|
logger.error("Unable to migrate config file {0}, exiting ...".format(CONFIG_FILE))
|
||||||
if 'NZBOP_SCRIPTDIR' in os.environ:
|
if 'NZBOP_SCRIPTDIR' in os.environ:
|
||||||
pass # We will try and read config from Environment.
|
pass # We will try and read config from Environment.
|
||||||
else:
|
else:
|
||||||
|
@ -287,7 +287,7 @@ def initialize(section=None):
|
||||||
CFG = config.addnzbget()
|
CFG = config.addnzbget()
|
||||||
|
|
||||||
else: # load newly migrated config
|
else: # load newly migrated config
|
||||||
logger.info("Loading config from [%s]" % (CONFIG_FILE))
|
logger.info("Loading config from [{0}]".format(CONFIG_FILE))
|
||||||
CFG = config()
|
CFG = config()
|
||||||
|
|
||||||
# Enable/Disable DEBUG Logging
|
# Enable/Disable DEBUG Logging
|
||||||
|
@ -298,7 +298,7 @@ def initialize(section=None):
|
||||||
|
|
||||||
if LOG_ENV:
|
if LOG_ENV:
|
||||||
for item in os.environ:
|
for item in os.environ:
|
||||||
logger.info("%s: %s" % (item, os.environ[item]), "ENVIRONMENT")
|
logger.info("{0}: {1}".format(item, os.environ[item]), "ENVIRONMENT")
|
||||||
|
|
||||||
# initialize the main SB database
|
# initialize the main SB database
|
||||||
nzbToMediaDB.upgradeDatabase(nzbToMediaDB.DBConnection(), mainDB.InitialSchema)
|
nzbToMediaDB.upgradeDatabase(nzbToMediaDB.DBConnection(), mainDB.InitialSchema)
|
||||||
|
@ -399,20 +399,20 @@ def initialize(section=None):
|
||||||
devnull = open(os.devnull, 'w')
|
devnull = open(os.devnull, 'w')
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(["nice"], stdout=devnull, stderr=devnull).communicate()
|
subprocess.Popen(["nice"], stdout=devnull, stderr=devnull).communicate()
|
||||||
NICENESS.extend(['nice', '-n%s' % (int(CFG["Posix"]["niceness"]))])
|
NICENESS.extend(['nice', '-n{0}'.format(int(CFG["Posix"]["niceness"]))])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(["ionice"], stdout=devnull, stderr=devnull).communicate()
|
subprocess.Popen(["ionice"], stdout=devnull, stderr=devnull).communicate()
|
||||||
try:
|
try:
|
||||||
NICENESS.extend(['ionice', '-c%s' % (int(CFG["Posix"]["ionice_class"]))])
|
NICENESS.extend(['ionice', '-c{0}'.format(int(CFG["Posix"]["ionice_class"]))])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
if 'ionice' in NICENESS:
|
if 'ionice' in NICENESS:
|
||||||
NICENESS.extend(['-n%s' % (int(CFG["Posix"]["ionice_classdata"]))])
|
NICENESS.extend(['-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))])
|
||||||
else:
|
else:
|
||||||
NICENESS.extend(['ionice', '-n%s' % (int(CFG["Posix"]["ionice_classdata"]))])
|
NICENESS.extend(['ionice', '-n{0}'.format(int(CFG["Posix"]["ionice_classdata"]))])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
|
@ -422,7 +422,7 @@ def initialize(section=None):
|
||||||
COMPRESSEDCONTAINER = [re.compile('.r\d{2}$', re.I),
|
COMPRESSEDCONTAINER = [re.compile('.r\d{2}$', re.I),
|
||||||
re.compile('.part\d+.rar$', re.I),
|
re.compile('.part\d+.rar$', re.I),
|
||||||
re.compile('.rar$', re.I)]
|
re.compile('.rar$', re.I)]
|
||||||
COMPRESSEDCONTAINER += [re.compile('%s$' % ext, re.I) for ext in CFG["Extensions"]["compressedExtensions"]]
|
COMPRESSEDCONTAINER += [re.compile('{0}$'.format(ext), re.I) for ext in CFG["Extensions"]["compressedExtensions"]]
|
||||||
MEDIACONTAINER = CFG["Extensions"]["mediaExtensions"]
|
MEDIACONTAINER = CFG["Extensions"]["mediaExtensions"]
|
||||||
AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"]
|
AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"]
|
||||||
METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt
|
METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt
|
||||||
|
@ -851,7 +851,7 @@ def restart():
|
||||||
|
|
||||||
|
|
||||||
def rchmod(path, mod):
|
def rchmod(path, mod):
|
||||||
logger.log("Changing file mode of %s to %s" % (path, oct(mod)))
|
logger.log("Changing file mode of {0} to {1}".format(path, oct(mod)))
|
||||||
os.chmod(path, mod)
|
os.chmod(path, mod)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
return # Skip files
|
return # Skip files
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -53,7 +54,9 @@ def extract(filePath, outputDestination):
|
||||||
else:
|
else:
|
||||||
for k, v in EXTRACT_COMMANDS.items():
|
for k, v in EXTRACT_COMMANDS.items():
|
||||||
if cmd in v[0]:
|
if cmd in v[0]:
|
||||||
core.logger.error("EXTRACTOR: %s not found, disabling support for %s" % (cmd, k))
|
core.logger.error("EXTRACTOR: {cmd} not found, "
|
||||||
|
"disabling support for {feature}".format
|
||||||
|
(cmd=cmd, feature=k))
|
||||||
del EXTRACT_COMMANDS[k]
|
del EXTRACT_COMMANDS[k]
|
||||||
devnull.close()
|
devnull.close()
|
||||||
else:
|
else:
|
||||||
|
@ -76,10 +79,11 @@ def extract(filePath, outputDestination):
|
||||||
if ext[1] in EXTRACT_COMMANDS:
|
if ext[1] in EXTRACT_COMMANDS:
|
||||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||||
else:
|
else:
|
||||||
core.logger.debug("EXTRACTOR: Unknown file type: %s" % ext[1])
|
core.logger.debug("EXTRACTOR: Unknown file type: {ext}".format
|
||||||
|
(ext=ext[1]))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Create outputDestination folder
|
# Create outputDestination folder
|
||||||
core.makeDir(outputDestination)
|
core.makeDir(outputDestination)
|
||||||
|
|
||||||
if core.PASSWORDSFILE != "" and os.path.isfile(os.path.normpath(core.PASSWORDSFILE)):
|
if core.PASSWORDSFILE != "" and os.path.isfile(os.path.normpath(core.PASSWORDSFILE)):
|
||||||
|
@ -87,8 +91,10 @@ def extract(filePath, outputDestination):
|
||||||
else:
|
else:
|
||||||
passwords = []
|
passwords = []
|
||||||
|
|
||||||
core.logger.info("Extracting %s to %s" % (filePath, outputDestination))
|
core.logger.info("Extracting {file} to {destination}".format
|
||||||
core.logger.debug("Extracting %s %s %s" % (cmd, filePath, outputDestination))
|
(file=filePath, destination=outputDestination))
|
||||||
|
core.logger.debug("Extracting {cmd} {file} {destination}".format
|
||||||
|
(cmd=cmd, file=filePath, destination=outputDestination))
|
||||||
|
|
||||||
origFiles = []
|
origFiles = []
|
||||||
origDirs = []
|
origDirs = []
|
||||||
|
@ -114,9 +120,9 @@ def extract(filePath, outputDestination):
|
||||||
cmd2.append("-p-") # don't prompt for password.
|
cmd2.append("-p-") # don't prompt for password.
|
||||||
p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine.
|
p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine.
|
||||||
res = p.wait()
|
res = p.wait()
|
||||||
if (
|
if (res >= 0 and os.name == 'nt') or res == 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful.
|
||||||
res >= 0 and os.name == 'nt') or res == 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful.
|
core.logger.info("EXTRACTOR: Extraction was successful for {file} to {destination}".format
|
||||||
core.logger.info("EXTRACTOR: Extraction was successful for %s to %s" % (filePath, outputDestination))
|
(file=filePath, destination=outputDestination))
|
||||||
success = 1
|
success = 1
|
||||||
elif len(passwords) > 0:
|
elif len(passwords) > 0:
|
||||||
core.logger.info("EXTRACTOR: Attempting to extract with passwords")
|
core.logger.info("EXTRACTOR: Attempting to extract with passwords")
|
||||||
|
@ -130,14 +136,17 @@ def extract(filePath, outputDestination):
|
||||||
p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine.
|
p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine.
|
||||||
res = p.wait()
|
res = p.wait()
|
||||||
if (res >= 0 and platform == 'Windows') or res == 0:
|
if (res >= 0 and platform == 'Windows') or res == 0:
|
||||||
core.logger.info("EXTRACTOR: Extraction was successful for %s to %s using password: %s" % (
|
core.logger.info("EXTRACTOR: Extraction was successful "
|
||||||
filePath, outputDestination, password))
|
"for {file} to {destination} using password: {pwd}".format
|
||||||
|
(file=filePath, destination=outputDestination, pwd=password))
|
||||||
success = 1
|
success = 1
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
except:
|
except:
|
||||||
core.logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s" % (filePath, cmd))
|
core.logger.error("EXTRACTOR: Extraction failed for {file}. "
|
||||||
|
"Could not call command {cmd}".format
|
||||||
|
(file=filePath, cmd=cmd))
|
||||||
os.chdir(pwd)
|
os.chdir(pwd)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -162,5 +171,7 @@ def extract(filePath, outputDestination):
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
core.logger.error("EXTRACTOR: Extraction failed for %s. Result was %s" % (filePath, res))
|
core.logger.error("EXTRACTOR: Extraction failed for {file}. "
|
||||||
|
"Result was {result}".format
|
||||||
|
(file=filePath, result=res))
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -33,14 +33,14 @@ if os.name == 'nt':
|
||||||
|
|
||||||
# Prevent spaces from messing with us!
|
# Prevent spaces from messing with us!
|
||||||
def _escape_param(param):
|
def _escape_param(param):
|
||||||
return '"%s"' % param
|
return '"{0}"'.format(param)
|
||||||
|
|
||||||
|
|
||||||
# Private function to create link on nt-based systems
|
# Private function to create link on nt-based systems
|
||||||
def _link_windows(src, dest):
|
def _link_windows(src, dest):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'cmd /C mklink /H %s %s' % (_escape_param(dest), _escape_param(src)),
|
'cmd /C mklink /H {0} {1}'.format(_escape_param(dest), _escape_param(src)),
|
||||||
stderr=subprocess.STDOUT, startupinfo=info)
|
stderr=subprocess.STDOUT, startupinfo=info)
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ def _link_windows(src, dest):
|
||||||
def _symlink_windows(src, dest):
|
def _symlink_windows(src, dest):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'cmd /C mklink %s %s' % (_escape_param(dest), _escape_param(src)),
|
'cmd /C mklink {0} {1}'.format(_escape_param(dest), _escape_param(src)),
|
||||||
stderr=subprocess.STDOUT, startupinfo=info)
|
stderr=subprocess.STDOUT, startupinfo=info)
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
raise IOError(err.output.decode('utf-8'))
|
raise IOError(err.output.decode('utf-8'))
|
||||||
|
@ -67,7 +67,7 @@ def _symlink_windows(src, dest):
|
||||||
def _dirlink_windows(src, dest):
|
def _dirlink_windows(src, dest):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'cmd /C mklink /J %s %s' % (_escape_param(dest), _escape_param(src)),
|
'cmd /C mklink /J {0} {1}'.format(_escape_param(dest), _escape_param(src)),
|
||||||
stderr=subprocess.STDOUT, startupinfo=info)
|
stderr=subprocess.STDOUT, startupinfo=info)
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
raise IOError(err.output.decode('utf-8'))
|
raise IOError(err.output.decode('utf-8'))
|
||||||
|
@ -80,7 +80,7 @@ def _dirlink_windows(src, dest):
|
||||||
def _junctionlink_windows(src, dest):
|
def _junctionlink_windows(src, dest):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
'cmd /C mklink /D %s %s' % (_escape_param(dest), _escape_param(src)),
|
'cmd /C mklink /D {0} {1}'.format(_escape_param(dest), _escape_param(src)),
|
||||||
stderr=subprocess.STDOUT, startupinfo=info)
|
stderr=subprocess.STDOUT, startupinfo=info)
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
raise IOError(err.output.decode('utf-8'))
|
raise IOError(err.output.decode('utf-8'))
|
||||||
|
|
|
@ -193,9 +193,9 @@ class NTMRotatingLogHandler(object):
|
||||||
self.writes_since_check += 1
|
self.writes_since_check += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = u"%s: %s" % (str(section).upper(), toLog)
|
message = u"{0}: {1}".format(str(section).upper(), toLog)
|
||||||
except:
|
except:
|
||||||
message = u"%s: Message contains non-utf-8 string" % (str(section).upper())
|
message = u"{0}: Message contains non-utf-8 string".format(str(section).upper())
|
||||||
|
|
||||||
out_line = message
|
out_line = message
|
||||||
|
|
||||||
|
|
|
@ -52,42 +52,49 @@ def autoFork(section, inputCategory):
|
||||||
|
|
||||||
detected = False
|
detected = False
|
||||||
if section == "NzbDrone":
|
if section == "NzbDrone":
|
||||||
logger.info("Attempting to verify %s fork" % inputCategory)
|
logger.info("Attempting to verify {category} fork".format
|
||||||
url = "%s%s:%s%s/api/rootfolder" % (protocol, host, port, web_root)
|
(category=inputCategory))
|
||||||
|
url = "{protocol}{host}:{port}{root}/api/rootfolder".format(
|
||||||
|
protocol=protocol, host=host, port=port, root=web_root)
|
||||||
headers = {"X-Api-Key": apikey}
|
headers = {"X-Api-Key": apikey}
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, headers=headers, stream=True, verify=False)
|
r = requests.get(url, headers=headers, stream=True, verify=False)
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.warning("Could not connect to %s:%s to verify fork!" % (section, inputCategory))
|
logger.warning("Could not connect to {0}:{1} to verify fork!".format(section, inputCategory))
|
||||||
|
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
logger.warning("Connection to %s:%s failed! Check your configuration" % (section, inputCategory))
|
logger.warning("Connection to {section}:{category} failed! "
|
||||||
|
"Check your configuration".format
|
||||||
|
(section=section, category=inputCategory))
|
||||||
|
|
||||||
fork = ['default', {}]
|
fork = ['default', {}]
|
||||||
|
|
||||||
elif fork == "auto":
|
elif fork == "auto":
|
||||||
params = core.ALL_FORKS
|
params = core.ALL_FORKS
|
||||||
rem_params = []
|
rem_params = []
|
||||||
logger.info("Attempting to auto-detect %s fork" % inputCategory)
|
logger.info("Attempting to auto-detect {category} fork".format(category=inputCategory))
|
||||||
# define the order to test. Default must be first since the default fork doesn't reject parameters.
|
# define the order to test. Default must be first since the default fork doesn't reject parameters.
|
||||||
# then in order of most unique parameters.
|
# then in order of most unique parameters.
|
||||||
url = "%s%s:%s%s/home/postprocess/" % (protocol, host, port, web_root)
|
url = "{protocol}{host}:{port}{root}/home/postprocess/".format(
|
||||||
|
protocol=protocol, host=host, port=port, root=web_root)
|
||||||
# attempting to auto-detect fork
|
# attempting to auto-detect fork
|
||||||
try:
|
try:
|
||||||
if username and password:
|
if username and password:
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
login = "%s%s:%s%s/login" % (protocol, host, port, web_root)
|
login = "{protocol}{host}:{port}{root}/login".format(
|
||||||
|
protocol=protocol, host=host, port=port, root=web_root)
|
||||||
login_params = {'username': username, 'password': password}
|
login_params = {'username': username, 'password': password}
|
||||||
s.post(login, data=login_params, stream=True, verify=False)
|
s.post(login, data=login_params, stream=True, verify=False)
|
||||||
r = s.get(url, auth=(username, password), verify=False)
|
r = s.get(url, auth=(username, password), verify=False)
|
||||||
else:
|
else:
|
||||||
r = requests.get(url, verify=False)
|
r = requests.get(url, verify=False)
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.info("Could not connect to %s:%s to perform auto-fork detection!" % (section, inputCategory))
|
logger.info("Could not connect to {section}:{category} to perform auto-fork detection!".format
|
||||||
|
(section=section, category=inputCategory))
|
||||||
r = []
|
r = []
|
||||||
if r and r.ok:
|
if r and r.ok:
|
||||||
for param in params:
|
for param in params:
|
||||||
if not 'name="%s"' % (param) in r.text:
|
if not 'name={param!r}'.format(param=param) in r.text:
|
||||||
rem_params.append(param)
|
rem_params.append(param)
|
||||||
for param in rem_params:
|
for param in rem_params:
|
||||||
params.pop(param)
|
params.pop(param)
|
||||||
|
@ -96,13 +103,17 @@ def autoFork(section, inputCategory):
|
||||||
detected = True
|
detected = True
|
||||||
break
|
break
|
||||||
if detected:
|
if detected:
|
||||||
logger.info("%s:%s fork auto-detection successful ..." % (section, inputCategory))
|
logger.info("{section}:{category} fork auto-detection successful ...".format
|
||||||
|
(section=section, category=inputCategory))
|
||||||
elif rem_params:
|
elif rem_params:
|
||||||
logger.info("%s:%s fork auto-detection found custom params %s" % (section, inputCategory, params))
|
logger.info("{section}:{category} fork auto-detection found custom params {params}".format
|
||||||
|
(section=section, category=inputCategory, params=params))
|
||||||
fork = ['custom', params]
|
fork = ['custom', params]
|
||||||
else:
|
else:
|
||||||
logger.info("%s:%s fork auto-detection failed" % (section, inputCategory))
|
logger.info("{section}:{category} fork auto-detection failed".format
|
||||||
|
(section=section, category=inputCategory))
|
||||||
fork = core.FORKS.items()[core.FORKS.keys().index(core.FORK_DEFAULT)]
|
fork = core.FORKS.items()[core.FORKS.keys().index(core.FORK_DEFAULT)]
|
||||||
|
|
||||||
logger.info("%s:%s fork set to %s" % (section, inputCategory, fork[0]))
|
logger.info("{section}:{category} fork set to {fork}".format
|
||||||
|
(section=section, category=inputCategory, fork=fork[0]))
|
||||||
return fork[0], fork[1]
|
return fork[0], fork[1]
|
||||||
|
|
|
@ -118,16 +118,16 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
if not os.path.isfile(core.CONFIG_FILE):
|
if not os.path.isfile(core.CONFIG_FILE):
|
||||||
shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE)
|
shutil.copyfile(core.CONFIG_SPEC_FILE, core.CONFIG_FILE)
|
||||||
CFG_OLD = config(core.CONFIG_FILE)
|
CFG_OLD = config(core.CONFIG_FILE)
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.debug("Error %s when copying to .cfg" % (e))
|
logger.debug("Error {msg} when copying to .cfg".format(msg=error))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# check for autoProcessMedia.cfg.spec and create if it does not exist
|
# check for autoProcessMedia.cfg.spec and create if it does not exist
|
||||||
if not os.path.isfile(core.CONFIG_SPEC_FILE):
|
if not os.path.isfile(core.CONFIG_SPEC_FILE):
|
||||||
shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE)
|
shutil.copyfile(core.CONFIG_FILE, core.CONFIG_SPEC_FILE)
|
||||||
CFG_NEW = config(core.CONFIG_SPEC_FILE)
|
CFG_NEW = config(core.CONFIG_SPEC_FILE)
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.debug("Error %s when copying to .spec" % (e))
|
logger.debug("Error {msg} when copying to .spec".format(msg=error))
|
||||||
|
|
||||||
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
||||||
if CFG_NEW is None or CFG_OLD is None:
|
if CFG_NEW is None or CFG_OLD is None:
|
||||||
|
@ -255,8 +255,9 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
try:
|
try:
|
||||||
if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ:
|
if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ:
|
||||||
if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']:
|
if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']:
|
||||||
logger.warning("%s category is set for SickBeard and NzbDrone. "
|
logger.warning("{x} category is set for SickBeard and NzbDrone. "
|
||||||
"Please check your config in NZBGet" % (os.environ['NZBPO_NDCATEGORY']))
|
"Please check your config in NZBGet".format
|
||||||
|
(x=os.environ['NZBPO_NDCATEGORY']))
|
||||||
|
|
||||||
section = "Nzb"
|
section = "Nzb"
|
||||||
key = 'NZBOP_DESTDIR'
|
key = 'NZBOP_DESTDIR'
|
||||||
|
@ -462,15 +463,15 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
CFG_NEW[section][os.environ[envCatKey]][option] = value
|
CFG_NEW[section][os.environ[envCatKey]][option] = value
|
||||||
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
|
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.debug("Error %s when applying NZBGet config" % (e))
|
logger.debug("Error {msg} when applying NZBGet config".format(msg=error))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# write our new config to autoProcessMedia.cfg
|
# write our new config to autoProcessMedia.cfg
|
||||||
CFG_NEW.filename = core.CONFIG_FILE
|
CFG_NEW.filename = core.CONFIG_FILE
|
||||||
CFG_NEW.write()
|
CFG_NEW.write()
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.debug("Error %s when writing changes to .cfg" % (e))
|
logger.debug("Error {msg} when writing changes to .cfg".format(msg=error))
|
||||||
|
|
||||||
return CFG_NEW
|
return CFG_NEW
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ def dbFilename(filename="nzbtomedia.db", suffix=None):
|
||||||
@return: the correct location of the database file.
|
@return: the correct location of the database file.
|
||||||
"""
|
"""
|
||||||
if suffix:
|
if suffix:
|
||||||
filename = "%s.%s" % (filename, suffix)
|
filename = "{0}.{1}".format(filename, suffix)
|
||||||
return core.os.path.join(core.PROGRAM_DIR, filename)
|
return core.os.path.join(core.PROGRAM_DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ class DBConnection(object):
|
||||||
|
|
||||||
def tableInfo(self, tableName):
|
def tableInfo(self, tableName):
|
||||||
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
||||||
cursor = self.connection.execute("PRAGMA table_info(%s)" % tableName)
|
cursor = self.connection.execute("PRAGMA table_info({0})".format(tableName))
|
||||||
columns = {}
|
columns = {}
|
||||||
for column in cursor:
|
for column in cursor:
|
||||||
columns[column['name']] = {'type': column['type']}
|
columns[column['name']] = {'type': column['type']}
|
||||||
|
@ -250,8 +250,8 @@ class SchemaUpgrade(object):
|
||||||
return column in self.connection.tableInfo(tableName)
|
return column in self.connection.tableInfo(tableName)
|
||||||
|
|
||||||
def addColumn(self, table, column, type="NUMERIC", default=0):
|
def addColumn(self, table, column, type="NUMERIC", default=0):
|
||||||
self.connection.action("ALTER TABLE %s ADD %s %s" % (table, column, type))
|
self.connection.action("ALTER TABLE {0} ADD {1} {2}".format(table, column, type))
|
||||||
self.connection.action("UPDATE %s SET %s = ?" % (table, column), (default,))
|
self.connection.action("UPDATE {0} SET {1} = ?".format(table, column), (default,))
|
||||||
|
|
||||||
def checkDBVersion(self):
|
def checkDBVersion(self):
|
||||||
result = self.connection.select("SELECT db_version FROM db_version")
|
result = self.connection.select("SELECT db_version FROM db_version")
|
||||||
|
|
|
@ -61,23 +61,25 @@ def strip_groups(filename):
|
||||||
|
|
||||||
|
|
||||||
def rename_file(filename, newfilePath):
|
def rename_file(filename, newfilePath):
|
||||||
logger.debug("Replacing file name %s with download name %s" % (filename, newfilePath), "EXCEPTION")
|
logger.debug("Replacing file name {old} with download name {new}".format
|
||||||
|
(old=filename, new=newfilePath), "EXCEPTION")
|
||||||
try:
|
try:
|
||||||
os.rename(filename, newfilePath)
|
os.rename(filename, newfilePath)
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION")
|
||||||
|
|
||||||
|
|
||||||
def replace_filename(filename, dirname, name):
|
def replace_filename(filename, dirname, name):
|
||||||
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
||||||
if media_pattern.search(os.path.basename(dirname).replace(' ', '.')) is not None:
|
if media_pattern.search(os.path.basename(dirname).replace(' ', '.')) is not None:
|
||||||
newname = os.path.basename(dirname).replace(' ', '.')
|
newname = os.path.basename(dirname).replace(' ', '.')
|
||||||
logger.debug("Replacing file name %s with directory name %s" % (head, newname), "EXCEPTION")
|
logger.debug("Replacing file name {old} with directory name {new}".format(old=head, new=newname), "EXCEPTION")
|
||||||
elif media_pattern.search(name.replace(' ', '.').lower()) is not None:
|
elif media_pattern.search(name.replace(' ', '.').lower()) is not None:
|
||||||
newname = name.replace(' ', '.')
|
newname = name.replace(' ', '.')
|
||||||
logger.debug("Replacing file name %s with download name %s" % (head, newname), "EXCEPTION")
|
logger.debug("Replacing file name {old} with download name {new}".format
|
||||||
|
(old=head, new=newname), "EXCEPTION")
|
||||||
else:
|
else:
|
||||||
logger.warning("No name replacement determined for %s" % (head), "EXCEPTION")
|
logger.warning("No name replacement determined for {name}".format(name=head), "EXCEPTION")
|
||||||
newname = name
|
newname = name
|
||||||
newfile = newname + fileExtension
|
newfile = newname + fileExtension
|
||||||
newfilePath = os.path.join(dirname, newfile)
|
newfilePath = os.path.join(dirname, newfile)
|
||||||
|
@ -103,7 +105,8 @@ def reverse_filename(filename, dirname, name):
|
||||||
else:
|
else:
|
||||||
newname = head[::-1].title()
|
newname = head[::-1].title()
|
||||||
newname = newname.replace(' ', '.')
|
newname = newname.replace(' ', '.')
|
||||||
logger.debug("Reversing filename %s to %s" % (head, newname), "EXCEPTION")
|
logger.debug("Reversing filename {old} to {new}".format
|
||||||
|
(old=head, new=newname), "EXCEPTION")
|
||||||
newfile = newname + fileExtension
|
newfile = newname + fileExtension
|
||||||
newfilePath = os.path.join(dirname, newfile)
|
newfilePath = os.path.join(dirname, newfile)
|
||||||
return newfilePath
|
return newfilePath
|
||||||
|
@ -129,11 +132,12 @@ def rename_script(dirname):
|
||||||
dest = os.path.join(dirname, cmd[1].split('\\')[-1].split('/')[-1])
|
dest = os.path.join(dirname, cmd[1].split('\\')[-1].split('/')[-1])
|
||||||
if os.path.isfile(dest):
|
if os.path.isfile(dest):
|
||||||
continue
|
continue
|
||||||
logger.debug("Renaming file %s to %s" % (orig, dest), "EXCEPTION")
|
logger.debug("Renaming file {source} to {destination}".format
|
||||||
|
(source=orig, destination=dest), "EXCEPTION")
|
||||||
try:
|
try:
|
||||||
os.rename(orig, dest)
|
os.rename(orig, dest)
|
||||||
except Exception as e:
|
except Exception as error:
|
||||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION")
|
||||||
|
|
||||||
# dict for custom groups
|
# dict for custom groups
|
||||||
# we can add more to this list
|
# we can add more to this list
|
||||||
|
|
|
@ -48,7 +48,7 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
if transcoder.isVideoGood(video, 0):
|
if transcoder.isVideoGood(video, 0):
|
||||||
import_subs(video)
|
import_subs(video)
|
||||||
else:
|
else:
|
||||||
logger.info("Corrupt video file found %s. Deleting." % (video), "USERSCRIPT")
|
logger.info("Corrupt video file found {0}. Deleting.".format(video), "USERSCRIPT")
|
||||||
os.unlink(video)
|
os.unlink(video)
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
||||||
|
@ -64,22 +64,22 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
command = [core.USER_SCRIPT]
|
command = [core.USER_SCRIPT]
|
||||||
for param in core.USER_SCRIPT_PARAM:
|
for param in core.USER_SCRIPT_PARAM:
|
||||||
if param == "FN":
|
if param == "FN":
|
||||||
command.append('%s' % file)
|
command.append('{0}'.format(file))
|
||||||
continue
|
continue
|
||||||
elif param == "FP":
|
elif param == "FP":
|
||||||
command.append('%s' % filePath)
|
command.append('{0}'.format(filePath))
|
||||||
continue
|
continue
|
||||||
elif param == "TN":
|
elif param == "TN":
|
||||||
command.append('%s' % torrentName)
|
command.append('{0}'.format(torrentName))
|
||||||
continue
|
continue
|
||||||
elif param == "TL":
|
elif param == "TL":
|
||||||
command.append('%s' % torrentLabel)
|
command.append('{0}'.format(torrentLabel))
|
||||||
continue
|
continue
|
||||||
elif param == "DN":
|
elif param == "DN":
|
||||||
if core.USER_SCRIPT_RUNONCE == 1:
|
if core.USER_SCRIPT_RUNONCE == 1:
|
||||||
command.append('%s' % outputDestination)
|
command.append('{0}'.format(outputDestination))
|
||||||
else:
|
else:
|
||||||
command.append('%s' % dirpath)
|
command.append('{0}'.format(dirpath))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
command.append(param)
|
command.append(param)
|
||||||
|
@ -87,21 +87,21 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
cmd = ""
|
cmd = ""
|
||||||
for item in command:
|
for item in command:
|
||||||
cmd = cmd + " " + item
|
cmd = cmd + " " + item
|
||||||
logger.info("Running script %s on file %s." % (cmd, filePath), "USERSCRIPT")
|
logger.info("Running script {0} on file {1}.".format(cmd, filePath), "USERSCRIPT")
|
||||||
try:
|
try:
|
||||||
p = Popen(command)
|
p = Popen(command)
|
||||||
res = p.wait()
|
res = p.wait()
|
||||||
if str(res) in core.USER_SCRIPT_SUCCESSCODES: # Linux returns 0 for successful.
|
if str(res) in core.USER_SCRIPT_SUCCESSCODES: # Linux returns 0 for successful.
|
||||||
logger.info("UserScript %s was successfull" % (command[0]))
|
logger.info("UserScript {0} was successfull".format(command[0]))
|
||||||
result = 0
|
result = 0
|
||||||
else:
|
else:
|
||||||
logger.error("UserScript %s has failed with return code: %s" % (command[0], res), "USERSCRIPT")
|
logger.error("UserScript {0} has failed with return code: {1}".format(command[0], res), "USERSCRIPT")
|
||||||
logger.info(
|
logger.info(
|
||||||
"If the UserScript completed successfully you should add %s to the user_script_successCodes" % (
|
"If the UserScript completed successfully you should add {0} to the user_script_successCodes".format(
|
||||||
res), "USERSCRIPT")
|
res), "USERSCRIPT")
|
||||||
result = int(1)
|
result = int(1)
|
||||||
except:
|
except:
|
||||||
logger.error("UserScript %s has failed" % (command[0]), "USERSCRIPT")
|
logger.error("UserScript {0} has failed".format(command[0]), "USERSCRIPT")
|
||||||
result = int(1)
|
result = int(1)
|
||||||
final_result += result
|
final_result += result
|
||||||
|
|
||||||
|
@ -114,9 +114,9 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
num_files_new += 1
|
num_files_new += 1
|
||||||
|
|
||||||
if core.USER_SCRIPT_CLEAN == int(1) and num_files_new == 0 and final_result == 0:
|
if core.USER_SCRIPT_CLEAN == int(1) and num_files_new == 0 and final_result == 0:
|
||||||
logger.info("All files have been processed. Cleaning outputDirectory %s" % (outputDestination))
|
logger.info("All files have been processed. Cleaning outputDirectory {0}".format(outputDestination))
|
||||||
rmDir(outputDestination)
|
rmDir(outputDestination)
|
||||||
elif core.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0:
|
elif core.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0:
|
||||||
logger.info("%s files were processed, but %s still remain. outputDirectory will not be cleaned." % (
|
logger.info("{0} files were processed, but {1} still remain. outputDirectory will not be cleaned.".format(
|
||||||
num_files, num_files_new))
|
num_files, num_files_new))
|
||||||
return [final_result, '']
|
return [final_result, '']
|
||||||
|
|
|
@ -40,7 +40,7 @@ def reportNzb(failure_link, clientAgent):
|
||||||
try:
|
try:
|
||||||
requests.post(failure_link, headers=headers, timeout=(30, 300))
|
requests.post(failure_link, headers=headers, timeout=(30, 300))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Unable to open URL %s due to %s" % (failure_link, e))
|
logger.error("Unable to open URL {0} due to {1}".format(failure_link, e))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,13 +115,13 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
pathlist = os.path.normpath(inputDirectory).split(os.sep)
|
pathlist = os.path.normpath(inputDirectory).split(os.sep)
|
||||||
|
|
||||||
if inputCategory and inputCategory in pathlist:
|
if inputCategory and inputCategory in pathlist:
|
||||||
logger.debug("SEARCH: Found the Category: %s in directory structure" % (inputCategory))
|
logger.debug("SEARCH: Found the Category: {0} in directory structure".format(inputCategory))
|
||||||
elif inputCategory:
|
elif inputCategory:
|
||||||
logger.debug("SEARCH: Could not find the category: %s in the directory structure" % (inputCategory))
|
logger.debug("SEARCH: Could not find the category: {0} in the directory structure".format(inputCategory))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
inputCategory = list(set(pathlist) & set(categories))[-1] # assume last match is most relevant category.
|
inputCategory = list(set(pathlist) & set(categories))[-1] # assume last match is most relevant category.
|
||||||
logger.debug("SEARCH: Found Category: %s in directory structure" % (inputCategory))
|
logger.debug("SEARCH: Found Category: {0} in directory structure".format(inputCategory))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
inputCategory = ""
|
inputCategory = ""
|
||||||
logger.debug("SEARCH: Could not find a category in the directory structure")
|
logger.debug("SEARCH: Could not find a category in the directory structure")
|
||||||
|
@ -132,30 +132,30 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
|
|
||||||
if inputCategory and os.path.isdir(os.path.join(inputDirectory, inputCategory)):
|
if inputCategory and os.path.isdir(os.path.join(inputDirectory, inputCategory)):
|
||||||
logger.info(
|
logger.info(
|
||||||
"SEARCH: Found category directory %s in input directory directory %s" % (inputCategory, inputDirectory))
|
"SEARCH: Found category directory {0} in input directory directory {1}".format(inputCategory, inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, inputCategory)
|
inputDirectory = os.path.join(inputDirectory, inputCategory)
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory))
|
||||||
if inputName and os.path.isdir(os.path.join(inputDirectory, inputName)):
|
if inputName and os.path.isdir(os.path.join(inputDirectory, inputName)):
|
||||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (inputName, inputDirectory))
|
logger.info("SEARCH: Found torrent directory {0} in input directory directory {1}".format(inputName, inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, inputName)
|
inputDirectory = os.path.join(inputDirectory, inputName)
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
elif inputName and os.path.isdir(os.path.join(inputDirectory, sanitizeName(inputName))):
|
elif inputName and os.path.isdir(os.path.join(inputDirectory, sanitizeName(inputName))):
|
||||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (
|
logger.info("SEARCH: Found torrent directory {0} in input directory directory {1}".format(
|
||||||
sanitizeName(inputName), inputDirectory))
|
sanitizeName(inputName), inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName))
|
inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName))
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
elif inputName and os.path.isfile(os.path.join(inputDirectory, inputName)):
|
elif inputName and os.path.isfile(os.path.join(inputDirectory, inputName)):
|
||||||
logger.info("SEARCH: Found torrent file %s in input directory directory %s" % (inputName, inputDirectory))
|
logger.info("SEARCH: Found torrent file {0} in input directory directory {1}".format(inputName, inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, inputName)
|
inputDirectory = os.path.join(inputDirectory, inputName)
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
elif inputName and os.path.isfile(os.path.join(inputDirectory, sanitizeName(inputName))):
|
elif inputName and os.path.isfile(os.path.join(inputDirectory, sanitizeName(inputName))):
|
||||||
logger.info("SEARCH: Found torrent file %s in input directory directory %s" % (
|
logger.info("SEARCH: Found torrent file {0} in input directory directory {1}".format(
|
||||||
sanitizeName(inputName), inputDirectory))
|
sanitizeName(inputName), inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName))
|
inputDirectory = os.path.join(inputDirectory, sanitizeName(inputName))
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to {0}".format(inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
|
|
||||||
imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path.
|
imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path.
|
||||||
|
@ -168,7 +168,8 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
index = pathlist.index(inputCategory)
|
index = pathlist.index(inputCategory)
|
||||||
if index + 1 < len(pathlist):
|
if index + 1 < len(pathlist):
|
||||||
tordir = True
|
tordir = True
|
||||||
logger.info("SEARCH: Found a unique directory %s in the category directory" % (pathlist[index + 1]))
|
logger.info("SEARCH: Found a unique directory {0} in the category directory".format
|
||||||
|
(pathlist[index + 1]))
|
||||||
if not inputName:
|
if not inputName:
|
||||||
inputName = pathlist[index + 1]
|
inputName = pathlist[index + 1]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -176,7 +177,7 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
|
|
||||||
if inputName and not tordir:
|
if inputName and not tordir:
|
||||||
if inputName in pathlist or sanitizeName(inputName) in pathlist:
|
if inputName in pathlist or sanitizeName(inputName) in pathlist:
|
||||||
logger.info("SEARCH: Found torrent directory %s in the directory structure" % (inputName))
|
logger.info("SEARCH: Found torrent directory {0} in the directory structure".format(inputName))
|
||||||
tordir = True
|
tordir = True
|
||||||
else:
|
else:
|
||||||
root = 1
|
root = 1
|
||||||
|
@ -206,7 +207,7 @@ def is_minSize(inputName, minSize):
|
||||||
try:
|
try:
|
||||||
inputSize = getDirSize(os.path.dirname(inputName))
|
inputSize = getDirSize(os.path.dirname(inputName))
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to get file size for %s" % (inputName), 'MINSIZE')
|
logger.error("Failed to get file size for {0}".format(inputName), 'MINSIZE')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Ignore files under a certain size
|
# Ignore files under a certain size
|
||||||
|
@ -221,9 +222,9 @@ def is_sample(inputName):
|
||||||
|
|
||||||
|
|
||||||
def copy_link(src, targetLink, useLink):
|
def copy_link(src, targetLink, useLink):
|
||||||
logger.info("MEDIAFILE: [%s]" % (os.path.basename(targetLink)), 'COPYLINK')
|
logger.info("MEDIAFILE: [{0}]".format(os.path.basename(targetLink)), 'COPYLINK')
|
||||||
logger.info("SOURCE FOLDER: [%s]" % (os.path.dirname(src)), 'COPYLINK')
|
logger.info("SOURCE FOLDER: [{0}]".format(os.path.dirname(src)), 'COPYLINK')
|
||||||
logger.info("TARGET FOLDER: [%s]" % (os.path.dirname(targetLink)), 'COPYLINK')
|
logger.info("TARGET FOLDER: [{0}]".format(os.path.dirname(targetLink)), 'COPYLINK')
|
||||||
|
|
||||||
if src != targetLink and os.path.exists(targetLink):
|
if src != targetLink and os.path.exists(targetLink):
|
||||||
logger.info("MEDIAFILE already exists in the TARGET folder, skipping ...", 'COPYLINK')
|
logger.info("MEDIAFILE already exists in the TARGET folder, skipping ...", 'COPYLINK')
|
||||||
|
@ -263,7 +264,7 @@ def copy_link(src, targetLink, useLink):
|
||||||
shutil.move(src, targetLink)
|
shutil.move(src, targetLink)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Error: %s, copying instead ... " % (e), 'COPYLINK')
|
logger.warning("Error: {0}, copying instead ... ".format(e), 'COPYLINK')
|
||||||
|
|
||||||
logger.info("Copying SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
logger.info("Copying SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK')
|
||||||
shutil.copy(src, targetLink)
|
shutil.copy(src, targetLink)
|
||||||
|
@ -277,26 +278,26 @@ def replace_links(link):
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import jaraco
|
import jaraco
|
||||||
if not jaraco.windows.filesystem.islink(link):
|
if not jaraco.windows.filesystem.islink(link):
|
||||||
logger.debug('%s is not a link' % (link))
|
logger.debug('{0} is not a link'.format(link))
|
||||||
return
|
return
|
||||||
while jaraco.windows.filesystem.islink(target):
|
while jaraco.windows.filesystem.islink(target):
|
||||||
target = jaraco.windows.filesystem.readlink(target)
|
target = jaraco.windows.filesystem.readlink(target)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
else:
|
else:
|
||||||
if not os.path.islink(link):
|
if not os.path.islink(link):
|
||||||
logger.debug('%s is not a link' % (link))
|
logger.debug('{0} is not a link'.format(link))
|
||||||
return
|
return
|
||||||
while os.path.islink(target):
|
while os.path.islink(target):
|
||||||
target = os.readlink(target)
|
target = os.readlink(target)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
if n > 1:
|
if n > 1:
|
||||||
logger.info("Changing sym-link: %s to point directly to file: %s" % (link, target), 'COPYLINK')
|
logger.info("Changing sym-link: {0} to point directly to file: {1}".format(link, target), 'COPYLINK')
|
||||||
os.unlink(link)
|
os.unlink(link)
|
||||||
linktastic.symlink(target, link)
|
linktastic.symlink(target, link)
|
||||||
|
|
||||||
|
|
||||||
def flatten(outputDestination):
|
def flatten(outputDestination):
|
||||||
logger.info("FLATTEN: Flattening directory: %s" % (outputDestination))
|
logger.info("FLATTEN: Flattening directory: {0}".format(outputDestination))
|
||||||
for outputFile in listMediaFiles(outputDestination):
|
for outputFile in listMediaFiles(outputDestination):
|
||||||
dirPath = os.path.dirname(outputFile)
|
dirPath = os.path.dirname(outputFile)
|
||||||
fileName = os.path.basename(outputFile)
|
fileName = os.path.basename(outputFile)
|
||||||
|
@ -309,7 +310,7 @@ def flatten(outputDestination):
|
||||||
try:
|
try:
|
||||||
shutil.move(outputFile, target)
|
shutil.move(outputFile, target)
|
||||||
except:
|
except:
|
||||||
logger.error("Could not flatten %s" % (outputFile), 'FLATTEN')
|
logger.error("Could not flatten {0}".format(outputFile), 'FLATTEN')
|
||||||
|
|
||||||
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
||||||
|
|
||||||
|
@ -320,7 +321,7 @@ def removeEmptyFolders(path, removeRoot=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
# remove empty subfolders
|
# remove empty subfolders
|
||||||
logger.debug("Checking for empty folders in:%s" % (path))
|
logger.debug("Checking for empty folders in:{0}".format(path))
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
if len(files):
|
if len(files):
|
||||||
for f in files:
|
for f in files:
|
||||||
|
@ -331,7 +332,7 @@ def removeEmptyFolders(path, removeRoot=True):
|
||||||
# if folder empty, delete it
|
# if folder empty, delete it
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
if len(files) == 0 and removeRoot:
|
if len(files) == 0 and removeRoot:
|
||||||
logger.debug("Removing empty folder:%s" % (path))
|
logger.debug("Removing empty folder:{}".format(path))
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -386,16 +387,16 @@ def WakeUp():
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
while TestCon(host, port) == "Down" and i < 4:
|
while TestCon(host, port) == "Down" and i < 4:
|
||||||
logger.info(("Sending WakeOnLan Magic Packet for mac: %s" % (mac)))
|
logger.info(("Sending WakeOnLan Magic Packet for mac: {0}".format(mac)))
|
||||||
WakeOnLan(mac)
|
WakeOnLan(mac)
|
||||||
time.sleep(20)
|
time.sleep(20)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
if TestCon(host, port) == "Down": # final check.
|
if TestCon(host, port) == "Down": # final check.
|
||||||
logger.warning("System with mac: %s has not woken after 3 attempts. Continuing with the rest of the script." % (
|
logger.warning("System with mac: {0} has not woken after 3 attempts. "
|
||||||
mac))
|
"Continuing with the rest of the script.".format(mac))
|
||||||
else:
|
else:
|
||||||
logger.info("System with mac: %s has been woken. Continuing with the rest of the script." % (mac))
|
logger.info("System with mac: {0} has been woken. Continuing with the rest of the script.".format(mac))
|
||||||
|
|
||||||
|
|
||||||
def CharReplace(Name):
|
def CharReplace(Name):
|
||||||
|
@ -454,23 +455,23 @@ def convert_to_ascii(inputName, dirName):
|
||||||
encoded, base2 = CharReplace(base)
|
encoded, base2 = CharReplace(base)
|
||||||
if encoded:
|
if encoded:
|
||||||
dirName = os.path.join(dir, base2)
|
dirName = os.path.join(dir, base2)
|
||||||
logger.info("Renaming directory to: %s." % (base2), 'ENCODER')
|
logger.info("Renaming directory to: {0}.".format(base2), 'ENCODER')
|
||||||
os.rename(os.path.join(dir, base), dirName)
|
os.rename(os.path.join(dir, base), dirName)
|
||||||
if 'NZBOP_SCRIPTDIR' in os.environ:
|
if 'NZBOP_SCRIPTDIR' in os.environ:
|
||||||
print("[NZB] DIRECTORY=%s" % (dirName))
|
print("[NZB] DIRECTORY={0}".format(dirName))
|
||||||
|
|
||||||
for dirname, dirnames, filenames in os.walk(dirName, topdown=False):
|
for dirname, dirnames, filenames in os.walk(dirName, topdown=False):
|
||||||
for subdirname in dirnames:
|
for subdirname in dirnames:
|
||||||
encoded, subdirname2 = CharReplace(subdirname)
|
encoded, subdirname2 = CharReplace(subdirname)
|
||||||
if encoded:
|
if encoded:
|
||||||
logger.info("Renaming directory to: %s." % (subdirname2), 'ENCODER')
|
logger.info("Renaming directory to: {0}.".format(subdirname2), 'ENCODER')
|
||||||
os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2))
|
os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2))
|
||||||
|
|
||||||
for dirname, dirnames, filenames in os.walk(dirName):
|
for dirname, dirnames, filenames in os.walk(dirName):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
encoded, filename2 = CharReplace(filename)
|
encoded, filename2 = CharReplace(filename)
|
||||||
if encoded:
|
if encoded:
|
||||||
logger.info("Renaming file to: %s." % (filename2), 'ENCODER')
|
logger.info("Renaming file to: {0}.".format(filename2), 'ENCODER')
|
||||||
os.rename(os.path.join(dirname, filename), os.path.join(dirname, filename2))
|
os.rename(os.path.join(dirname, filename), os.path.join(dirname, filename2))
|
||||||
|
|
||||||
return inputName, dirName
|
return inputName, dirName
|
||||||
|
@ -604,7 +605,7 @@ def getDirs(section, subsection, link='hard'):
|
||||||
def processDir(path):
|
def processDir(path):
|
||||||
folders = []
|
folders = []
|
||||||
|
|
||||||
logger.info("Searching %s for mediafiles to post-process ..." % (path))
|
logger.info("Searching {0} for mediafiles to post-process ...".format(path))
|
||||||
sync = [o for o in os.listdir(path) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
|
sync = [o for o in os.listdir(path) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
|
||||||
# search for single files and move them into their own folder for post-processing
|
# search for single files and move them into their own folder for post-processing
|
||||||
for mediafile in [os.path.join(path, o) for o in os.listdir(path) if
|
for mediafile in [os.path.join(path, o) for o in os.listdir(path) if
|
||||||
|
@ -614,7 +615,7 @@ def getDirs(section, subsection, link='hard'):
|
||||||
if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']:
|
if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
logger.debug("Found file %s in root directory %s." % (os.path.split(mediafile)[1], path))
|
logger.debug("Found file {0} in root directory {1}.".format(os.path.split(mediafile)[1], path))
|
||||||
newPath = None
|
newPath = None
|
||||||
fileExt = os.path.splitext(mediafile)[1]
|
fileExt = os.path.splitext(mediafile)[1]
|
||||||
try:
|
try:
|
||||||
|
@ -626,7 +627,7 @@ def getDirs(section, subsection, link='hard'):
|
||||||
album = f.album
|
album = f.album
|
||||||
|
|
||||||
# create new path
|
# create new path
|
||||||
newPath = os.path.join(path, "%s - %s" % (sanitizeName(artist), sanitizeName(album)))
|
newPath = os.path.join(path, "{0} - {1}".format(sanitizeName(artist), sanitizeName(album)))
|
||||||
elif fileExt in core.MEDIACONTAINER:
|
elif fileExt in core.MEDIACONTAINER:
|
||||||
f = guessit.guess_video_info(mediafile)
|
f = guessit.guess_video_info(mediafile)
|
||||||
|
|
||||||
|
@ -638,7 +639,7 @@ def getDirs(section, subsection, link='hard'):
|
||||||
|
|
||||||
newPath = os.path.join(path, sanitizeName(title))
|
newPath = os.path.join(path, sanitizeName(title))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception parsing name for media file: %s: %s" % (os.path.split(mediafile)[1], e))
|
logger.error("Exception parsing name for media file: {0}: {1}".format(os.path.split(mediafile)[1], e))
|
||||||
|
|
||||||
if not newPath:
|
if not newPath:
|
||||||
title = os.path.splitext(os.path.basename(mediafile))[0]
|
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||||
|
@ -667,7 +668,7 @@ def getDirs(section, subsection, link='hard'):
|
||||||
# link file to its new path
|
# link file to its new path
|
||||||
copy_link(mediafile, newfile, link)
|
copy_link(mediafile, newfile, link)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to move %s to its own directory: %s" % (os.path.split(mediafile)[1], e))
|
logger.error("Failed to move {0} to its own directory: {1}".format(os.path.split(mediafile)[1], e))
|
||||||
|
|
||||||
# removeEmptyFolders(path, removeRoot=False)
|
# removeEmptyFolders(path, removeRoot=False)
|
||||||
|
|
||||||
|
@ -687,8 +688,8 @@ def getDirs(section, subsection, link='hard'):
|
||||||
elif os.path.exists(core.CFG[section][subsection]["watch_dir"]):
|
elif os.path.exists(core.CFG[section][subsection]["watch_dir"]):
|
||||||
to_return.extend(processDir(core.CFG[section][subsection]["watch_dir"]))
|
to_return.extend(processDir(core.CFG[section][subsection]["watch_dir"]))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to add directories from %s for post-processing: %s" % (
|
logger.error("Failed to add directories from {0} for post-processing: {1}".format
|
||||||
core.CFG[section][subsection]["watch_dir"], e))
|
(core.CFG[section][subsection]["watch_dir"], e))
|
||||||
|
|
||||||
if core.USELINK == 'move':
|
if core.USELINK == 'move':
|
||||||
try:
|
try:
|
||||||
|
@ -696,10 +697,10 @@ def getDirs(section, subsection, link='hard'):
|
||||||
if os.path.exists(outputDirectory):
|
if os.path.exists(outputDirectory):
|
||||||
to_return.extend(processDir(outputDirectory))
|
to_return.extend(processDir(outputDirectory))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to add directories from %s for post-processing: %s" % (core.OUTPUTDIRECTORY, e))
|
logger.error("Failed to add directories from {0} for post-processing: {1}".format(core.OUTPUTDIRECTORY, e))
|
||||||
|
|
||||||
if not to_return:
|
if not to_return:
|
||||||
logger.debug("No directories identified in %s:%s for post-processing" % (section, subsection))
|
logger.debug("No directories identified in {0}:{1} for post-processing".format(section, subsection))
|
||||||
|
|
||||||
return list(set(to_return))
|
return list(set(to_return))
|
||||||
|
|
||||||
|
@ -724,19 +725,19 @@ def onerror(func, path, exc_info):
|
||||||
|
|
||||||
|
|
||||||
def rmDir(dirName):
|
def rmDir(dirName):
|
||||||
logger.info("Deleting %s" % (dirName))
|
logger.info("Deleting {0}".format(dirName))
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(dirName, onerror=onerror)
|
shutil.rmtree(dirName, onerror=onerror)
|
||||||
except:
|
except:
|
||||||
logger.error("Unable to delete folder %s" % (dirName))
|
logger.error("Unable to delete folder {0}".format(dirName))
|
||||||
|
|
||||||
|
|
||||||
def cleanDir(path, section, subsection):
|
def cleanDir(path, section, subsection):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
logger.info('Directory %s has been processed and removed ...' % (path), 'CLEANDIR')
|
logger.info('Directory {0} has been processed and removed ...'.format(path), 'CLEANDIR')
|
||||||
return
|
return
|
||||||
if core.FORCE_CLEAN and not core.FAILED:
|
if core.FORCE_CLEAN and not core.FAILED:
|
||||||
logger.info('Doing Forceful Clean of %s' % (path), 'CLEANDIR')
|
logger.info('Doing Forceful Clean of {0}'.format(path), 'CLEANDIR')
|
||||||
rmDir(path)
|
rmDir(path)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
@ -753,15 +754,15 @@ def cleanDir(path, section, subsection):
|
||||||
num_files = 'unknown'
|
num_files = 'unknown'
|
||||||
if num_files > 0:
|
if num_files > 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Directory %s still contains %s unprocessed file(s), skipping ..." % (path, num_files),
|
"Directory {0} still contains {1} unprocessed file(s), skipping ...".format(path, num_files),
|
||||||
'CLEANDIRS')
|
'CLEANDIRS')
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info("Directory %s has been processed, removing ..." % (path), 'CLEANDIRS')
|
logger.info("Directory {0} has been processed, removing ...".format(path), 'CLEANDIRS')
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path, onerror=onerror)
|
shutil.rmtree(path, onerror=onerror)
|
||||||
except:
|
except:
|
||||||
logger.error("Unable to delete directory %s" % (path))
|
logger.error("Unable to delete directory {0}".format(path))
|
||||||
|
|
||||||
|
|
||||||
def create_torrent_class(clientAgent):
|
def create_torrent_class(clientAgent):
|
||||||
|
@ -770,14 +771,14 @@ def create_torrent_class(clientAgent):
|
||||||
|
|
||||||
if clientAgent == 'utorrent':
|
if clientAgent == 'utorrent':
|
||||||
try:
|
try:
|
||||||
logger.debug("Connecting to %s: %s" % (clientAgent, core.UTORRENTWEBUI))
|
logger.debug("Connecting to {0}: {1}".format(clientAgent, core.UTORRENTWEBUI))
|
||||||
tc = UTorrentClient(core.UTORRENTWEBUI, core.UTORRENTUSR, core.UTORRENTPWD)
|
tc = UTorrentClient(core.UTORRENTWEBUI, core.UTORRENTUSR, core.UTORRENTPWD)
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to connect to uTorrent")
|
logger.error("Failed to connect to uTorrent")
|
||||||
|
|
||||||
if clientAgent == 'transmission':
|
if clientAgent == 'transmission':
|
||||||
try:
|
try:
|
||||||
logger.debug("Connecting to %s: http://%s:%s" % (
|
logger.debug("Connecting to {0}: http://{1}:{2}".format(
|
||||||
clientAgent, core.TRANSMISSIONHOST, core.TRANSMISSIONPORT))
|
clientAgent, core.TRANSMISSIONHOST, core.TRANSMISSIONPORT))
|
||||||
tc = TransmissionClient(core.TRANSMISSIONHOST, core.TRANSMISSIONPORT,
|
tc = TransmissionClient(core.TRANSMISSIONHOST, core.TRANSMISSIONPORT,
|
||||||
core.TRANSMISSIONUSR,
|
core.TRANSMISSIONUSR,
|
||||||
|
@ -787,7 +788,7 @@ def create_torrent_class(clientAgent):
|
||||||
|
|
||||||
if clientAgent == 'deluge':
|
if clientAgent == 'deluge':
|
||||||
try:
|
try:
|
||||||
logger.debug("Connecting to %s: http://%s:%s" % (clientAgent, core.DELUGEHOST, core.DELUGEPORT))
|
logger.debug("Connecting to {0}: http://{1}:{2}".format(clientAgent, core.DELUGEHOST, core.DELUGEPORT))
|
||||||
tc = DelugeClient()
|
tc = DelugeClient()
|
||||||
tc.connect(host=core.DELUGEHOST, port=core.DELUGEPORT, username=core.DELUGEUSR,
|
tc.connect(host=core.DELUGEHOST, port=core.DELUGEPORT, username=core.DELUGEUSR,
|
||||||
password=core.DELUGEPWD)
|
password=core.DELUGEPWD)
|
||||||
|
@ -798,7 +799,7 @@ def create_torrent_class(clientAgent):
|
||||||
|
|
||||||
|
|
||||||
def pause_torrent(clientAgent, inputHash, inputID, inputName):
|
def pause_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
logger.debug("Stopping torrent %s in %s while processing" % (inputName, clientAgent))
|
logger.debug("Stopping torrent {0} in {1} while processing".format(inputName, clientAgent))
|
||||||
try:
|
try:
|
||||||
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
||||||
core.TORRENT_CLASS.stop(inputHash)
|
core.TORRENT_CLASS.stop(inputHash)
|
||||||
|
@ -808,13 +809,13 @@ def pause_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
core.TORRENT_CLASS.core.pause_torrent([inputID])
|
core.TORRENT_CLASS.core.pause_torrent([inputID])
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
except:
|
except:
|
||||||
logger.warning("Failed to stop torrent %s in %s" % (inputName, clientAgent))
|
logger.warning("Failed to stop torrent {0} in {1}".format(inputName, clientAgent))
|
||||||
|
|
||||||
|
|
||||||
def resume_torrent(clientAgent, inputHash, inputID, inputName):
|
def resume_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
if not core.TORRENT_RESUME == 1:
|
if not core.TORRENT_RESUME == 1:
|
||||||
return
|
return
|
||||||
logger.debug("Starting torrent %s in %s" % (inputName, clientAgent))
|
logger.debug("Starting torrent {0} in {1}".format(inputName, clientAgent))
|
||||||
try:
|
try:
|
||||||
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
||||||
core.TORRENT_CLASS.start(inputHash)
|
core.TORRENT_CLASS.start(inputHash)
|
||||||
|
@ -824,12 +825,12 @@ def resume_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
core.TORRENT_CLASS.core.resume_torrent([inputID])
|
core.TORRENT_CLASS.core.resume_torrent([inputID])
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
except:
|
except:
|
||||||
logger.warning("Failed to start torrent %s in %s" % (inputName, clientAgent))
|
logger.warning("Failed to start torrent {0} in {1}".format(inputName, clientAgent))
|
||||||
|
|
||||||
|
|
||||||
def remove_torrent(clientAgent, inputHash, inputID, inputName):
|
def remove_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
if core.DELETE_ORIGINAL == 1 or core.USELINK == 'move':
|
if core.DELETE_ORIGINAL == 1 or core.USELINK == 'move':
|
||||||
logger.debug("Deleting torrent %s from %s" % (inputName, clientAgent))
|
logger.debug("Deleting torrent {0} from {1}".format(inputName, clientAgent))
|
||||||
try:
|
try:
|
||||||
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
if clientAgent == 'utorrent' and core.TORRENT_CLASS != "":
|
||||||
core.TORRENT_CLASS.removedata(inputHash)
|
core.TORRENT_CLASS.removedata(inputHash)
|
||||||
|
@ -840,13 +841,13 @@ def remove_torrent(clientAgent, inputHash, inputID, inputName):
|
||||||
core.TORRENT_CLASS.core.remove_torrent(inputID, True)
|
core.TORRENT_CLASS.core.remove_torrent(inputID, True)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
except:
|
except:
|
||||||
logger.warning("Failed to delete torrent %s in %s" % (inputName, clientAgent))
|
logger.warning("Failed to delete torrent {0} in {1}".format(inputName, clientAgent))
|
||||||
else:
|
else:
|
||||||
resume_torrent(clientAgent, inputHash, inputID, inputName)
|
resume_torrent(clientAgent, inputHash, inputID, inputName)
|
||||||
|
|
||||||
|
|
||||||
def find_download(clientAgent, download_id):
|
def find_download(clientAgent, download_id):
|
||||||
logger.debug("Searching for Download on %s ..." % (clientAgent))
|
logger.debug("Searching for Download on {0} ...".format(clientAgent))
|
||||||
if clientAgent == 'utorrent':
|
if clientAgent == 'utorrent':
|
||||||
torrents = core.TORRENT_CLASS.list()[1]['torrents']
|
torrents = core.TORRENT_CLASS.list()[1]['torrents']
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
|
@ -862,9 +863,9 @@ def find_download(clientAgent, download_id):
|
||||||
return False
|
return False
|
||||||
if clientAgent == 'sabnzbd':
|
if clientAgent == 'sabnzbd':
|
||||||
if "http" in core.SABNZBDHOST:
|
if "http" in core.SABNZBDHOST:
|
||||||
baseURL = "%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT)
|
baseURL = "{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT)
|
||||||
else:
|
else:
|
||||||
baseURL = "http://%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT)
|
baseURL = "http://{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT)
|
||||||
url = baseURL
|
url = baseURL
|
||||||
params = {
|
params = {
|
||||||
'apikey': core.SABNZBDAPIKEY,
|
'apikey': core.SABNZBDAPIKEY,
|
||||||
|
@ -889,9 +890,9 @@ def get_nzoid(inputName):
|
||||||
slots = []
|
slots = []
|
||||||
logger.debug("Searching for nzoid from SAbnzbd ...")
|
logger.debug("Searching for nzoid from SAbnzbd ...")
|
||||||
if "http" in core.SABNZBDHOST:
|
if "http" in core.SABNZBDHOST:
|
||||||
baseURL = "%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT)
|
baseURL = "{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT)
|
||||||
else:
|
else:
|
||||||
baseURL = "http://%s:%s/api" % (core.SABNZBDHOST, core.SABNZBDPORT)
|
baseURL = "http://{0}:{1}/api".format(core.SABNZBDHOST, core.SABNZBDPORT)
|
||||||
url = baseURL
|
url = baseURL
|
||||||
params = {
|
params = {
|
||||||
'apikey': core.SABNZBDAPIKEY,
|
'apikey': core.SABNZBDAPIKEY,
|
||||||
|
@ -925,7 +926,7 @@ def get_nzoid(inputName):
|
||||||
for nzo_id, name in slots:
|
for nzo_id, name in slots:
|
||||||
if name in [inputName, cleanName]:
|
if name in [inputName, cleanName]:
|
||||||
nzoid = nzo_id
|
nzoid = nzo_id
|
||||||
logger.debug("Found nzoid: %s" % nzoid)
|
logger.debug("Found nzoid: {0}".format(nzoid))
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
logger.warning("Data from SABnzbd could not be parsed")
|
logger.warning("Data from SABnzbd could not be parsed")
|
||||||
|
@ -988,7 +989,8 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me
|
||||||
if delete_ignored == 1:
|
if delete_ignored == 1:
|
||||||
try:
|
try:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
logger.debug('Ignored file %s has been removed ...' % (curFile))
|
logger.debug('Ignored file {0} has been removed ...'.format
|
||||||
|
(curFile))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -1009,7 +1011,8 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me
|
||||||
if delete_ignored == 1:
|
if delete_ignored == 1:
|
||||||
try:
|
try:
|
||||||
os.unlink(fullCurFile)
|
os.unlink(fullCurFile)
|
||||||
logger.debug('Ignored file %s has been removed ...' % (curFile))
|
logger.debug('Ignored file {0} has been removed ...'.format
|
||||||
|
(curFile))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
continue
|
continue
|
||||||
|
@ -1022,21 +1025,21 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me
|
||||||
def find_imdbid(dirName, inputName):
|
def find_imdbid(dirName, inputName):
|
||||||
imdbid = None
|
imdbid = None
|
||||||
|
|
||||||
logger.info('Attemping imdbID lookup for %s' % (inputName))
|
logger.info('Attemping imdbID lookup for {0}'.format(inputName))
|
||||||
|
|
||||||
# find imdbid in dirName
|
# find imdbid in dirName
|
||||||
logger.info('Searching folder and file names for imdbID ...')
|
logger.info('Searching folder and file names for imdbID ...')
|
||||||
m = re.search('(tt\d{7})', dirName + inputName)
|
m = re.search('(tt\d{7})', dirName + inputName)
|
||||||
if m:
|
if m:
|
||||||
imdbid = m.group(1)
|
imdbid = m.group(1)
|
||||||
logger.info("Found imdbID [%s]" % imdbid)
|
logger.info("Found imdbID [{0}]".format(imdbid))
|
||||||
return imdbid
|
return imdbid
|
||||||
if os.path.isdir(dirName):
|
if os.path.isdir(dirName):
|
||||||
for file in os.listdir(dirName):
|
for file in os.listdir(dirName):
|
||||||
m = re.search('(tt\d{7})', file)
|
m = re.search('(tt\d{7})', file)
|
||||||
if m:
|
if m:
|
||||||
imdbid = m.group(1)
|
imdbid = m.group(1)
|
||||||
logger.info("Found imdbID [%s] via file name" % imdbid)
|
logger.info("Found imdbID [{0}] via file name".format(imdbid))
|
||||||
return imdbid
|
return imdbid
|
||||||
if 'NZBPR__DNZB_MOREINFO' in os.environ:
|
if 'NZBPR__DNZB_MOREINFO' in os.environ:
|
||||||
dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '')
|
dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '')
|
||||||
|
@ -1045,7 +1048,7 @@ def find_imdbid(dirName, inputName):
|
||||||
m = regex.match(dnzb_more_info)
|
m = regex.match(dnzb_more_info)
|
||||||
if m:
|
if m:
|
||||||
imdbid = m.group(1)
|
imdbid = m.group(1)
|
||||||
logger.info("Found imdbID [%s] from DNZB-MoreInfo" % imdbid)
|
logger.info("Found imdbID [{0}] from DNZB-MoreInfo".format(imdbid))
|
||||||
return imdbid
|
return imdbid
|
||||||
logger.info('Searching IMDB for imdbID ...')
|
logger.info('Searching IMDB for imdbID ...')
|
||||||
guess = guessit.guess_movie_info(inputName)
|
guess = guessit.guess_movie_info(inputName)
|
||||||
|
@ -1062,12 +1065,12 @@ def find_imdbid(dirName, inputName):
|
||||||
|
|
||||||
url = "http://www.omdbapi.com"
|
url = "http://www.omdbapi.com"
|
||||||
|
|
||||||
logger.debug("Opening URL: %s" % url)
|
logger.debug("Opening URL: {0}".format(url))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, params={'y': year, 't': title}, verify=False, timeout=(60, 300))
|
r = requests.get(url, params={'y': year, 't': title}, verify=False, timeout=(60, 300))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error("Unable to open URL %s" % url)
|
logger.error("Unable to open URL {0}".format(url))
|
||||||
return
|
return
|
||||||
|
|
||||||
results = r.json()
|
results = r.json()
|
||||||
|
@ -1078,10 +1081,10 @@ def find_imdbid(dirName, inputName):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if imdbid:
|
if imdbid:
|
||||||
logger.info("Found imdbID [%s]" % imdbid)
|
logger.info("Found imdbID [{0}]".format(imdbid))
|
||||||
return imdbid
|
return imdbid
|
||||||
|
|
||||||
logger.warning('Unable to find a imdbID for %s' % (inputName))
|
logger.warning('Unable to find a imdbID for {0}'.format(inputName))
|
||||||
return imdbid
|
return imdbid
|
||||||
|
|
||||||
|
|
||||||
|
@ -1103,7 +1106,7 @@ def extractFiles(src, dst=None, keep_archive=None):
|
||||||
extracted_folder.append(dst or dirPath)
|
extracted_folder.append(dst or dirPath)
|
||||||
extracted_archive.append(archiveName)
|
extracted_archive.append(archiveName)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Extraction failed for: %s" % (fullFileName))
|
logger.error("Extraction failed for: {0}".format(fullFileName))
|
||||||
|
|
||||||
for folder in extracted_folder:
|
for folder in extracted_folder:
|
||||||
for inputFile in listMediaFiles(folder, media=False, audio=False, meta=False, archives=True):
|
for inputFile in listMediaFiles(folder, media=False, audio=False, meta=False, archives=True):
|
||||||
|
@ -1112,14 +1115,14 @@ def extractFiles(src, dst=None, keep_archive=None):
|
||||||
archiveName = re.sub(r"part[0-9]+", "", archiveName)
|
archiveName = re.sub(r"part[0-9]+", "", archiveName)
|
||||||
if archiveName not in extracted_archive or keep_archive is True:
|
if archiveName not in extracted_archive or keep_archive is True:
|
||||||
continue # don't remove if we haven't extracted this archive, or if we want to preserve them.
|
continue # don't remove if we haven't extracted this archive, or if we want to preserve them.
|
||||||
logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder))
|
logger.info("Removing extracted archive {0} from folder {1} ...".format(fullFileName, folder))
|
||||||
try:
|
try:
|
||||||
if not os.access(inputFile, os.W_OK):
|
if not os.access(inputFile, os.W_OK):
|
||||||
os.chmod(inputFile, stat.S_IWUSR)
|
os.chmod(inputFile, stat.S_IWUSR)
|
||||||
os.remove(inputFile)
|
os.remove(inputFile)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Unable to remove file %s due to: %s" % (inputFile, e))
|
logger.error("Unable to remove file {0} due to: {1}".format(inputFile, e))
|
||||||
|
|
||||||
|
|
||||||
def import_subs(filename):
|
def import_subs(filename):
|
||||||
|
@ -1139,13 +1142,13 @@ def import_subs(filename):
|
||||||
if not languages:
|
if not languages:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("Attempting to download subtitles for %s" % (filename), 'SUBTITLES')
|
logger.debug("Attempting to download subtitles for {0}".format(filename), 'SUBTITLES')
|
||||||
try:
|
try:
|
||||||
video = subliminal.scan_video(filename, subtitles=True, embedded_subtitles=True)
|
video = subliminal.scan_video(filename, subtitles=True, embedded_subtitles=True)
|
||||||
subtitles = subliminal.download_best_subtitles({video}, languages, hearing_impaired=False)
|
subtitles = subliminal.download_best_subtitles({video}, languages, hearing_impaired=False)
|
||||||
subliminal.save_subtitles(subtitles)
|
subliminal.save_subtitles(subtitles)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to download subtitles for %s due to: %s" % (filename, e), 'SUBTITLES')
|
logger.error("Failed to download subtitles for {0} due to: {1}".format(filename, e), 'SUBTITLES')
|
||||||
|
|
||||||
|
|
||||||
def server_responding(baseURL):
|
def server_responding(baseURL):
|
||||||
|
@ -1167,7 +1170,7 @@ def plex_update(category):
|
||||||
section = None
|
section = None
|
||||||
if not core.PLEXSEC:
|
if not core.PLEXSEC:
|
||||||
return
|
return
|
||||||
logger.debug("Attempting to update Plex Library for category %s." % (category), 'PLEX')
|
logger.debug("Attempting to update Plex Library for category {0}.".format(category), 'PLEX')
|
||||||
for item in core.PLEXSEC:
|
for item in core.PLEXSEC:
|
||||||
if item[0] == category:
|
if item[0] == category:
|
||||||
section = item[1]
|
section = item[1]
|
||||||
|
@ -1210,7 +1213,7 @@ def backupVersionedFile(old_file, version):
|
||||||
|
|
||||||
|
|
||||||
def update_downloadInfoStatus(inputName, status):
|
def update_downloadInfoStatus(inputName, status):
|
||||||
logger.db("Updating status of our download %s in the DB to %s" % (inputName, status))
|
logger.db("Updating status of our download {0} in the DB to {1}".format(inputName, status))
|
||||||
|
|
||||||
myDB = nzbToMediaDB.DBConnection()
|
myDB = nzbToMediaDB.DBConnection()
|
||||||
myDB.action("UPDATE downloads SET status=?, last_update=? WHERE input_name=?",
|
myDB.action("UPDATE downloads SET status=?, last_update=? WHERE input_name=?",
|
||||||
|
@ -1218,7 +1221,7 @@ def update_downloadInfoStatus(inputName, status):
|
||||||
|
|
||||||
|
|
||||||
def get_downloadInfo(inputName, status):
|
def get_downloadInfo(inputName, status):
|
||||||
logger.db("Getting download info for %s from the DB" % (inputName))
|
logger.db("Getting download info for {0} from the DB".format(inputName))
|
||||||
|
|
||||||
myDB = nzbToMediaDB.DBConnection()
|
myDB = nzbToMediaDB.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT * FROM downloads WHERE input_name=? AND status=?",
|
sqlResults = myDB.select("SELECT * FROM downloads WHERE input_name=? AND status=?",
|
||||||
|
|
|
@ -435,7 +435,7 @@ def dumps(x, float_bits=DEFAULT_FLOAT_BITS):
|
||||||
elif float_bits == 64:
|
elif float_bits == 64:
|
||||||
encode_func[FloatType] = encode_float64
|
encode_func[FloatType] = encode_float64
|
||||||
else:
|
else:
|
||||||
raise ValueError('Float bits (%d) is not 32 or 64' % float_bits)
|
raise ValueError('Float bits ({0:d}) is not 32 or 64'.format(float_bits))
|
||||||
r = []
|
r = []
|
||||||
encode_func[type(x)](x, r)
|
encode_func[type(x)](x, r)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -37,24 +37,25 @@ def isVideoGood(videofile, status):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logger.info('Checking [%s] for corruption, please stand by ...' % (fileNameExt), 'TRANSCODER')
|
logger.info('Checking [{0}] for corruption, please stand by ...'.format(fileNameExt), 'TRANSCODER')
|
||||||
video_details, result = getVideoDetails(videofile)
|
video_details, result = getVideoDetails(videofile)
|
||||||
|
|
||||||
if result != 0:
|
if result != 0:
|
||||||
logger.error("FAILED: [%s] is corrupted!" % (fileNameExt), 'TRANSCODER')
|
logger.error("FAILED: [{0}] is corrupted!".format(fileNameExt), 'TRANSCODER')
|
||||||
return False
|
return False
|
||||||
if video_details.get("error"):
|
if video_details.get("error"):
|
||||||
logger.info("FAILED: [%s] returned error [%s]." % (fileNameExt, str(video_details.get("error"))), 'TRANSCODER')
|
logger.info("FAILED: [{0}] returned error [{1}].".format(fileNameExt, video_details.get("error")), 'TRANSCODER')
|
||||||
return False
|
return False
|
||||||
if video_details.get("streams"):
|
if video_details.get("streams"):
|
||||||
videoStreams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
videoStreams = [item for item in video_details["streams"] if item["codec_type"] == "video"]
|
||||||
audioStreams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
|
audioStreams = [item for item in video_details["streams"] if item["codec_type"] == "audio"]
|
||||||
if len(videoStreams) > 0 and len(audioStreams) > 0:
|
if len(videoStreams) > 0 and len(audioStreams) > 0:
|
||||||
logger.info("SUCCESS: [%s] has no corruption." % (fileNameExt), 'TRANSCODER')
|
logger.info("SUCCESS: [{0}] has no corruption.".format(fileNameExt), 'TRANSCODER')
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.info("FAILED: [%s] has %s video streams and %s audio streams. Assume corruption." % (
|
logger.info("FAILED: [{0}] has {1} video streams and {2} audio streams. "
|
||||||
fileNameExt, str(len(videoStreams)), str(len(audioStreams))), 'TRANSCODER')
|
"Assume corruption.".format
|
||||||
|
(fileNameExt, len(videoStreams), len(audioStreams)), 'TRANSCODER')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ def zip_out(file, img, bitbucket):
|
||||||
try:
|
try:
|
||||||
procin = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
procin = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||||
except:
|
except:
|
||||||
logger.error("Extracting [%s] has failed" % (file), 'TRANSCODER')
|
logger.error("Extracting [{0}] has failed".format(file), 'TRANSCODER')
|
||||||
return procin
|
return procin
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
|
||||||
result = proc.returncode
|
result = proc.returncode
|
||||||
video_details = json.loads(out)
|
video_details = json.loads(out)
|
||||||
except:
|
except:
|
||||||
logger.error("Checking [%s] has failed" % (file), 'TRANSCODER')
|
logger.error("Checking [{0}] has failed".format(file), 'TRANSCODER')
|
||||||
return video_details, result
|
return video_details, result
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
||||||
if check and core.CONCAT:
|
if check and core.CONCAT:
|
||||||
name = movieName
|
name = movieName
|
||||||
elif check:
|
elif check:
|
||||||
name = ('%s.cd%s' % (movieName, check.groups()[0]))
|
name = ('{0}.cd{1}'.format(movieName, check.groups()[0]))
|
||||||
elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name):
|
elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name):
|
||||||
name = re.sub("([\ \.\-\_\=\:]+[cC][dD][0-9])", "", name)
|
name = re.sub("([\ \.\-\_\=\:]+[cC][dD][0-9])", "", name)
|
||||||
if ext == core.VEXTENSION and newDir == dir: # we need to change the name to prevent overwriting itself.
|
if ext == core.VEXTENSION and newDir == dir: # we need to change the name to prevent overwriting itself.
|
||||||
|
@ -545,20 +546,20 @@ def extract_subs(file, newfilePath, bitbucket):
|
||||||
lan = "unk"
|
lan = "unk"
|
||||||
|
|
||||||
if num == 1:
|
if num == 1:
|
||||||
outputFile = os.path.join(subdir, "%s.srt" % (name))
|
outputFile = os.path.join(subdir, "{0}.srt".format(name))
|
||||||
if os.path.isfile(outputFile):
|
if os.path.isfile(outputFile):
|
||||||
outputFile = os.path.join(subdir, "%s.%s.srt" % (name, n))
|
outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, n))
|
||||||
else:
|
else:
|
||||||
outputFile = os.path.join(subdir, "%s.%s.srt" % (name, lan))
|
outputFile = os.path.join(subdir, "{0}.{1}.srt".format(name, lan))
|
||||||
if os.path.isfile(outputFile):
|
if os.path.isfile(outputFile):
|
||||||
outputFile = os.path.join(subdir, "%s.%s.%s.srt" % (name, lan, n))
|
outputFile = os.path.join(subdir, "{0}.{1}.{2}.srt".format(name, lan, n))
|
||||||
|
|
||||||
command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an', '-codec:' + str(idx), 'srt',
|
command = [core.FFMPEG, '-loglevel', 'warning', '-i', file, '-vn', '-an', '-codec:' + str(idx), 'srt',
|
||||||
outputFile]
|
outputFile]
|
||||||
if platform.system() != 'Windows':
|
if platform.system() != 'Windows':
|
||||||
command = core.NICENESS + command
|
command = core.NICENESS + command
|
||||||
|
|
||||||
logger.info("Extracting %s subtitle from: %s" % (lan, file))
|
logger.info("Extracting {0} subtitle from: {1}".format(lan, file))
|
||||||
print_cmd(command)
|
print_cmd(command)
|
||||||
result = 1 # set result to failed in case call fails.
|
result = 1 # set result to failed in case call fails.
|
||||||
try:
|
try:
|
||||||
|
@ -573,7 +574,7 @@ def extract_subs(file, newfilePath, bitbucket):
|
||||||
shutil.copymode(file, outputFile)
|
shutil.copymode(file, outputFile)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
logger.info("Extracting %s subtitle from %s has succeeded" % (lan, file))
|
logger.info("Extracting {0} subtitle from {1} has succeeded".format(lan, file))
|
||||||
else:
|
else:
|
||||||
logger.error("Extracting subtitles has failed")
|
logger.error("Extracting subtitles has failed")
|
||||||
|
|
||||||
|
@ -587,11 +588,11 @@ def processList(List, newDir, bitbucket):
|
||||||
for item in List:
|
for item in List:
|
||||||
ext = os.path.splitext(item)[1].lower()
|
ext = os.path.splitext(item)[1].lower()
|
||||||
if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS:
|
if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS:
|
||||||
logger.debug("Attempting to rip disk image: %s" % (item), "TRANSCODER")
|
logger.debug("Attempting to rip disk image: {0}".format(item), "TRANSCODER")
|
||||||
newList.extend(ripISO(item, newDir, bitbucket))
|
newList.extend(ripISO(item, newDir, bitbucket))
|
||||||
remList.append(item)
|
remList.append(item)
|
||||||
elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and '.vob' not in core.IGNOREEXTENSIONS:
|
elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and '.vob' not in core.IGNOREEXTENSIONS:
|
||||||
logger.debug("Found VIDEO_TS image file: %s" % (item), "TRANSCODER")
|
logger.debug("Found VIDEO_TS image file: {0}".format(item), "TRANSCODER")
|
||||||
if not vtsPath:
|
if not vtsPath:
|
||||||
try:
|
try:
|
||||||
vtsPath = re.match("(.+VIDEO_TS)", item).groups()[0]
|
vtsPath = re.match("(.+VIDEO_TS)", item).groups()[0]
|
||||||
|
@ -617,7 +618,7 @@ def processList(List, newDir, bitbucket):
|
||||||
List.extend(newList)
|
List.extend(newList)
|
||||||
for item in remList:
|
for item in remList:
|
||||||
List.remove(item)
|
List.remove(item)
|
||||||
logger.debug("Successfully extracted .vob file %s from disk image" % (newList[0]), "TRANSCODER")
|
logger.debug("Successfully extracted .vob file {0} from disk image".format(newList[0]), "TRANSCODER")
|
||||||
elif newList and not success:
|
elif newList and not success:
|
||||||
newList = []
|
newList = []
|
||||||
remList = []
|
remList = []
|
||||||
|
@ -630,12 +631,12 @@ def ripISO(item, newDir, bitbucket):
|
||||||
failure_dir = 'failure'
|
failure_dir = 'failure'
|
||||||
# Mount the ISO in your OS and call combineVTS.
|
# Mount the ISO in your OS and call combineVTS.
|
||||||
if not core.SEVENZIP:
|
if not core.SEVENZIP:
|
||||||
logger.error("No 7zip installed. Can't extract image file %s" % (item), "TRANSCODER")
|
logger.error("No 7zip installed. Can't extract image file {0}".format(item), "TRANSCODER")
|
||||||
newFiles = [failure_dir]
|
newFiles = [failure_dir]
|
||||||
return newFiles
|
return newFiles
|
||||||
cmd = [core.SEVENZIP, 'l', item]
|
cmd = [core.SEVENZIP, 'l', item]
|
||||||
try:
|
try:
|
||||||
logger.debug("Attempting to extract .vob from image file %s" % (item), "TRANSCODER")
|
logger.debug("Attempting to extract .vob from image file {0}".format(item), "TRANSCODER")
|
||||||
print_cmd(cmd)
|
print_cmd(cmd)
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
|
@ -646,7 +647,7 @@ def ripISO(item, newDir, bitbucket):
|
||||||
concat = []
|
concat = []
|
||||||
m = 1
|
m = 1
|
||||||
while True:
|
while True:
|
||||||
vtsName = 'VIDEO_TS%sVTS_%02d_%d.VOB' % (os.sep, n + 1, m)
|
vtsName = 'VIDEO_TS{0}VTS_{1:02d}_{2:d}.VOB'.format(os.sep, n + 1, m)
|
||||||
if vtsName in fileList:
|
if vtsName in fileList:
|
||||||
concat.append(vtsName)
|
concat.append(vtsName)
|
||||||
m += 1
|
m += 1
|
||||||
|
@ -657,16 +658,16 @@ def ripISO(item, newDir, bitbucket):
|
||||||
if core.CONCAT:
|
if core.CONCAT:
|
||||||
combined.extend(concat)
|
combined.extend(concat)
|
||||||
continue
|
continue
|
||||||
name = '%s.cd%s' % (os.path.splitext(os.path.split(item)[1])[0], str(n + 1))
|
name = '{0}.cd{1}'.format(os.path.splitext(os.path.split(item)[1])[0], str(n + 1))
|
||||||
newFiles.append({item: {'name': name, 'files': concat}})
|
newFiles.append({item: {'name': name, 'files': concat}})
|
||||||
if core.CONCAT:
|
if core.CONCAT:
|
||||||
name = os.path.splitext(os.path.split(item)[1])[0]
|
name = os.path.splitext(os.path.split(item)[1])[0]
|
||||||
newFiles.append({item: {'name': name, 'files': combined}})
|
newFiles.append({item: {'name': name, 'files': combined}})
|
||||||
if not newFiles:
|
if not newFiles:
|
||||||
logger.error("No VIDEO_TS folder found in image file %s" % (item), "TRANSCODER")
|
logger.error("No VIDEO_TS folder found in image file {0}".format(item), "TRANSCODER")
|
||||||
newFiles = [failure_dir]
|
newFiles = [failure_dir]
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to extract from image file %s" % (item), "TRANSCODER")
|
logger.error("Failed to extract from image file {0}".format(item), "TRANSCODER")
|
||||||
newFiles = [failure_dir]
|
newFiles = [failure_dir]
|
||||||
return newFiles
|
return newFiles
|
||||||
|
|
||||||
|
@ -678,7 +679,7 @@ def combineVTS(vtsPath):
|
||||||
concat = ''
|
concat = ''
|
||||||
m = 1
|
m = 1
|
||||||
while True:
|
while True:
|
||||||
vtsName = 'VTS_%02d_%d.VOB' % (n + 1, m)
|
vtsName = 'VTS_{0:02d}_{1:d}.VOB'.format(n + 1, m)
|
||||||
if os.path.isfile(os.path.join(vtsPath, vtsName)):
|
if os.path.isfile(os.path.join(vtsPath, vtsName)):
|
||||||
concat = concat + os.path.join(vtsPath, vtsName) + '|'
|
concat = concat + os.path.join(vtsPath, vtsName) + '|'
|
||||||
m += 1
|
m += 1
|
||||||
|
@ -689,9 +690,9 @@ def combineVTS(vtsPath):
|
||||||
if core.CONCAT:
|
if core.CONCAT:
|
||||||
combined = combined + concat + '|'
|
combined = combined + concat + '|'
|
||||||
continue
|
continue
|
||||||
newFiles.append('concat:%s' % concat[:-1])
|
newFiles.append('concat:{0}'.format(concat[:-1]))
|
||||||
if core.CONCAT:
|
if core.CONCAT:
|
||||||
newFiles.append('concat:%s' % combined[:-1])
|
newFiles.append('concat:{0}'.format(combined[:-1]))
|
||||||
return newFiles
|
return newFiles
|
||||||
|
|
||||||
|
|
||||||
|
@ -707,7 +708,7 @@ def combineCD(combine):
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if concat:
|
if concat:
|
||||||
newFiles.append('concat:%s' % concat[:-1])
|
newFiles.append('concat:{0}'.format(concat[:-1]))
|
||||||
return newFiles
|
return newFiles
|
||||||
|
|
||||||
|
|
||||||
|
@ -715,7 +716,7 @@ def print_cmd(command):
|
||||||
cmd = ""
|
cmd = ""
|
||||||
for item in command:
|
for item in command:
|
||||||
cmd = cmd + " " + str(item)
|
cmd = cmd + " " + str(item)
|
||||||
logger.debug("calling command:%s" % (cmd))
|
logger.debug("calling command:{0}".format(cmd))
|
||||||
|
|
||||||
|
|
||||||
def Transcode_directory(dirName):
|
def Transcode_directory(dirName):
|
||||||
|
@ -756,11 +757,11 @@ def Transcode_directory(dirName):
|
||||||
os.remove(newfilePath)
|
os.remove(newfilePath)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
logger.debug("Error when removing transcoding target: {0}".format(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
logger.debug("Error when removing transcoding target: {0}".format(e))
|
||||||
|
|
||||||
logger.info("Transcoding video: %s" % (newfilePath))
|
logger.info("Transcoding video: {0}".format(newfilePath))
|
||||||
print_cmd(command)
|
print_cmd(command)
|
||||||
result = 1 # set result to failed in case call fails.
|
result = 1 # set result to failed in case call fails.
|
||||||
try:
|
try:
|
||||||
|
@ -777,7 +778,7 @@ def Transcode_directory(dirName):
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
result = proc.returncode
|
result = proc.returncode
|
||||||
except:
|
except:
|
||||||
logger.error("Transcoding of video %s has failed" % (newfilePath))
|
logger.error("Transcoding of video {0} has failed".format(newfilePath))
|
||||||
|
|
||||||
if core.SUBSDIR and result == 0 and isinstance(file, str):
|
if core.SUBSDIR and result == 0 and isinstance(file, str):
|
||||||
for sub in get_subs(file):
|
for sub in get_subs(file):
|
||||||
|
@ -793,14 +794,14 @@ def Transcode_directory(dirName):
|
||||||
shutil.copymode(file, newfilePath)
|
shutil.copymode(file, newfilePath)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
logger.info("Transcoding of video to %s succeeded" % (newfilePath))
|
logger.info("Transcoding of video to {0} succeeded".format(newfilePath))
|
||||||
if os.path.isfile(newfilePath) and (file in newList or not core.DUPLICATE):
|
if os.path.isfile(newfilePath) and (file in newList or not core.DUPLICATE):
|
||||||
try:
|
try:
|
||||||
os.unlink(file)
|
os.unlink(file)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.error("Transcoding of video to %s failed with result %s" % (newfilePath, str(result)))
|
logger.error("Transcoding of video to {0} failed with result {1}".format(newfilePath, result))
|
||||||
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
||||||
final_result = final_result + result
|
final_result = final_result + result
|
||||||
if final_result == 0 and not core.DUPLICATE:
|
if final_result == 0 and not core.DUPLICATE:
|
||||||
|
|
|
@ -100,7 +100,7 @@ def parse_torrent_ids(args):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if not addition:
|
if not addition:
|
||||||
raise ValueError('Invalid torrent id, \"%s\"' % item)
|
raise ValueError('Invalid torrent id, {item!r}'.format(item=item))
|
||||||
ids.extend(addition)
|
ids.extend(addition)
|
||||||
elif isinstance(args, (list, tuple)):
|
elif isinstance(args, (list, tuple)):
|
||||||
for item in args:
|
for item in args:
|
||||||
|
@ -251,20 +251,20 @@ class Client(object):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
http_data = self._http_query(query, timeout)
|
http_data = self._http_query(query, timeout)
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
LOGGER.info('http request took %.3f s' % (elapsed))
|
LOGGER.info('http request took {time:.3f} s'.format(time=elapsed))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(http_data)
|
data = json.loads(http_data)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
LOGGER.error('Error: ' + str(error))
|
LOGGER.error('Error: ' + str(error))
|
||||||
LOGGER.error('Request: \"%s\"' % (query))
|
LOGGER.error('Request: {request!r}'.format(request=query))
|
||||||
LOGGER.error('HTTP data: \"%s\"' % (http_data))
|
LOGGER.error('HTTP data: {data!r}'.format(data=http_data))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
LOGGER.debug(json.dumps(data, indent=2))
|
LOGGER.debug(json.dumps(data, indent=2))
|
||||||
if 'result' in data:
|
if 'result' in data:
|
||||||
if data['result'] != 'success':
|
if data['result'] != 'success':
|
||||||
raise TransmissionError('Query failed with result \"%s\".' % (data['result']))
|
raise TransmissionError('Query failed with result {result!r}.'.format(result=data['result']))
|
||||||
else:
|
else:
|
||||||
raise TransmissionError('Query failed without result.')
|
raise TransmissionError('Query failed without result.')
|
||||||
|
|
||||||
|
@ -348,8 +348,9 @@ class Client(object):
|
||||||
Add a warning to the log if the Transmission RPC version is lower then the provided version.
|
Add a warning to the log if the Transmission RPC version is lower then the provided version.
|
||||||
"""
|
"""
|
||||||
if self.rpc_version < version:
|
if self.rpc_version < version:
|
||||||
LOGGER.warning('Using feature not supported by server. RPC version for server %d, feature introduced in %d.'
|
LOGGER.warning('Using feature not supported by server. '
|
||||||
% (self.rpc_version, version))
|
'RPC version for server {x}, feature introduced in {y}.'.format
|
||||||
|
(x=self.rpc_version, y=version))
|
||||||
|
|
||||||
def add_torrent(self, torrent, timeout=None, **kwargs):
|
def add_torrent(self, torrent, timeout=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TransmissionError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.original:
|
if self.original:
|
||||||
original_name = type(self.original).__name__
|
original_name = type(self.original).__name__
|
||||||
return '%s Original exception: %s, "%s"' % (self.message, original_name, str(self.original))
|
return '{0} Original exception: {1}, "{2}"'.format(self.message, original_name, str(self.original))
|
||||||
else:
|
else:
|
||||||
return self.message
|
return self.message
|
||||||
|
|
||||||
|
@ -49,10 +49,10 @@ class HTTPHandlerError(Exception):
|
||||||
self.data = httpdata
|
self.data = httpdata
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<HTTPHandlerError %d, %s>' % (self.code, self.message)
|
return '<HTTPHandlerError {0:d}, {1}>'.format(self.code, self.message)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'HTTPHandlerError %d: %s' % (self.code, self.message)
|
return 'HTTPHandlerError {0:d}: {1}'.format(self.code, self.message)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return 'HTTPHandlerError %d: %s' % (self.code, self.message)
|
return 'HTTPHandlerError {0:d}: {1}'.format(self.code, self.message)
|
||||||
|
|
|
@ -75,7 +75,7 @@ class DefaultHTTPHandler(HTTPHandler):
|
||||||
if hasattr(error.reason, 'args') and isinstance(error.reason.args, tuple) and len(error.reason.args) == 2:
|
if hasattr(error.reason, 'args') and isinstance(error.reason.args, tuple) and len(error.reason.args) == 2:
|
||||||
raise HTTPHandlerError(httpcode=error.reason.args[0], httpmsg=error.reason.args[1])
|
raise HTTPHandlerError(httpcode=error.reason.args[0], httpmsg=error.reason.args[1])
|
||||||
else:
|
else:
|
||||||
raise HTTPHandlerError(httpmsg='urllib2.URLError: %s' % (error.reason))
|
raise HTTPHandlerError(httpmsg='urllib2.URLError: {error.reason}'.format(error=error))
|
||||||
except BadStatusLine as error:
|
except BadStatusLine as error:
|
||||||
raise HTTPHandlerError(httpmsg='httplib.BadStatusLine: %s' % (error.line))
|
raise HTTPHandlerError(httpmsg='httplib.BadStatusLine: {error.line}'.format(error=error))
|
||||||
return response.read().decode('utf-8')
|
return response.read().decode('utf-8')
|
||||||
|
|
|
@ -27,12 +27,12 @@ class Session(object):
|
||||||
try:
|
try:
|
||||||
return self._fields[name].value
|
return self._fields[name].value
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError('No attribute %s' % name)
|
raise AttributeError('No attribute {0}'.format(name))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
text = ''
|
text = ''
|
||||||
for key in sorted(self._fields.keys()):
|
for key in sorted(self._fields.keys()):
|
||||||
text += "% 32s: %s\n" % (key[-32:], self._fields[key].value)
|
text += "{0:32}: {1}\n".format(key[-32:], self._fields[key].value)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def _update_fields(self, other):
|
def _update_fields(self, other):
|
||||||
|
|
|
@ -73,14 +73,14 @@ class Torrent(object):
|
||||||
tid = self._fields['id'].value
|
tid = self._fields['id'].value
|
||||||
name = self._get_name_string()
|
name = self._get_name_string()
|
||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
return '<Torrent %d \"%s\">' % (tid, name)
|
return '<Torrent {0:d} \"{1}\">'.format(tid, name)
|
||||||
else:
|
else:
|
||||||
return '<Torrent %d>' % (tid)
|
return '<Torrent {0:d}>'.format(tid)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
name = self._get_name_string()
|
name = self._get_name_string()
|
||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
return 'Torrent \"%s\"' % (name)
|
return 'Torrent \"{0}\"'.format(name)
|
||||||
else:
|
else:
|
||||||
return 'Torrent'
|
return 'Torrent'
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ class Torrent(object):
|
||||||
try:
|
try:
|
||||||
return self._fields[name].value
|
return self._fields[name].value
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError('No attribute %s' % name)
|
raise AttributeError('No attribute {0}'.format(name))
|
||||||
|
|
||||||
def _rpc_version(self):
|
def _rpc_version(self):
|
||||||
"""Get the Transmission RPC API version."""
|
"""Get the Transmission RPC API version."""
|
||||||
|
|
|
@ -40,7 +40,7 @@ def format_timedelta(delta):
|
||||||
"""
|
"""
|
||||||
minutes, seconds = divmod(delta.seconds, 60)
|
minutes, seconds = divmod(delta.seconds, 60)
|
||||||
hours, minutes = divmod(minutes, 60)
|
hours, minutes = divmod(minutes, 60)
|
||||||
return '%d %02d:%02d:%02d' % (delta.days, hours, minutes, seconds)
|
return '{0:d} {1:02d}:{2:02d}:{3:02d}'.format(delta.days, hours, minutes, seconds)
|
||||||
|
|
||||||
|
|
||||||
def format_timestamp(timestamp, utc=False):
|
def format_timestamp(timestamp, utc=False):
|
||||||
|
@ -80,17 +80,17 @@ def inet_address(address, default_port, default_address='localhost'):
|
||||||
try:
|
try:
|
||||||
port = int(addr[1])
|
port = int(addr[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise INetAddressError('Invalid address "%s".' % address)
|
raise INetAddressError('Invalid address "{0}".'.format(address))
|
||||||
if len(addr[0]) == 0:
|
if len(addr[0]) == 0:
|
||||||
addr = default_address
|
addr = default_address
|
||||||
else:
|
else:
|
||||||
addr = addr[0]
|
addr = addr[0]
|
||||||
else:
|
else:
|
||||||
raise INetAddressError('Invalid address "%s".' % address)
|
raise INetAddressError('Invalid address "{0}".'.format(address))
|
||||||
try:
|
try:
|
||||||
socket.getaddrinfo(addr, port, socket.AF_INET, socket.SOCK_STREAM)
|
socket.getaddrinfo(addr, port, socket.AF_INET, socket.SOCK_STREAM)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
raise INetAddressError('Cannot look up address "%s".' % address)
|
raise INetAddressError('Cannot look up address "{0}".'.format(address))
|
||||||
return addr, port
|
return addr, port
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ def argument_value_convert(method, argument, value, rpc_version):
|
||||||
elif method in ('session-get', 'session-set'):
|
elif method in ('session-get', 'session-set'):
|
||||||
args = constants.SESSION_ARGS[method[-3:]]
|
args = constants.SESSION_ARGS[method[-3:]]
|
||||||
else:
|
else:
|
||||||
return ValueError('Method "%s" not supported' % (method))
|
return ValueError('Method "{0}" not supported'.format(method))
|
||||||
if argument in args:
|
if argument in args:
|
||||||
info = args[argument]
|
info = args[argument]
|
||||||
invalid_version = True
|
invalid_version = True
|
||||||
|
@ -155,14 +155,12 @@ def argument_value_convert(method, argument, value, rpc_version):
|
||||||
if invalid_version:
|
if invalid_version:
|
||||||
if replacement:
|
if replacement:
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
'Replacing requested argument "%s" with "%s".'
|
'Replacing requested argument "{0}" with "{1}".'.format(argument, replacement))
|
||||||
% (argument, replacement))
|
|
||||||
argument = replacement
|
argument = replacement
|
||||||
info = args[argument]
|
info = args[argument]
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Method "%s" Argument "%s" does not exist in version %d.'
|
'Method "{0}" Argument "{1}" does not exist in version {2:d}.'.format(method, argument, rpc_version))
|
||||||
% (method, argument, rpc_version))
|
|
||||||
return argument, TR_TYPE_MAP[info[0]](value)
|
return argument, TR_TYPE_MAP[info[0]](value)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Argument "%s" does not exists for method "%s".',
|
raise ValueError('Argument "%s" does not exists for method "%s".',
|
||||||
|
@ -178,7 +176,7 @@ def get_arguments(method, rpc_version):
|
||||||
elif method in ('session-get', 'session-set'):
|
elif method in ('session-get', 'session-set'):
|
||||||
args = constants.SESSION_ARGS[method[-3:]]
|
args = constants.SESSION_ARGS[method[-3:]]
|
||||||
else:
|
else:
|
||||||
return ValueError('Method "%s" not supported' % (method))
|
return ValueError('Method "{0}" not supported'.format(method))
|
||||||
accessible = []
|
accessible = []
|
||||||
for argument, info in iteritems(args):
|
for argument, info in iteritems(args):
|
||||||
valid_version = True
|
valid_version = True
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MultiPartForm(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_content_type(self):
|
def get_content_type(self):
|
||||||
return 'multipart/form-data; boundary=%s' % self.boundary
|
return 'multipart/form-data; boundary={0}'.format(self.boundary)
|
||||||
|
|
||||||
def add_field(self, name, value):
|
def add_field(self, name, value):
|
||||||
"""Add a simple field to the form data."""
|
"""Add a simple field to the form data."""
|
||||||
|
@ -43,7 +43,7 @@ class MultiPartForm(object):
|
||||||
# Add the form fields
|
# Add the form fields
|
||||||
parts.extend(
|
parts.extend(
|
||||||
[part_boundary,
|
[part_boundary,
|
||||||
'Content-Disposition: form-data; name="%s"' % name,
|
'Content-Disposition: form-data; name="{0}"'.format(name),
|
||||||
'',
|
'',
|
||||||
value,
|
value,
|
||||||
]
|
]
|
||||||
|
@ -53,8 +53,8 @@ class MultiPartForm(object):
|
||||||
# Add the files to upload
|
# Add the files to upload
|
||||||
parts.extend(
|
parts.extend(
|
||||||
[part_boundary,
|
[part_boundary,
|
||||||
'Content-Disposition: file; name="%s"; filename="%s"' % (field_name, filename),
|
'Content-Disposition: file; name="{0}"; filename="{1}"'.format(field_name, filename),
|
||||||
'Content-Type: %s' % content_type,
|
'Content-Type: {0}'.format(content_type),
|
||||||
'',
|
'',
|
||||||
body,
|
body,
|
||||||
]
|
]
|
||||||
|
|
|
@ -514,7 +514,7 @@ from core import logger, nzbToMediaDB
|
||||||
def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None):
|
def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None):
|
||||||
if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR:
|
if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR:
|
||||||
logger.error(
|
logger.error(
|
||||||
'The input directory:[%s] is the Default Download Directory. Please configure category directories to prevent processing of other media.' % (
|
'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.'.format(
|
||||||
inputDirectory))
|
inputDirectory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
|
||||||
download_id = get_nzoid(inputName)
|
download_id = get_nzoid(inputName)
|
||||||
|
|
||||||
if clientAgent != 'manual' and not core.DOWNLOADINFO:
|
if clientAgent != 'manual' and not core.DOWNLOADINFO:
|
||||||
logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory))
|
logger.debug('Adding NZB download info for directory {0} to database'.format(inputDirectory))
|
||||||
|
|
||||||
myDB = nzbToMediaDB.DBConnection()
|
myDB = nzbToMediaDB.DBConnection()
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
|
||||||
section = core.CFG.findsection("ALL").isenabled()
|
section = core.CFG.findsection("ALL").isenabled()
|
||||||
if section is None:
|
if section is None:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % (
|
'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format(
|
||||||
inputCategory))
|
inputCategory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
else:
|
else:
|
||||||
|
@ -563,15 +563,15 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
|
||||||
|
|
||||||
if len(section) > 1:
|
if len(section) > 1:
|
||||||
logger.error(
|
logger.error(
|
||||||
'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % (
|
'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format(
|
||||||
inputCategory, section.keys()))
|
inputCategory, section.keys()))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
if section:
|
if section:
|
||||||
sectionName = section.keys()[0]
|
sectionName = section.keys()[0]
|
||||||
logger.info('Auto-detected SECTION:%s' % (sectionName))
|
logger.info('Auto-detected SECTION:{0}'.format(sectionName))
|
||||||
else:
|
else:
|
||||||
logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % (
|
logger.error("Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!".format(
|
||||||
inputCategory))
|
inputCategory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
|
|
||||||
|
@ -582,20 +582,20 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if int(section[usercat]['remote_path']) and not core.REMOTEPATHS:
|
if int(section[usercat]['remote_path']) and not core.REMOTEPATHS:
|
||||||
logger.error('Remote Path is enabled for %s:%s but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' % (
|
logger.error('Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!'.format(
|
||||||
sectionName, inputCategory))
|
sectionName, inputCategory))
|
||||||
return [-1, ""]
|
return [-1, ""]
|
||||||
except:
|
except:
|
||||||
logger.error('Remote Path %s is not valid for %s:%s Please set this to either 0 to disable or 1 to enable!' % (
|
logger.error('Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!'.format(
|
||||||
section[usercat]['remote_path'], sectionName, inputCategory))
|
section[usercat]['remote_path'], sectionName, inputCategory))
|
||||||
|
|
||||||
inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory)
|
inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory)
|
||||||
|
|
||||||
if extract == 1:
|
if extract == 1:
|
||||||
logger.debug('Checking for archives to extract in directory: %s' % (inputDirectory))
|
logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory))
|
||||||
extractFiles(inputDirectory)
|
extractFiles(inputDirectory)
|
||||||
|
|
||||||
logger.info("Calling %s:%s to post-process:%s" % (sectionName, inputCategory, inputName))
|
logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, inputCategory, inputName))
|
||||||
|
|
||||||
if sectionName == "CouchPotato":
|
if sectionName == "CouchPotato":
|
||||||
result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id,
|
result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id,
|
||||||
|
@ -636,11 +636,11 @@ def main(args, section=None):
|
||||||
clientAgent = core.NZB_CLIENTAGENT
|
clientAgent = core.NZB_CLIENTAGENT
|
||||||
|
|
||||||
logger.info("#########################################################")
|
logger.info("#########################################################")
|
||||||
logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__))
|
logger.info("## ..::[{0}]::.. ##".format(os.path.basename(__file__)))
|
||||||
logger.info("#########################################################")
|
logger.info("#########################################################")
|
||||||
|
|
||||||
# debug command line options
|
# debug command line options
|
||||||
logger.debug("Options passed into nzbToMedia: %s" % args)
|
logger.debug("Options passed into nzbToMedia: {0}".format(args))
|
||||||
|
|
||||||
# Post-Processing Result
|
# Post-Processing Result
|
||||||
result = [0, ""]
|
result = [0, ""]
|
||||||
|
@ -650,15 +650,15 @@ def main(args, section=None):
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
||||||
# Check if the script is called from nzbget 11.0 or later
|
# Check if the script is called from nzbget 11.0 or later
|
||||||
if os.environ['NZBOP_VERSION'][0:5] < '11.0':
|
if os.environ['NZBOP_VERSION'][0:5] < '11.0':
|
||||||
logger.error("NZBGet Version %s is not supported. Please update NZBGet." %(str(os.environ['NZBOP_VERSION'])))
|
logger.error("NZBGet Version {0} is not supported. Please update NZBGet.".format(os.environ['NZBOP_VERSION']))
|
||||||
sys.exit(core.NZBGET_POSTPROCESS_ERROR)
|
sys.exit(core.NZBGET_POSTPROCESS_ERROR)
|
||||||
|
|
||||||
logger.info("Script triggered from NZBGet Version %s." %(str(os.environ['NZBOP_VERSION'])))
|
logger.info("Script triggered from NZBGet Version {0}.".format(os.environ['NZBOP_VERSION']))
|
||||||
|
|
||||||
# Check if the script is called from nzbget 13.0 or later
|
# Check if the script is called from nzbget 13.0 or later
|
||||||
if os.environ.has_key('NZBPP_TOTALSTATUS'):
|
if os.environ.has_key('NZBPP_TOTALSTATUS'):
|
||||||
if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS':
|
if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS':
|
||||||
logger.info("Download failed with status %s." %(os.environ['NZBPP_STATUS']))
|
logger.info("Download failed with status {0}.".format(os.environ['NZBPP_STATUS']))
|
||||||
status = 1
|
status = 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -745,16 +745,16 @@ def main(args, section=None):
|
||||||
if not core.CFG[section][subsection].isenabled():
|
if not core.CFG[section][subsection].isenabled():
|
||||||
continue
|
continue
|
||||||
for dirName in getDirs(section, subsection, link = 'move'):
|
for dirName in getDirs(section, subsection, link = 'move'):
|
||||||
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName))
|
logger.info("Starting manual run for {0}:{1} - Folder:{2}".format(section, subsection, dirName))
|
||||||
|
|
||||||
logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName)))
|
logger.info("Checking database for download info for {0} ...".format(os.path.basename(dirName)))
|
||||||
core.DOWNLOADINFO = get_downloadInfo(os.path.basename(dirName), 0)
|
core.DOWNLOADINFO = get_downloadInfo(os.path.basename(dirName), 0)
|
||||||
if core.DOWNLOADINFO:
|
if core.DOWNLOADINFO:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Found download info for %s, setting variables now ..." % (os.path.basename(dirName)))
|
"Found download info for {0}, setting variables now ...".format(os.path.basename(dirName)))
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Unable to locate download info for %s, continuing to try and process this release ...' % (
|
'Unable to locate download info for {0}, continuing to try and process this release ...'.format(
|
||||||
os.path.basename(dirName))
|
os.path.basename(dirName))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -781,19 +781,19 @@ def main(args, section=None):
|
||||||
results = process(dirName, inputName, 0, clientAgent=clientAgent,
|
results = process(dirName, inputName, 0, clientAgent=clientAgent,
|
||||||
download_id=download_id, inputCategory=subsection)
|
download_id=download_id, inputCategory=subsection)
|
||||||
if results[0] != 0:
|
if results[0] != 0:
|
||||||
logger.error("A problem was reported when trying to perform a manual run for %s:%s." % (
|
logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format(
|
||||||
section, subsection))
|
section, subsection))
|
||||||
result = results
|
result = results
|
||||||
|
|
||||||
if result[0] == 0:
|
if result[0] == 0:
|
||||||
logger.info("The %s script completed successfully." % args[0])
|
logger.info("The {0} script completed successfully.".format(args[0]))
|
||||||
if result[1]:
|
if result[1]:
|
||||||
print result[1] + "!" # For SABnzbd Status display.
|
print result[1] + "!" # For SABnzbd Status display.
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||||
del core.MYAPP
|
del core.MYAPP
|
||||||
return (core.NZBGET_POSTPROCESS_SUCCESS)
|
return (core.NZBGET_POSTPROCESS_SUCCESS)
|
||||||
else:
|
else:
|
||||||
logger.error("A problem was reported in the %s script." % args[0])
|
logger.error("A problem was reported in the {0} script.".format(args[0]))
|
||||||
if result[1]:
|
if result[1]:
|
||||||
print result[1] + "!" # For SABnzbd Status display.
|
print result[1] + "!" # For SABnzbd Status display.
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue