diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-18 18:45:17 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-18 18:45:17 +0100 |
commit | da9e6c949243613f4d5e100cac6ff192449b4718 (patch) | |
tree | 5c9d96913d8a86a822821f781ab209105e426489 | |
parent | Update checkFile routine in some hoster plugins (diff) | |
download | pyload-da9e6c949243613f4d5e100cac6ff192449b4718.tar.xz |
Update extractor plugins
-rw-r--r-- | module/plugins/hooks/ExtractArchive.py | 37 | ||||
-rw-r--r-- | module/plugins/internal/AbstractExtractor.py | 29 | ||||
-rw-r--r-- | module/plugins/internal/UnRar.py | 54 | ||||
-rw-r--r-- | module/plugins/internal/UnZip.py | 15 |
4 files changed, 68 insertions, 67 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py index 895aee51f..ddec8319b 100644 --- a/module/plugins/hooks/ExtractArchive.py +++ b/module/plugins/hooks/ExtractArchive.py @@ -16,7 +16,6 @@ if sys.version_info < (2, 7) and os.name != "nt": import errno from subprocess import Popen - def _eintr_retry_call(func, *args): while True: try: @@ -59,7 +58,7 @@ from module.utils import save_join, fs_encode class ExtractArchive(Hook): __name__ = "ExtractArchive" __type__ = "hook" - __version__ = "0.19" + __version__ = "0.20" __config__ = [("activated", "bool", "Activated", True), ("fullpath", "bool", "Extract full path", True), @@ -89,7 +88,7 @@ class ExtractArchive(Hook): def setup(self): - self.plugins = [] + self.plugins = [] self.passwords = [] names = [] @@ -141,24 +140,27 @@ class ExtractArchive(Hook): @threaded def allDownloadsProcessed(self, thread): local = copy(self.queue) + del self.queue[:] + if self.extract(local, thread): #: check only if all gone fine, no failed reporting for now self.manager.dispatchEvent("all_archives_extracted") + self.manager.dispatchEvent("all_archives_processed") def extract(self, ids, thread=None): processed = [] extracted = [] - failed = [] + failed = [] - destination = self.getConfig("destination") - subfolder = self.getConfig("subfolder") - fullpath = self.getConfig("fullpath") - overwrite = self.getConfig("overwrite") + destination = self.getConfig("destination") + subfolder = self.getConfig("subfolder") + fullpath = self.getConfig("fullpath") + overwrite = self.getConfig("overwrite") excludefiles = self.getConfig("excludefiles") - renice = self.getConfig("renice") - recursive = self.getConfig("recursive") + renice = self.getConfig("renice") + recursive = self.getConfig("recursive") # reload from txt file self.reloadPasswords() @@ -208,8 +210,7 @@ class ExtractArchive(Hook): klass = plugin(self, target, out, fullpath, overwrite, excludefiles, renice) klass.init() - passwords = p.password.strip().splitlines() - new_files = self._extract(klass, fid, passwords, thread) + new_files = self._extract(klass, fid, [p.password.strip()], thread) except Exception, e: self.logError(basename(target), e) @@ -253,15 +254,15 @@ class ExtractArchive(Hook): success = False if not plugin.checkArchive(): - plugin.extract(progress) + plugin.extract(progress, pw) success = True else: self.logInfo(basename(plugin.file), _("Password protected")) - self.logDebug("Passwords", passwords) + self.logDebug("Passwords: %s" % passwords if passwords else "No password provided") - for pw in set(passwords) + set(self.getPasswords()): + for pw in set(passwords) | set(self.getPasswords()): try: - self.logDebug("Try password", pw) + self.logDebug("Try password: %s" % pw) if plugin.checkPassword(pw): plugin.extract(progress, pw) self.addPassword(pw) @@ -305,6 +306,7 @@ class ExtractArchive(Hook): self.logError(basename(plugin.file), _("Unknown Error"), e) self.manager.dispatchEvent("archive_extract_failed", pyfile) + raise Exception(_("Extract failed")) @@ -344,6 +346,7 @@ class ExtractArchive(Hook): with open(passwordfile, "wb") as f: for pw in self.passwords: f.write(pw + "\n") + except IOError, e: self.logError(e) @@ -352,6 +355,7 @@ class ExtractArchive(Hook): for f in files: if not exists(f): continue + try: if self.config['permission']['change_file']: if isfile(f): @@ -363,5 +367,6 @@ class ExtractArchive(Hook): uid = getpwnam(self.config['permission']['user'])[2] gid = getgrnam(self.config['permission']['group'])[2] chown(f, uid, gid) + except Exception, e: self.logWarning(_("Setting User and Group failed"), e) diff --git a/module/plugins/internal/AbstractExtractor.py b/module/plugins/internal/AbstractExtractor.py index 2317ad689..c8a73c861 100644 --- a/module/plugins/internal/AbstractExtractor.py +++ b/module/plugins/internal/AbstractExtractor.py @@ -14,23 +14,24 @@ class WrongPassword(Exception): class AbtractExtractor: __name__ = "AbtractExtractor" - __version__ = "0.10" + __version__ = "0.11" __description__ = """Abtract extractor plugin""" __license__ = "GPLv3" - __authors__ = [("pyLoad Team", "admin@pyload.org")] + __authors__ = [("RaNaN", "ranan@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] - @staticmethod - def checkDeps(): + @classmethod + def checkDeps(cls): """ Check if system statisfy dependencies :return: boolean """ return True - @staticmethod - def getTargets(files_ids): + @classmethod + def getTargets(cls, files_ids): """ Filter suited targets from list of filename id tuple list :param files_ids: List of filepathes :return: List of targets, id tuple list @@ -48,14 +49,14 @@ class AbtractExtractor: :param overwrite: Overwrite existing archives :param renice: Renice value """ - self.m = m - self.file = file - self.out = out - self.fullpath = fullpath - self.overwrite = overwrite + self.m = m + self.file = file + self.out = out + self.fullpath = fullpath + self.overwrite = overwrite self.excludefiles = excludefiles - self.renice = renice - self.files = [] #: Store extracted files here + self.renice = renice + self.files = [] #: Store extracted files here def init(self): @@ -83,7 +84,7 @@ class AbtractExtractor: return True - def extract(self, progress, password=None): + def extract(self, progress, password=""): """Extract the archive. Raise specific errors in case of failure. :param progress: Progress function, call this to update status diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py index 716a62613..4bbd2042c 100644 --- a/module/plugins/internal/UnRar.py +++ b/module/plugins/internal/UnRar.py @@ -22,53 +22,52 @@ def renice(pid, value): class UnRar(AbtractExtractor): __name__ = "UnRar" - __version__ = "0.20" + __version__ = "0.21" __description__ = """Rar extractor plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.org")] + __authors__ = [("RaNaN", "RaNaN@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] CMD = "unrar" - # there are some more uncovered rar formats - re_version = re.compile(r'UNRAR ([\w .]+?)') + #@NOTE: there are some more uncovered rar formats re_splitfile = re.compile(r'(.*)\.part(\d+)\.rar$', re.I) re_partfiles = re.compile(r'.*\.(rar|r\d+)', re.I) - re_filelist = re.compile(r'(.+)\s+(\d+)\s+(\d+)\s+') - re_filelist5 = re.compile(r'(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)') + re_filelist = re.compile(r'(.+)\s+(\d+)\s+(\d+)\s+|(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)') re_wrongpwd = re.compile(r'(Corrupt file or wrong password|password incorrect)', re.I) - @staticmethod - def checkDeps(): + @classmethod + def checkDeps(cls): if os.name == "nt": - UnRar.CMD = join(pypath, "UnRAR.exe") - p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE) + cls.CMD = join(pypath, "UnRAR.exe") + p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) p.communicate() else: try: - p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE) + p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) p.communicate() - except OSError: + except OSError: # fallback to rar - UnRar.CMD = "rar" - p = Popen([UnRar.CMD], stdout=PIPE, stderr=PIPE) + cls.CMD = "rar" + p = Popen([cls.CMD], stdout=PIPE, stderr=PIPE) p.communicate() return True - @staticmethod - def getTargets(files_ids): + @classmethod + def getTargets(cls, files_ids): result = [] for file, id in files_ids: if not file.endswith(".rar"): continue - match = UnRar.re_splitfile.findall(file) + match = cls.re_splitfile.findall(file) if match: # only add first parts if int(match[0][1]) == 1: @@ -81,9 +80,8 @@ class UnRar(AbtractExtractor): def init(self): self.passwordProtected = False - self.headerProtected = False #: list files will not work without password - self.smallestFile = None #: small file to test passwords - self.password = "" #: save the correct password + self.headerProtected = False #: list files will not work without password + self.password = "" #: save the correct password def checkArchive(self): @@ -95,16 +93,10 @@ class UnRar(AbtractExtractor): return True # output only used to check if passworded files are present - if self.re_version.search(out): - for attr, size, name in self.re_filelist5.findall(out): - if attr.startswith("*"): - self.passwordProtected = True - return True - else: - for name, size, packed in self.re_filelist.findall(out): - if name.startswith("*"): - self.passwordProtected = True - return True + for attr in self.re_filelist.findall(out): + if attr[0].startswith("*"): + self.passwordProtected = True + return True self.listContent() if not self.files: @@ -131,6 +123,7 @@ class UnRar(AbtractExtractor): renice(p.pid, self.renice) progress(0) + progressstring = "" while True: c = p.stdout.read(1) @@ -147,6 +140,7 @@ class UnRar(AbtractExtractor): # add digit to progressstring else: progressstring = progressstring + c + progress(100) # retrieve stderr diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py index 52e279ccf..81c298784 100644 --- a/module/plugins/internal/UnZip.py +++ b/module/plugins/internal/UnZip.py @@ -8,20 +8,21 @@ from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPas class UnZip(AbtractExtractor): __name__ = "UnZip" - __version__ = "0.11" + __version__ = "0.12" __description__ = """Zip extractor plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "RaNaN@pyload.org")] + __authors__ = [("RaNaN", "RaNaN@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] - @staticmethod - def checkDeps(): + @classmethod + def checkDeps(cls): return sys.version_info[:2] >= (2, 6) - @staticmethod - def getTargets(files_ids): + @classmethod + def getTargets(cls, files_ids): result = [] for file, id in files_ids: @@ -31,7 +32,7 @@ class UnZip(AbtractExtractor): return result - def extract(self, progress, password=None): + def extract(self, progress, password=""): try: z = zipfile.ZipFile(self.file) self.files = z.namelist() |