diff --git a/TorrentToMedia.py b/TorrentToMedia.py index cef3da6c..c34e48d1 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -304,9 +304,10 @@ for dirpath, dirnames, filenames in os.walk(inputDirectory): Logger.info("MAIN: Found compressed archive %s for file %s", fileExtention, filePath) source = filePath target = os.path.join(outputDestination, file) - state = extractor.extract(dirpath, file, outputDestination) - if state == False: - Logger.info("MAIN: Failed to unpack file %s", file) + try: + extractor.extract(dirpath, file, outputDestination) + except: + Logger.warn("Extraction failed") failed_extract = 1 else: Logger.info("MAIN: Ignoring unknown filetype %s for file %s", fileExtention, filePath) diff --git a/extractor/bin/x64/7z.dll b/extractor/bin/x64/7z.dll new file mode 100644 index 00000000..cea996e4 Binary files /dev/null and b/extractor/bin/x64/7z.dll differ diff --git a/extractor/bin/x64/7z.exe b/extractor/bin/x64/7z.exe new file mode 100644 index 00000000..b55fefe6 Binary files /dev/null and b/extractor/bin/x64/7z.exe differ diff --git a/extractor/bin/7z.dll b/extractor/bin/x86/7z.dll similarity index 100% rename from extractor/bin/7z.dll rename to extractor/bin/x86/7z.dll diff --git a/extractor/bin/7z.exe b/extractor/bin/x86/7z.exe similarity index 100% rename from extractor/bin/7z.exe rename to extractor/bin/x86/7z.exe diff --git a/extractor/extractor.py b/extractor/extractor.py index d1f27d8a..187cade1 100644 --- a/extractor/extractor.py +++ b/extractor/extractor.py @@ -4,7 +4,18 @@ import logging Logger = logging.getLogger(__name__) -# which() breaks when running in Transmission (has to do with os.environ["PATH"]) +# which() and os_platform() breaks when running in Transmission (has to do with os.environ) + +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"] + except KeyError: + pass + #true_platform not assigned to if this does not exist + return true_platform + def which(program): # Author Credit: Jay @ http://stackoverflow.com/a/377028 def is_exe(fpath): @@ -25,11 +36,15 @@ def which(program): def extract(dirpath, file, outputDestination): # Using Windows if os.name == 'nt': - binLocation = 'extractor/bin/7z.exe' # Only 32bit for now - sevenzipLocation = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), binLocation)) + if os_platform() == 'AMD64': + platform = 'x64' + else: + platform = 'x86' + + sevenzipLocation = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), 'extractor/bin/' + platform + '/7z.exe')) if not os.path.exists(sevenzipLocation): Logger.error("EXTRACTOR: Couldnt find 7-zip, Exiting") - sys.exit(-1) + sys.exit(-1) else: cmd_7zip = [sevenzipLocation, 'x -y'] ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2",".tbz",".tar.lzma",".tlz",".7z",".xz"]