summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/UnRar.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/UnRar.py')
-rw-r--r--module/plugins/internal/UnRar.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py
index 3f27c2e9e..1943f69e0 100644
--- a/module/plugins/internal/UnRar.py
+++ b/module/plugins/internal/UnRar.py
@@ -18,16 +18,14 @@
"""
import os
+import re
from os.path import join
from glob import glob
from subprocess import Popen, PIPE
-
from module.plugins.hooks.ExtractArchive import AbtractExtractor
from module.utils import save_join, decode
-import re
-
class UnRar(AbtractExtractor):
__name__ = "UnRar"
__version__ = "0.1"
@@ -36,16 +34,25 @@ class UnRar(AbtractExtractor):
re_splitfile = re.compile(r"(.*)\.part(\d+)\.rar$")
re_filelist = re.compile(r"(.+)\s+(\d+)\s+(\d+)\s+")
re_wrongpwd = re.compile("(Corrupt file or wrong password|password incorrect)")
+ CMD = "unrar"
@staticmethod
def checkDeps():
if os.name == "nt":
- cmd = join(pypath, "UnRAR.exe")
+ UnRar.CMD = join(pypath, "UnRAR.exe")
+ p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE)
+ p.communicate()
else:
- cmd = "unrar"
+ try:
+ p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE)
+ p.communicate()
+ except OSError:
+
+ #fallback to rar
+ UnRar.CMD = "rar"
+ p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE)
+ p.communicate()
- p = Popen([cmd], stdout=PIPE, stderr=PIPE)
- p.communicate()
return True
@staticmethod
@@ -129,7 +136,7 @@ class UnRar(AbtractExtractor):
def getDeleteFiles(self):
if ".part" in self.file:
- return glob(self.file.replace("0", "*").replace("1", "*"))
+ return glob(re.sub("(?<=\.part)([01]+)", "*", self.file, re.IGNORECASE))
return [self.file]
def listContent(self):
@@ -153,13 +160,7 @@ class UnRar(AbtractExtractor):
def call_unrar(self, command, *xargs, **kwargs):
- if os.name == "nt":
- cmd = join(pypath, "UnRAR.exe")
- else:
- cmd = "unrar"
-
args = []
-
#overwrite flag
args.append("-o+") if self.overwrite else args.append("-o-")
@@ -174,7 +175,7 @@ class UnRar(AbtractExtractor):
#NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue
- call = [cmd, command] + args + list(xargs)
+ call = [self.CMD, command] + args + list(xargs)
self.m.logDebug(" ".join(call))
p = Popen(call, stdout=PIPE, stderr=PIPE)