diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-14 02:51:07 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 20:50:38 +0100 |
commit | d8096353ba12d9e507c1e574f79b9fbff2a1df02 (patch) | |
tree | 8caab2980ad607dd147d8267974ae3fde2ec4be1 /module/plugins/internal/UnRar.py | |
parent | New extractor: UnTar (diff) | |
download | pyload-d8096353ba12d9e507c1e574f79b9fbff2a1df02.tar.xz |
Update extractors (1)
Diffstat (limited to 'module/plugins/internal/UnRar.py')
-rw-r--r-- | module/plugins/internal/UnRar.py | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 963ca2a2e..93fc04c32 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -6,34 +6,32 @@ import string import subprocess from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.plugins.internal.utils import decode, fs_join, renice +from module.plugins.internal.misc import decode, encode, fsjoin, renice class UnRar(Extractor): __name__ = "UnRar" __type__ = "extractor" - __version__ = "1.29" + __version__ = "1.30" __status__ = "testing" - __description__ = """Rar extractor plugin""" + __description__ = """RAR extractor plugin""" __license__ = "GPLv3" __authors__ = [("RaNaN" , "RaNaN@pyload.org" ), ("Walter Purcaro", "vuolter@gmail.com"), ("Immenz" , "immenz@gmx.net" )] - CMD = "unrar" - EXTENSIONS = [".rar"] + CMD = "unrar" + EXTENSIONS = ["rar", "zip", "cab", "arj", "lzh", "tar", "gz", "ace", "uue", + "bz2", "jar", "iso", "7z", "xz", "z"] - re_multipart = re.compile(r'\.(part|r)(\d+)(?:\.rar)?(\.rev|\.bad)?', re.I) - - re_filefixed = re.compile(r'Building (.+)') - re_filelist = re.compile(r'^(.)(\s*[\w\-.]+)\s+(\d+\s+)+(?:\d+\%\s+)?[\d\-]{8}\s+[\d\:]{5}', re.I | re.M) - - re_wrongpwd = re.compile(r'password', re.I) - re_wrongcrc = re.compile(r'encrypted|damaged|CRC failed|checksum error|corrupt', re.I) - - re_version = re.compile(r'(?:UN)?RAR\s(\d+\.\d+)', re.I) + _RE_PART = re.compile(r'\.(part|r)\d+(\.rar|\.rev)?(\.bad)?', re.I) + _RE_FIXNAME = re.compile(r'Building (.+)') + _RE_FILES = re.compile(r'^(.)(\s*[\w\-.]+)\s+(\d+\s+)+(?:\d+\%\s+)?[\d\-]{8}\s+[\d\:]{5}', re.I | re.M) + _RE_BADPWD = re.compile(r'password', re.I) + _RE_BADCRC = re.compile(r'encrypted|damaged|CRC failed|checksum error|corrupt', re.I) + _RE_VERSION = re.compile(r'(?:UN)?RAR\s(\d+\.\d+)', re.I) @classmethod @@ -62,7 +60,7 @@ class UnRar(Extractor): except OSError: return False - m = cls.re_version.search(out) + m = cls._RE_VERSION.search(out) if m is not None: cls.VERSION = m.group(1) @@ -71,21 +69,21 @@ class UnRar(Extractor): @classmethod def ismultipart(cls, filename): - return True if cls.re_multipart.search(filename) else False + return True if cls._RE_PART.search(filename) else False def verify(self, password=None): p = self.call_cmd("l", "-v", self.target, password=password) out, err = p.communicate() - if self.re_wrongpwd.search(err): + if self._RE_BADPWD.search(err): raise PasswordError - if self.re_wrongcrc.search(err): + if self._RE_BADCRC.search(err): raise CRCError(err) #: Output only used to check if passworded files are present - for attr in self.re_filelist.findall(out): + for attr in self._RE_FILES.findall(out): if attr[0].startswith("*"): raise PasswordError @@ -94,14 +92,14 @@ class UnRar(Extractor): p = self.call_cmd("rc", self.target) #: Communicate and retrieve stderr - self._progress(p) + self.progress(p) err = p.stderr.read().strip() if err or p.returncode: p = self.call_cmd("r", self.target) # communicate and retrieve stderr - self._progress(p) + self.progress(p) err = p.stderr.read().strip() if err or p.returncode: @@ -109,14 +107,14 @@ class UnRar(Extractor): else: dir = os.path.dirname(filename) - name = re_filefixed.search(out).group(1) + name = _RE_FIXNAME.search(out).group(1) self.filename = os.path.join(dir, name) return True - def _progress(self, process): + def progress(self, process): s = "" while True: c = process.stdout.read(1) @@ -125,7 +123,7 @@ class UnRar(Extractor): break #: Reading a percentage sign -> set progress and restart if c == "%": - self.notify_progress(int(s)) + self.notifyprogress(int(s)) s = "" #: Not reading a digit -> therefore restart elif c not in string.digits: @@ -138,17 +136,17 @@ class UnRar(Extractor): def extract(self, password=None): command = "x" if self.fullpath else "e" - p = self.call_cmd(command, self.target, self.out, password=password) + p = self.call_cmd(command, self.target, self.dest, password=password) #: Communicate and retrieve stderr - self._progress(p) + self.progress(p) err = p.stderr.read().strip() if err: - if self.re_wrongpwd.search(err): + if self._RE_BADPWD.search(err): raise PasswordError - elif self.re_wrongcrc.search(err): + elif self._RE_BADCRC.search(err): raise CRCError(err) else: #: Raise error if anything is on stderr @@ -157,18 +155,16 @@ class UnRar(Extractor): if p.returncode: raise ArchiveError(_("Process return code: %d") % p.returncode) - self.files = self.list(password) - - def items(self): + def chunks(self): dir, name = os.path.split(self.filename) #: Actually extracted file files = [self.filename] #: eventually Multipart Files - files.extend(fs_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)) + files.extend(fsjoin(dir, os.path.basename(file)) for file in filter(self.ismultipart, os.listdir(dir)) + if re.sub(self._RE_PART, "", name) == re.sub(self._RE_PART, "", file)) return files @@ -189,12 +185,12 @@ class UnRar(Extractor): if not self.fullpath and self.VERSION.startswith('5'): #@NOTE: Unrar 5 always list full path for f in decode(out).splitlines(): - f = fs_join(self.out, os.path.basename(f.strip())) + f = fsjoin(self.dest, os.path.basename(f.strip())) if os.path.isfile(f): - result.add(fs_join(self.out, os.path.basename(f))) + result.add(fsjoin(self.dest, os.path.basename(f))) else: for f in decode(out).splitlines(): - result.add(fs_join(self.out, f.strip())) + result.add(fsjoin(self.dest, f.strip())) return list(result) @@ -226,8 +222,8 @@ class UnRar(Extractor): #@NOTE: return codes are not reliable, some kind of threading, cleanup whatever issue call = [self.CMD, command] + args + list(xargs) - self.log_debug(" ".join(call)) + call = map(encode, call) p = subprocess.Popen(call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |