diff options
Diffstat (limited to 'pyload/plugin/extractor')
-rw-r--r-- | pyload/plugin/extractor/SevenZip.py | 38 | ||||
-rw-r--r-- | pyload/plugin/extractor/UnRar.py | 71 | ||||
-rw-r--r-- | pyload/plugin/extractor/UnZip.py | 8 |
3 files changed, 60 insertions, 57 deletions
diff --git a/pyload/plugin/extractor/SevenZip.py b/pyload/plugin/extractor/SevenZip.py index 74eb4c855..1d7d57886 100644 --- a/pyload/plugin/extractor/SevenZip.py +++ b/pyload/plugin/extractor/SevenZip.py @@ -12,7 +12,7 @@ from pyload.utils import fs_encode, safe_join class SevenZip(UnRar): __name = "SevenZip" __type = "extractor" - __version = "0.08" + __version = "0.09" __description = """7-Zip extractor plugin""" __license = "GPLv3" @@ -33,9 +33,9 @@ class SevenZip(UnRar): #@NOTE: there are some more uncovered 7z formats re_filelist = re.compile(r'([\d\:]+)\s+([\d\:]+)\s+([\w\.]+)\s+(\d+)\s+(\d+)\s+(.+)') - re_wrongpwd = re.compile(r'(Can not open encrypted archive|Wrong password)', re.I) - re_wrongcrc = re.compile(r'Encrypted\s+\=\s+\+', re.I) - re_version = re.compile(r'7-Zip\s(?:\[64\]\s)?(\d+\.\d+)', re.I) + re_wrongpwd = re.compile(r'(Can not open encrypted archive|Wrong password|Encrypted\s+\=\s+\+)', re.I) + re_wrongcrc = re.compile(r'CRC Failed|Can not open file', re.I) + re_version = re.compile(r'7-Zip\s(?:\[64\]\s)?(\d+\.\d+)', re.I) @classmethod @@ -53,36 +53,38 @@ class SevenZip(UnRar): return True - def check(self): + def test(self, password): file = fs_encode(self.filename) - p = self.call_cmd("t", file) + # 7z can't distinguish crc and pw error in test + p = self.call_cmd("l", "-slt", file) out, err = p.communicate() - if p.returncode > 1: + if self.re_wrongpwd.search(out): + raise PasswordError + + if self.re_wrongpwd.search(err): + raise PasswordError + + if self.re_wrongcrc.search(err): raise CRCError(err) + + + def check(self, password): + file = fs_encode(self.filename) + p = self.call_cmd("l", "-slt", file) out, err = p.communicate() - if p.returncode > 1: - raise ArchiveError(_("Process return code: %d") % p.returncode) - # check if output or error macthes the 'wrong password'-Regexp if self.re_wrongpwd.search(out): raise PasswordError - # check if output matches 'Encrypted = +' if self.re_wrongcrc.search(out): raise CRCError(_("Header protected")) - def isPassword(self, password): - p = self.call_cmd("l", fs_encode(self.filename), password=password) - p.communicate() - return p.returncode == 0 - - def repair(self): return False @@ -143,7 +145,7 @@ class SevenZip(UnRar): #set a password if "password" in kwargs and kwargs["password"]: - args.append("-p'%s'" % kwargs["password"]) + args.append("-p%s" % kwargs["password"]) else: args.append("-p-") diff --git a/pyload/plugin/extractor/UnRar.py b/pyload/plugin/extractor/UnRar.py index 0ff815597..a8279bfa9 100644 --- a/pyload/plugin/extractor/UnRar.py +++ b/pyload/plugin/extractor/UnRar.py @@ -23,7 +23,7 @@ def renice(pid, value): class UnRar(Extractor): __name = "UnRar" __type = "extractor" - __version = "1.13" + __version = "1.14" __description = """Rar extractor plugin""" __license = "GPLv3" @@ -34,34 +34,40 @@ class UnRar(Extractor): CMD = "unrar" VERSION = "" - EXTENSIONS = [".rar"] - re_multipart = re.compile(r'\.(part|r)(\d+)(?:\.rar)?',re.I) + 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.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_wrongcrc = re.compile(r'encrypted|damaged|CRC failed|checksum error|corrupt', re.I) - re_version = re.compile(r'UNRAR\s(\d+\.\d+)', re.I) + re_version = re.compile(r'(?:UN)?RAR\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) - out, err = p.communicate() - else: try: + cls.CMD = os.path.join(pypath, "RAR.exe") p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) out, err = p.communicate() - - except OSError: #: fallback to rar - cls.CMD = "rar" + cls.__name__ = "RAR" + cls.REPAIR = True + except OSError: + cls.CMD = os.path.join(pypath, "UnRAR.exe") + p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) + out, err = p.communicate() + else: + try: + p = Popen(["rar"], stdout=PIPE, stderr=PIPE) + out, err = p.communicate() + cls.__name__ = "RAR" + cls.REPAIR = True + except OSError: #: fallback to unrar p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) out, err = p.communicate() @@ -75,13 +81,25 @@ class UnRar(Extractor): 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 if (multipart.group(1) == "part" and int(multipart.group(2)) == 1 and not multipart.group(3)) else True return False - def check(self): - p = self.call_cmd("l", "-v", fs_encode(self.filename)) + def test(self, password): + p = self.call_cmd("t", "-v", fs_encode(self.filename), password=password) + self._progress(p) + err = p.stderr.read().strip() + + if self.re_wrongpwd.search(err): + raise PasswordError + + if self.re_wrongcrc.search(err): + raise CRCError(err) + + + def check(self, password): + p = self.call_cmd("l", "-v", fs_encode(self.filename), password=password) out, err = p.communicate() if self.re_wrongpwd.search(err): @@ -96,35 +114,14 @@ class UnRar(Extractor): raise PasswordError - def isPassword(self, password): - # at this point we can only verify header protected files - p = self.call_cmd("l", "-v", fs_encode(self.filename), password=password) - out, err = p.communicate() - return False if self.re_wrongpwd.search(err) else True - - def repair(self): p = self.call_cmd("rc", fs_encode(self.filename)) # communicate and retrieve stderr self._progress(p) err = p.stderr.read().strip() - if err or p.returncode: - p = self.call_cmd("r", fs_encode(self.filename)) - - # communicate and retrieve stderr - self._progress(p) - err = p.stderr.read().strip() - - if err or p.returncode: - return False - else: - dir = os.path.dirname(filename) - name = re_filefixed.search(out).group(1) - - self.filename = os.path.join(dir, name) - + return False return True diff --git a/pyload/plugin/extractor/UnZip.py b/pyload/plugin/extractor/UnZip.py index 68dea3a1d..811ca7700 100644 --- a/pyload/plugin/extractor/UnZip.py +++ b/pyload/plugin/extractor/UnZip.py @@ -13,7 +13,7 @@ from pyload.utils import fs_encode class UnZip(Extractor): __name = "UnZip" __type = "extractor" - __version = "1.10" + __version = "1.11" __description = """Zip extractor plugin""" __license = "GPLv3" @@ -35,7 +35,11 @@ class UnZip(Extractor): return z.namelist() - def check(self): + def check(self, password): + pass + + + def test(self): with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: badfile = z.testzip() |