diff options
Diffstat (limited to 'module/plugins/internal/Extractor.py')
-rw-r--r-- | module/plugins/internal/Extractor.py | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/module/plugins/internal/Extractor.py b/module/plugins/internal/Extractor.py index 41ba4d429..1d035f3e6 100644 --- a/module/plugins/internal/Extractor.py +++ b/module/plugins/internal/Extractor.py @@ -5,7 +5,7 @@ import re from module.PyFile import PyFile from module.plugins.internal.Plugin import Plugin -from module.plugins.internal.utils import encode +from module.plugins.internal.misc import encode class ArchiveError(Exception): @@ -40,7 +40,7 @@ class Extractor(Plugin): @classmethod def isarchive(cls, filename): name = os.path.basename(filename).lower() - return any(name.endswith(ext) for ext in cls.EXTENSIONS) + return any(name.endswith('.' + ext) for ext in cls.EXTENSIONS) @classmethod @@ -63,43 +63,48 @@ class Extractor(Plugin): :param files_ids: List of filepathes :return: List of targets, id tuple list """ - targets = [] + targets = [] processed = [] - for fname, id, fout in files_ids: - if cls.isarchive(fname): - pname = re.sub(cls.re_multipart, "", fname) if cls.ismultipart(fname) else os.path.splitext(fname)[0] - if pname not in processed: - processed.append(pname) - targets.append((fname, id, fout)) + for id, fname, fout in files_ids: + if not cls.isarchive(fname): + continue + + if cls.ismultipart(fname): + pname = re.sub(cls._RE_PART, "", fname) + else: + pname = os.path.splitext(fname)[0] + + if pname in processed: + continue + + processed.append(pname) + targets.append((id, fname, fout)) return targets - def __init__(self, plugin, filename, out, + def __init__(self, pyfile, filename, out, fullpath=True, overwrite=False, excludefiles=[], priority=0, - keepbroken=False, - fid=None): + keepbroken=False): """ Initialize extractor for specific file """ - self._init(plugin.pyload) + self._init(pyfile.m.core) - self.plugin = plugin + self.pyfile = pyfile self.filename = filename + self.name = os.path.basename(filename) self.out = out self.fullpath = fullpath self.overwrite = overwrite self.excludefiles = excludefiles self.priority = priority self.keepbroken = keepbroken - self.files = [] #: Store extracted files here - - pyfile = self.pyload.files.getFile(fid) if fid else None - self.notify_progress = lambda x: pyfile.setProgress(x) if pyfile else lambda x: None + self.progress = lambda x: pyfile.setProgress(int(x)) self.init() @@ -109,9 +114,14 @@ class Extractor(Plugin): return encode(self.filename) + @property + def dest(self): + return encode(self.out) + + def _log(self, level, plugintype, pluginname, messages): messages = (self.__name__,) + messages - return self.plugin._log(level, plugintype, self.plugin.__name__, messages) + return self.pyfile.plugin._log(level, plugintype, self.pyfile.plugin.__name__, messages) def verify(self, password=None): @@ -134,7 +144,7 @@ class Extractor(Plugin): raise NotImplementedError - def items(self): + def chunks(self): """ Return list of archive parts """ @@ -143,6 +153,6 @@ class Extractor(Plugin): def list(self, password=None): """ - Populate self.files at some point while extracting + Return list of archive files """ - return self.files + raise NotImplementedError |