Massive changes to the way we handle our config, its now loaded and stored in memory so that we don't keep loading it and possibly get corrupt values.

New logger class added,logger options removed from settings.
This commit is contained in:
echel0n 2014-04-11 20:09:00 -07:00
parent d8a3bdb7dc
commit 18926d1db8
30 changed files with 1603 additions and 1058 deletions

View file

@ -14,15 +14,15 @@ class Transcoder:
ffmpeg = os.path.join(os.path.dirname(sys.argv[0]), 'ffmpeg\\bin\\ffmpeg.exe') # note, will need to package in this dir.
useNiceness = False
if not os.path.isfile(ffmpeg): # problem
Logger.error("ffmpeg not found. ffmpeg needs to be located at: %s", ffmpeg)
Logger.info("Cannot transcode files in folder %s", dirName)
logger.error("ffmpeg not found. ffmpeg needs to be located at: %s", ffmpeg)
logger.info("Cannot transcode files in folder %s", dirName)
return 1 # failure
else:
if call(['which', 'ffmpeg']) != 0:
res = call([os.path.join(os.path.dirname(sys.argv[0]),'getffmpeg.sh')])
if res or call(['which', 'ffmpeg']) != 0: # did not install or ffmpeg still not found.
Logger.error("Failed to install ffmpeg. Please install manually")
Logger.info("Cannot transcode files in folder %s", dirName)
logger.error("Failed to install ffmpeg. Please install manually")
logger.info("Cannot transcode files in folder %s", dirName)
return 1 # failure
else:
ffmpeg = 'ffmpeg'
@ -30,33 +30,33 @@ class Transcoder:
ffmpeg = 'ffmpeg'
useNiceness = True
Logger.info("Loading config from %s", config.CONFIG_FILE)
logger.info("Loading config from %s", nzbtomedia.CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
if not nzbtomedia.CFG:
logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
mediaContainer = (config()["Transcoder"]["duplicate"])
duplicate = int(config()["Transcoder"]["duplicate"])
ignoreExtensions = (config()["Transcoder"]["ignoreExtensions"])
outputVideoExtension = config()["Transcoder"]["outputVideoExtension"].strip()
outputVideoCodec = config()["Transcoder"]["outputVideoCodec"].strip()
outputVideoPreset = config()["Transcoder"]["outputVideoPreset"].strip()
outputVideoFramerate = config()["Transcoder"]["outputVideoFramerate"].strip()
outputVideoBitrate = config()["Transcoder"]["outputVideoBitrate"].strip()
outputAudioCodec = config()["Transcoder"]["outputAudioCodec"].strip()
outputAudioBitrate = config()["Transcoder"]["outputAudioBitrate"].strip()
outputSubtitleCodec = config()["Transcoder"]["outputSubtitleCodec"].strip()
outputFastStart = int(config()["Transcoder"]["outputFastStart"])
outputQualityPercent = int(config()["Transcoder"]["outputQualityPercent"])
mediaContainer = (nzbtomedia.CFG["Transcoder"]["duplicate"])
duplicate = int(nzbtomedia.CFG["Transcoder"]["duplicate"])
ignoreExtensions = (nzbtomedia.CFG["Transcoder"]["ignoreExtensions"])
outputVideoExtension = nzbtomedia.CFG["Transcoder"]["outputVideoExtension"].strip()
outputVideoCodec = nzbtomedia.CFG["Transcoder"]["outputVideoCodec"].strip()
outputVideoPreset = nzbtomedia.CFG["Transcoder"]["outputVideoPreset"].strip()
outputVideoFramerate = nzbtomedia.CFG["Transcoder"]["outputVideoFramerate"].strip()
outputVideoBitrate = nzbtomedia.CFG["Transcoder"]["outputVideoBitrate"].strip()
outputAudioCodec = nzbtomedia.CFG["Transcoder"]["outputAudioCodec"].strip()
outputAudioBitrate = nzbtomedia.CFG["Transcoder"]["outputAudioBitrate"].strip()
outputSubtitleCodec = nzbtomedia.CFG["Transcoder"]["outputSubtitleCodec"].strip()
outputFastStart = int(nzbtomedia.CFG["Transcoder"]["outputFastStart"])
outputQualityPercent = int(nzbtomedia.CFG["Transcoder"]["outputQualityPercent"])
niceness = None
if useNiceness:niceness = int(config()["Transcoder"]["niceness"])
if useNiceness:niceness = int(nzbtomedia.CFG["Transcoder"]["niceness"])
map(lambda ext: ext.strip(), mediaContainer)
map(lambda ext: ext.strip(), ignoreExtensions)
Logger.info("Checking for files to be transcoded")
logger.info("Checking for files to be transcoded")
final_result = 0 # initialize as successful
for dirpath, dirnames, filenames in os.walk(dirName):
for file in filenames:
@ -64,7 +64,7 @@ class Transcoder:
name, ext = os.path.splitext(filePath)
if ext in mediaContainer: # If the file is a video file
if ext in ignoreExtensions:
Logger.info("No need to transcode video type %s", ext)
logger.info("No need to transcode video type %s", ext)
continue
if ext == outputVideoExtension: # we need to change the name to prevent overwriting itself.
outputVideoExtension = '-transcoded' + outputVideoExtension # adds '-transcoded.ext'
@ -119,26 +119,26 @@ class Transcoder:
os.remove(newfilePath)
except OSError, e:
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: %s", e)
except Exception, e:
Logger.debug("Error when removing transcoding target: %s", e)
logger.debug("Error when removing transcoding target: %s", e)
Logger.info("Transcoding video: %s", file)
logger.info("Transcoding video: %s", file)
cmd = ""
for item in command:
cmd = cmd + " " + item
Logger.debug("calling command:%s", cmd)
logger.debug("calling command:%s", cmd)
result = 1 # set result to failed in case call fails.
try:
result = call(command)
except:
Logger.exception("Transcoding of video %s has failed", filePath)
logger.error("Transcoding of video %s has failed", filePath)
if result == 0:
Logger.info("Transcoding of video %s to %s succeeded", filePath, newfilePath)
logger.info("Transcoding of video %s to %s succeeded", filePath, newfilePath)
if duplicate == 0: # we get rid of the original file
os.unlink(filePath)
else:
Logger.error("Transcoding of video %s to %s failed", filePath, newfilePath)
logger.error("Transcoding of video %s to %s failed", filePath, newfilePath)
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
final_result = final_result + result
return final_result