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.py62
1 files changed, 30 insertions, 32 deletions
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py
index 0ba990006..f6ca5a2eb 100644
--- a/module/plugins/internal/UnRar.py
+++ b/module/plugins/internal/UnRar.py
@@ -22,7 +22,7 @@ def renice(pid, value):
class UnRar(Extractor):
__name__ = "UnRar"
- __version__ = "1.11"
+ __version__ = "1.12"
__description__ = """Rar extractor plugin"""
__license__ = "GPLv3"
@@ -31,42 +31,53 @@ class UnRar(Extractor):
CMD = "unrar"
+ VERSION = ""
- # TODO: Find out what Filetypes Unrar supports exactly
- EXTENSIONS = [".rar", ".cab", ".arj", ".lzh", ".tar", ".gz", ".bz2",
- ".ace", ".uue", ".jar", ".iso", ".7z", ".xz", ".z"]
+ EXTENSIONS = [".rar"]
- #@NOTE: there are some more uncovered rar formats
- re_rarpart1 = re.compile(r'\.part(\d+)\.rar$', re.I)
- re_rarpart2 = re.compile(r'\.r(\d+)$', re.I)
+
+ re_multipart = re.compile(r'\.(part|r)(\d+)(?:\.rar)?',re.I)
re_filefixed = re.compile(r'Building (.+)')
- re_filelist = re.compile(r'(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)')
+ re_filelist = re.compile(r'^(.)(\s*[\w\.\-]+)\s+(\d+\s+)+(?:\d+\%\s+)?[\d\-]{8}\s+[\d\:]{5}', re.M|re.I)
re_wrongpwd = re.compile(r'password', re.I)
re_wrongcrc = re.compile(r'encrypted|damaged|CRC failed|checksum error', re.I)
- re_version = re.compile(r'UNRAR\s(\d+)\.\d+', re.I)
+ re_version = re.compile(r'UNRAR\s(\d+\.\d+)', re.I)
+
@classmethod
def isUsable(cls):
if os.name == "nt":
cls.CMD = os.path.join(pypath, "UnRAR.exe")
p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE)
- p.communicate()
+ out, err = p.communicate()
else:
try:
p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE)
- p.communicate()
+ out, err = p.communicate()
except OSError: #: fallback to rar
cls.CMD = "rar"
p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE)
- p.communicate()
+ out, err = p.communicate()
+
+ cls.VERSION = cls.re_version.search(out).group(1)
return True
+ @classmethod
+ def isMultipart(cls,filename):
+ multipart = cls.re_multipart.search(filename)
+ if multipart:
+ # First Multipart file (part1.rar for *.part1-9.rar format or *.rar for .r1-9 format) handled as normal Archive
+ return False if (multipart.group(1) == "part" and int(multipart.group(2)) == 1) else True
+
+ return False
+
+
def check(self):
p = self.call_cmd("l", "-v", fs_encode(self.filename))
out, err = p.communicate()
@@ -162,23 +173,14 @@ class UnRar(Extractor):
def getDeleteFiles(self):
- files = []
+ dir, name = os.path.split(self.filename)
- for i in (1, 2):
- try:
- dir, name = os.path.split(self.filename)
-
- part = getattr(self, "re_rarpart%d" % i).search(name).group(1)
- new_name = name[::-1].replace((".part%s.rar" % part)[::-1], ".part*.rar"[::-1], 1)[::-1]
- file = fs_encode(os.path.join(dir, new_name))
-
- files.extend(glob(file))
+ # actually extracted file
+ files = [self.filename]
- except Exception:
- continue
-
- if self.filename not in files:
- files.insert(0, self.filename)
+ # eventually Multipart Files
+ files.extend(save_join(self.out, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir))
+ if re.sub(self.re_multipart,".rar",name) == re.sub(self.re_multipart,".rar",file))
return files
@@ -186,10 +188,6 @@ class UnRar(Extractor):
def list(self, password=None):
command = "vb" if self.fullpath else "lb"
- p = self.call_cmd("", "", fs_encode(self.filename))
- out, err = p.communicate()
- version = self.re_version.search(out).group(1)
-
p = self.call_cmd(command, "-v", fs_encode(self.filename), password=password)
out, err = p.communicate()
@@ -200,7 +198,7 @@ class UnRar(Extractor):
self.manager.logError(err.strip())
result = set()
- if not self.fullpath and version =='5':
+ if not self.fullpath and self.rarversion.startswith('5'):
# NOTE: Unrar 5 always list full path
for f in decode(out).splitlines():
f = save_join(self.out, os.path.basename(f.strip()))