diff options
author | Walter Purcaro <vuolter@gmail.com> | 2015-01-29 23:13:54 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2015-01-29 23:13:54 +0100 |
commit | 788a06132882300a22f6db3aa7ac3a6009d4d762 (patch) | |
tree | a6df8ca7e7edab49552847dc33cc8c18ae6d2f08 /module/plugins/internal | |
parent | [RapidgatorNet] Fix typo (diff) | |
download | pyload-788a06132882300a22f6db3aa7ac3a6009d4d762.tar.xz |
Update Extractor (2)
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Extractor.py | 17 | ||||
-rw-r--r-- | module/plugins/internal/SevenZip.py | 24 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 64 | ||||
-rw-r--r-- | module/plugins/internal/UnZip.py | 12 |
4 files changed, 73 insertions, 44 deletions
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index ddf0f8a85..3ea634ec8 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -3,7 +3,6 @@ import os from module.PyFile import PyFile -from module.utils import fs_encode class ArchiveError(Exception): @@ -20,7 +19,7 @@ class PasswordError(Exception): class Extractor: __name__ = "Extractor" - __version__ = "0.15" + __version__ = "0.16" __description__ = """Base extractor plugin""" __license__ = "GPLv3" @@ -64,7 +63,7 @@ class Extractor: fid=None): """ Initialize extractor for specific file """ self.manager = manager - self.target = fs_encode(filename) + self.filename = filename self.out = out self.fullpath = fullpath self.overwrite = overwrite @@ -83,17 +82,17 @@ class Extractor: pass - def checkArchive(self): + def check(self): """Check if password if needed. Raise ArchiveError if integrity is questionable. :return: boolean :raises ArchiveError """ - return False + raise PasswordError - def checkPassword(self, password): + def isPassword(self, password): """ Check if the given password is/might be correct. If it can not be decided at this point return true. @@ -103,6 +102,10 @@ class Extractor: return True + def repair(self): + return False + + def extract(self, password=None): """Extract the archive. Raise specific errors in case of failure. @@ -121,7 +124,7 @@ class Extractor: :return: List with paths of files to delete """ - return [self.target] + return [self.filename] def getExtractedFiles(self): diff --git a/module/plugins/internal/SevenZip.py b/module/plugins/internal/SevenZip.py index 508cf9c8d..e808e0d88 100644 --- a/module/plugins/internal/SevenZip.py +++ b/module/plugins/internal/SevenZip.py @@ -5,13 +5,13 @@ import re from subprocess import Popen, PIPE -from module.plugins.internal.UnRar import UnRar, renice -from module.utils import save_join +from module.plugins.internal.UnRar import ArchiveError, CRCError, PasswordError, UnRar, renice +from module.utils import fs_encode, save_join class SevenZip(UnRar): __name__ = "SevenZip" - __version__ = "0.02" + __version__ = "0.03" __description__ = """7-Zip extractor plugin""" __license__ = "GPLv3" @@ -48,8 +48,8 @@ class SevenZip(UnRar): return True - def checkArchive(self): - p = self.call_cmd("l", "-slt", self.target) + def check(self): + p = self.call_cmd("l", "-slt", fs_encode(self.filename)) out, err = p.communicate() if p.returncode > 1: @@ -57,22 +57,20 @@ class SevenZip(UnRar): # check if output or error macthes the 'wrong password'-Regexp if self.re_wrongpwd.search(out): - return True + raise PasswordError # check if output matches 'Encrypted = +' if self.re_wrongcrc.search(out): - return True + raise CRCError # check if archive is empty self.files = self.list() if not self.files: raise ArchiveError("Empty Archive") - return False - - def checkPassword(self, password): - p = self.call_cmd("l", self.target, password=password) + def isPassword(self, password): + p = self.call_cmd("l", fs_encode(self.filename), password=password) p.communicate() return p.returncode == 0 @@ -80,7 +78,7 @@ class SevenZip(UnRar): def extract(self, password=None): command = "x" if self.fullpath else "e" - p = self.call_cmd(command, '-o' + self.out, self.target, password=password) + p = self.call_cmd(command, '-o' + self.out, fs_encode(self.filename), password=password) renice(p.pid, self.renice) @@ -123,7 +121,7 @@ class SevenZip(UnRar): def list(self, password=None): command = "l" if self.fullpath else "l" - p = self.call_cmd(command, self.target, password=password) + p = self.call_cmd(command, fs_encode(self.filename), password=password) out, err = p.communicate() code = p.returncode diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 7f1b08caf..b8e2c3606 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -8,20 +8,21 @@ from string import digits from subprocess import Popen, PIPE from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError -from module.utils import save_join, decode +from module.utils import decode, fs_encode, save_join, uniqify def renice(pid, value): if value and os.name != "nt": try: Popen(["renice", str(value), str(pid)], stdout=PIPE, stderr=PIPE, bufsize=-1) + except Exception: pass class UnRar(Extractor): __name__ = "UnRar" - __version__ = "1.04" + __version__ = "1.05" __description__ = """Rar extractor plugin""" __license__ = "GPLv3" @@ -71,42 +72,65 @@ class UnRar(Extractor): continue m = cls.re_rarpart1.match(filename) - if not m or int(m.group(1)) is 1: #@NOTE: only add first part file + if not m or int(m.group(1)) == 1: #@NOTE: only add first part file targets.append((filename, id)) return targets - def checkArchive(self): - p = self.call_cmd("l", "-v", self.target) + def check(self): + p = self.call_cmd("l", "-v", fs_encode(self.filename)) out, err = p.communicate() if self.re_wrongpwd.search(err): - return True + raise PasswordError + + if self.re_wrongcrc.search(err): + raise CRCError # output only used to check if passworded files are present for attr in self.re_filelist.findall(out): if attr[0].startswith("*"): - return True + raise PasswordError self.files = self.list() if not self.files: raise ArchiveError("Empty Archive") - return False - - def checkPassword(self, password): + def isPassword(self, password): # at this point we can only verify header protected files - p = self.call_cmd("l", "-v", self.target, password=password) + 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)) + out, err = p.communicate() + + if p.returncode or err.strip(): + p = self.call_cmd("r", fs_encode(self.filename)) + out, err = p.communicate() + + if p.returncode or err.strip(): + return False + else: + dir, name = os.path.split(filename) + + if 'fixed' in out: + self.filename = os.path.join(dir, 'fixed.' + name) + + elif 'rebuild' in out: + self.filename = os.path.join(dir, 'rebuild.' + name) + + return True + + 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, fs_encode(self.filename), self.out, password=password) renice(p.pid, self.renice) @@ -139,7 +163,7 @@ class UnRar(Extractor): elif err.strip(): #: raise error if anything is on stderr raise ArchiveError(err.strip()) - if p.returncode != 0: + if p.returncode: raise ArchiveError("Process terminated") if not self.files: @@ -149,18 +173,18 @@ class UnRar(Extractor): def getDeleteFiles(self): files = [] - for i in [1, 2]: + for i in (1, 2): try: - dir, name = os.path.split(self.target) + dir, name = os.path.split(self.filename) part = self.getattr(self, "re_rarpart%d" % i).match(name).group(1) - filename = os.path.join(dir, name.replace(part, '*', 1)) - files.extend(glob(filename)) + file = fs_encode(os.path.join(dir, name.replace(part, '*', 1))) + files.extend(glob(file)) except Exception: continue - if self.target not in files: - files.insert(0, self.target) + if self.filename not in files: + files.insert(0, self.filename) return files @@ -168,7 +192,7 @@ class UnRar(Extractor): def list(self, password=None): command = "vb" if self.fullpath else "lb" - p = self.call_cmd(command, "-v", self.target, password=password) + p = self.call_cmd(command, "-v", fs_encode(self.filename), password=password) out, err = p.communicate() if "Cannot open" in err: diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 026503be5..4f3f1ca32 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -7,16 +7,16 @@ import sys import zipfile from module.plugins.internal.Extractor import Extractor, ArchiveError, CRCError, PasswordError +from module.utils import fs_encode class UnZip(Extractor): __name__ = "UnZip" - __version__ = "1.03" + __version__ = "1.04" __description__ = """Zip extractor plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.org"), - ("Walter Purcaro", "vuolter@gmail.com")] + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] EXTENSIONS = [".zip", ".zip64"] @@ -32,9 +32,13 @@ class UnZip(Extractor): return [(filename, id) for filename, id in files_ids if cls.isArchive(filename)] + def repair(self): + return False + + def extract(self, password=None): try: - with zipfile.ZipFile(self.target, 'r', allowZip64=True) as z: + with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z: z.setpassword(self.password) if not z.testzip(): z.extractall(self.out) |