mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Updated logger code to now include the section, formatting has been modified as well.
Logging of debug messages is now optional via log_debug option location in autoProcessMedia.cfg Lots of code cleanup has been performed including cleanup log messages and corrections of spelling errors. Improved release lookup code for autoProcessMovie, narrows search results down by making API calls to the download clients to compare results in CouchPotato's database.
This commit is contained in:
parent
dd41ff3b2f
commit
eb7822b60b
16 changed files with 420 additions and 441 deletions
|
@ -11,10 +11,10 @@ def os_platform():
|
|||
# Author Credit: Matthew Scouten @ http://stackoverflow.com/a/7260315
|
||||
true_platform = os.environ['PROCESSOR_ARCHITECTURE']
|
||||
try:
|
||||
true_platform = os.environ["PROCESSOR_ARCHITEW6432"]
|
||||
true_platform = os.environ["PROCESSOR_ARCHITEW6432"]
|
||||
except KeyError:
|
||||
pass
|
||||
#true_platform not assigned to if this does not exist
|
||||
pass
|
||||
#true_platform not assigned to if this does not exist
|
||||
return true_platform
|
||||
|
||||
|
||||
|
@ -27,10 +27,13 @@ def extract(filePath, outputDestination):
|
|||
platform = 'x86'
|
||||
if not os.path.dirname(sys.argv[0]):
|
||||
chplocation = os.path.normpath(os.path.join(os.getcwd(), 'nzbtomedia/extractor/bin/chp.exe'))
|
||||
sevenzipLocation = os.path.normpath(os.path.join(os.getcwd(), 'nzbtomedia/extractor/bin/' + platform + '/7z.exe'))
|
||||
sevenzipLocation = os.path.normpath(
|
||||
os.path.join(os.getcwd(), 'nzbtomedia/extractor/bin/' + platform + '/7z.exe'))
|
||||
else:
|
||||
chplocation = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), 'nzbtomedia/extractor/bin/chp.exe'))
|
||||
sevenzipLocation = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), 'nzbtomedia/extractor/bin/' + platform + '/7z.exe'))
|
||||
chplocation = os.path.normpath(
|
||||
os.path.join(os.path.dirname(sys.argv[0]), 'nzbtomedia/extractor/bin/chp.exe'))
|
||||
sevenzipLocation = os.path.normpath(
|
||||
os.path.join(os.path.dirname(sys.argv[0]), 'nzbtomedia/extractor/bin/' + platform + '/7z.exe'))
|
||||
if not os.path.exists(sevenzipLocation):
|
||||
logger.error("EXTRACTOR: Could not find 7-zip, Exiting")
|
||||
return False
|
||||
|
@ -39,11 +42,11 @@ def extract(filePath, outputDestination):
|
|||
cmd_7zip = [sevenzipLocation, "x", "-y"]
|
||||
else:
|
||||
cmd_7zip = [chplocation, sevenzipLocation, "x", "-y"]
|
||||
ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2",".tbz",".tar.lzma",".tlz",".7z",".xz"]
|
||||
ext_7zip = [".rar", ".zip", ".tar.gz", "tgz", ".tar.bz2", ".tbz", ".tar.lzma", ".tlz", ".7z", ".xz"]
|
||||
EXTRACT_COMMANDS = dict.fromkeys(ext_7zip, cmd_7zip)
|
||||
# Using unix
|
||||
else:
|
||||
required_cmds=["unrar", "unzip", "tar", "unxz", "unlzma", "7zr", "bunzip2"]
|
||||
required_cmds = ["unrar", "unzip", "tar", "unxz", "unlzma", "7zr", "bunzip2"]
|
||||
## Possible future suport:
|
||||
# gunzip: gz (cmd will delete original archive)
|
||||
## the following do not extract to dest dir
|
||||
|
@ -60,14 +63,14 @@ def extract(filePath, outputDestination):
|
|||
".tar.lzma": ["tar", "--lzma", "-xf"], ".tlz": ["tar", "--lzma", "-xf"],
|
||||
".tar.xz": ["tar", "--xz", "-xf"], ".txz": ["tar", "--xz", "-xf"],
|
||||
".7z": ["7zr", "x"],
|
||||
}
|
||||
}
|
||||
# Test command exists and if not, remove
|
||||
if not os.getenv('TR_TORRENT_DIR'):
|
||||
for cmd in required_cmds:
|
||||
if call(['which', cmd]): #note, returns 0 if exists, or 1 if doesn't exist.
|
||||
if call(['which', cmd]): #note, returns 0 if exists, or 1 if doesn't exist.
|
||||
for k, v in EXTRACT_COMMANDS.items():
|
||||
if cmd in v[0]:
|
||||
logger.error("EXTRACTOR: %s not found, disabling support for %s", cmd, k)
|
||||
logger.error("EXTRACTOR: %s not found, disabling support for %s" % (cmd, k))
|
||||
del EXTRACT_COMMANDS[k]
|
||||
else:
|
||||
logger.warning("EXTRACTOR: Cannot determine which tool to use when called from Transmission")
|
||||
|
@ -78,16 +81,16 @@ def extract(filePath, outputDestination):
|
|||
ext = os.path.splitext(filePath)
|
||||
cmd = []
|
||||
if ext[1] in (".gz", ".bz2", ".lzma"):
|
||||
# Check if this is a tar
|
||||
# Check if this is a tar
|
||||
if os.path.splitext(ext[0])[1] == ".tar":
|
||||
cmd = EXTRACT_COMMANDS[".tar" + ext[1]]
|
||||
elif ext[1] in (".1", ".01", ".001") and os.path.splitext(ext[0])[1] in (".rar", ".zip", ".7z"): #support for *.zip.001, *.zip.002 etc.
|
||||
cmd = EXTRACT_COMMANDS[os.path.splitext(ext[0])[1]]
|
||||
elif ext[1] in (".1", ".01", ".001") and os.path.splitext(ext[0])[1] in (".rar", ".zip", ".7z"):
|
||||
cmd = EXTRACT_COMMANDS[os.path.splitext(ext[0])[1]]
|
||||
else:
|
||||
if ext[1] in EXTRACT_COMMANDS:
|
||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||
else:
|
||||
logger.debug("EXTRACTOR: Unknown file type: %s", ext[1])
|
||||
logger.debug("EXTRACTOR: Unknown file type: %s" % ext[1])
|
||||
return False
|
||||
|
||||
# Create outputDestination folder
|
||||
|
@ -99,39 +102,42 @@ def extract(filePath, outputDestination):
|
|||
else:
|
||||
passwords = []
|
||||
|
||||
logger.info("Extracting %s to %s", filePath, outputDestination)
|
||||
logger.debug("Extracting %s %s %s", cmd, filePath, outputDestination)
|
||||
pwd = os.getcwd() # Get our Present Working Directory
|
||||
os.chdir(outputDestination) # Not all unpack commands accept full paths, so just extract into this directory
|
||||
try: # now works same for nt and *nix
|
||||
cmd.append(filePath) # add filePath to final cmd arg.
|
||||
logger.info("Extracting %s to %s" % (filePath, outputDestination))
|
||||
logger.debug("Extracting %s %s %s" % (cmd, filePath, outputDestination))
|
||||
pwd = os.getcwd() # Get our Present Working Directory
|
||||
os.chdir(outputDestination) # Not all unpack commands accept full paths, so just extract into this directory
|
||||
try: # now works same for nt and *nix
|
||||
cmd.append(filePath) # add filePath to final cmd arg.
|
||||
cmd2 = cmd
|
||||
cmd2.append("-p-") # don't prompt for password.
|
||||
p = Popen(cmd2) # should extract files fine.
|
||||
cmd2.append("-p-") # don't prompt for password.
|
||||
p = Popen(cmd2) # should extract files fine.
|
||||
res = p.wait()
|
||||
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.
|
||||
logger.info("EXTRACTOR: Extraction was successful for %s to %s", filePath, outputDestination)
|
||||
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.
|
||||
logger.info("EXTRACTOR: Extraction was successful for %s to %s" % (filePath, outputDestination))
|
||||
elif len(passwords) > 0:
|
||||
logger.info("EXTRACTOR: Attempting to extract with passwords")
|
||||
pass_success = int(0)
|
||||
for password in passwords:
|
||||
if password == "": # if edited in windows or otherwise if blank lines.
|
||||
if password == "": # if edited in windows or otherwise if blank lines.
|
||||
continue
|
||||
cmd2 = cmd
|
||||
#append password here.
|
||||
passcmd = "-p" + password
|
||||
cmd2.append(passcmd)
|
||||
p = Popen(cmd2) # should extract files fine.
|
||||
p = Popen(cmd2) # should extract files fine.
|
||||
res = p.wait()
|
||||
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.
|
||||
logger.info("EXTRACTOR: Extraction was successful for %s to %s using password: %s", filePath, outputDestination, password)
|
||||
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.
|
||||
logger.info("EXTRACTOR: Extraction was successful for %s to %s using password: %s" % (
|
||||
filePath, outputDestination, password))
|
||||
pass_success = int(1)
|
||||
break
|
||||
else:
|
||||
continue
|
||||
if pass_success == int(0):
|
||||
logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)
|
||||
logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s" % (filePath, res))
|
||||
except:
|
||||
logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd)
|
||||
os.chdir(pwd) # Go back to our Original Working Directory
|
||||
logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s" % (filePath, cmd))
|
||||
os.chdir(pwd) # Go back to our Original Working Directory
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue