mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
make logger safe and encode before database. Fixes #424
This commit is contained in:
parent
ee8dec7109
commit
c6c729aef8
4 changed files with 20 additions and 13 deletions
|
@ -9,7 +9,7 @@ import nzbtomedia
|
|||
|
||||
from subprocess import Popen
|
||||
from nzbtomedia import logger, nzbToMediaDB
|
||||
from nzbtomedia.nzbToMediaUtil import convert_to_ascii
|
||||
from nzbtomedia.nzbToMediaUtil import convert_to_ascii, CharReplace
|
||||
|
||||
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
|
||||
status = 1 # 1 = failed | 0 = success
|
||||
|
@ -21,8 +21,11 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
|
||||
myDB = nzbToMediaDB.DBConnection()
|
||||
|
||||
controlValueDict = {"input_directory": unicode(inputDirectory)}
|
||||
newValueDict = {"input_name": unicode(inputName),
|
||||
encoded, inputDirectory1 = CharReplace(inputDirectory)
|
||||
encoded, inputName1 = CharReplace(inputName)
|
||||
|
||||
controlValueDict = {"input_directory": unicode(inputDirectory1)}
|
||||
newValueDict = {"input_name": unicode(inputName1),
|
||||
"input_hash": unicode(inputHash),
|
||||
"input_id": unicode(inputID),
|
||||
"client_agent": unicode(clientAgent),
|
||||
|
|
|
@ -346,7 +346,7 @@ from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
|||
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
||||
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||
from nzbtomedia.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo
|
||||
from nzbtomedia.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo, CharReplace
|
||||
from nzbtomedia import logger, nzbToMediaDB
|
||||
|
||||
# post-processing
|
||||
|
@ -362,8 +362,11 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
|
|||
|
||||
myDB = nzbToMediaDB.DBConnection()
|
||||
|
||||
controlValueDict = {"input_directory": unicode(inputDirectory)}
|
||||
newValueDict = {"input_name": unicode(inputName),
|
||||
encoded, inputDirectory1 = CharReplace(inputDirectory)
|
||||
encoded, inputName1 = CharReplace(inputName)
|
||||
|
||||
controlValueDict = {"input_directory": unicode(inputDirectory1)}
|
||||
newValueDict = {"input_name": unicode(inputName1),
|
||||
"input_hash": unicode(download_id),
|
||||
"input_id": unicode(download_id),
|
||||
"client_agent": unicode(clientAgent),
|
||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
|||
import threading
|
||||
import logging
|
||||
import nzbtomedia
|
||||
from nzbtomedia.nzbToMediaUtil import CharReplace
|
||||
|
||||
# number of log files to keep
|
||||
NUM_LOGS = 3
|
||||
|
@ -190,6 +191,8 @@ class NTMRotatingLogHandler(object):
|
|||
else:
|
||||
self.writes_since_check += 1
|
||||
|
||||
encoded, toLog = CharReplace(toLog) # Make sure log message can be written.
|
||||
|
||||
message = u"%s: %s" % (str(section).upper(), toLog)
|
||||
|
||||
out_line = message
|
||||
|
|
|
@ -329,14 +329,12 @@ def CharReplace(fileDirName):
|
|||
elif ((fileDirName[Idx] >= '\x80') & (fileDirName[Idx] <= '\xA5')):
|
||||
utf8Name = fileDirName.decode('cp850')
|
||||
utf8Name = utf8Name.encode('utf-8')
|
||||
logger.debug("Renaming CP850 encoding %s to utf8 %s" %(fileDirName, utf8Name))
|
||||
encodingDetected = True
|
||||
break;
|
||||
# Detect ISO-8859-15
|
||||
elif (fileDirName[Idx] >= '\xA6') & (fileDirName[Idx] <= '\xFF'):
|
||||
utf8Name = fileDirName.decode('iso-8859-15')
|
||||
utf8Name = utf8Name.encode('utf-8')
|
||||
logger.debug("Renamed iso-8859-15 encoding %s to utf8 %s" %(fileDirName, utf8Name))
|
||||
encodingDetected = True
|
||||
break;
|
||||
else:
|
||||
|
@ -344,14 +342,12 @@ def CharReplace(fileDirName):
|
|||
if ((fileDirName[Idx] >= '\x80') & (fileDirName[Idx] <= '\xA5')):
|
||||
utf8Name = fileDirName.decode('cp850')
|
||||
utf8Name = utf8Name.encode('utf-8')
|
||||
logger.debug("Renamed CP850 encoding %s to utf8 %s" %(fileDirName, utf8Name))
|
||||
encodingDetected = True
|
||||
break;
|
||||
# Detect ISO-8859-15
|
||||
elif (fileDirName[Idx] >= '\xA6') & (fileDirName[Idx] <= '\xFF'):
|
||||
utf8Name = fileDirName.decode('iso-8859-15')
|
||||
utf8Name = utf8Name.encode('utf-8')
|
||||
logger.debug("Renamed iso-8859-15 encoding %s to utf8 %s" %(fileDirName, utf8Name))
|
||||
encodingDetected = True
|
||||
break;
|
||||
if encodingDetected == False:
|
||||
|
@ -373,21 +369,23 @@ def convert_to_ascii(inputName, dirName):
|
|||
encoded, base2 = CharReplace(base)
|
||||
if encoded:
|
||||
dirName = os.path.join(dir, base2)
|
||||
logger.info("Renaming directory: %s to: %s." % (base, base2))
|
||||
logger.info("Renaming directory to: %s." % (base2))
|
||||
os.rename(os.path.join(dir,base), dirName)
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
||||
print "[NZB] DIRECTORY=%s" % (dirName) # Return the new directory to NZBGet.
|
||||
|
||||
for dirname, dirnames, filenames in os.walk(dirName, topdown=False):
|
||||
for subdirname in dirnames:
|
||||
encoded, subdirname2 = CharReplace(subdirname)
|
||||
if encoded:
|
||||
logger.info("Renaming directory: %s to: %s." % (subdirname, subdirname2))
|
||||
logger.info("Renaming directory to: %s." % (subdirname2))
|
||||
os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2))
|
||||
|
||||
for dirname, dirnames, filenames in os.walk(dirName):
|
||||
for filename in filenames:
|
||||
encoded, filename2 = CharReplace(filename)
|
||||
if encoded:
|
||||
logger.info("Renaming file: %s to: %s." % (filename, filename2))
|
||||
logger.info("Renaming file to: %s." % (filename2))
|
||||
os.rename(os.path.join(dirname, filename), os.path.join(dirname, filename2))
|
||||
|
||||
return inputName, dirName
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue