From 2a809297f288a585d96af0d8afd894c2a2f695fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=B6rnlein?= Date: Sun, 8 Feb 2015 13:47:59 +0100 Subject: [ExtractArchive] correct fullpath behavior, bugfix --- module/plugins/internal/UnRar.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'module/plugins/internal/UnRar.py') diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 81cfb38a7..0ba990006 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.10" + __version__ = "1.11" __description__ = """Rar extractor plugin""" __license__ = "GPLv3" @@ -37,15 +37,16 @@ class UnRar(Extractor): ".ace", ".uue", ".jar", ".iso", ".7z", ".xz", ".z"] #@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_rarpart1 = re.compile(r'\.part(\d+)\.rar$', re.I) + re_rarpart2 = re.compile(r'\.r(\d+)$', re.I) re_filefixed = re.compile(r'Building (.+)') - re_filelist = re.compile(r'(.+)\s+(\D+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)') + re_filelist = re.compile(r'(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)') 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) @classmethod def isUsable(cls): @@ -185,6 +186,10 @@ 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() @@ -195,9 +200,16 @@ class UnRar(Extractor): self.manager.logError(err.strip()) result = set() - for f in decode(out).splitlines(): - f = f.strip() - result.add(save_join(self.out, f)) + if not self.fullpath and version =='5': + # NOTE: Unrar 5 always list full path + for f in decode(out).splitlines(): + f = save_join(self.out, os.path.basename(f.strip())) + if os.path.isfile(f): + result.add(save_join(self.out, os.path.basename(f))) + else: + for f in decode(out).splitlines(): + f = f.strip() + result.add(save_join(self.out, f)) return list(result) -- cgit v1.2.3 From 2dc3536e36956eab99fa5f7945dcf60073b5fd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=B6rnlein?= Date: Mon, 9 Feb 2015 23:36:10 +0100 Subject: [ExtractArchive] better Multipart behavior, new version output --- module/plugins/internal/UnRar.py | 62 +++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'module/plugins/internal/UnRar.py') 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())) -- cgit v1.2.3 From f2ac32085922f739343bac3cf396e703833323f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20H=C3=B6rnlein?= Date: Wed, 11 Feb 2015 16:32:55 +0100 Subject: [UnRar] bugfixes --- module/plugins/internal/UnRar.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/UnRar.py') diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index f6ca5a2eb..54d64c430 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -22,12 +22,13 @@ def renice(pid, value): class UnRar(Extractor): __name__ = "UnRar" - __version__ = "1.12" + __version__ = "1.13" __description__ = """Rar extractor plugin""" __license__ = "GPLv3" __authors__ = [("RaNaN", "RaNaN@pyload.org"), - ("Walter Purcaro", "vuolter@gmail.com")] + ("Walter Purcaro", "vuolter@gmail.com"), + ("Immenz", "immenz@gmx.net"),] CMD = "unrar" @@ -179,7 +180,7 @@ class UnRar(Extractor): files = [self.filename] # eventually Multipart Files - files.extend(save_join(self.out, os.path.basename(file)) for file in filter(self.isMultipart, os.listdir(dir)) + files.extend(save_join(dir, 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 @@ -198,7 +199,7 @@ class UnRar(Extractor): self.manager.logError(err.strip()) result = set() - if not self.fullpath and self.rarversion.startswith('5'): + if not self.fullpath and self.VERSION.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())) -- cgit v1.2.3