summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-11-14 19:53:55 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-11-14 19:53:55 +0100
commit9d8d8db40662aeeb8ebbc5e6934d39f84574dd80 (patch)
treecff8ab2e9c20cd8a4b27b42b704c75377d343fd6 /module/plugins/internal
parentrehost,to timeout fix (diff)
downloadpyload-9d8d8db40662aeeb8ebbc5e6934d39f84574dd80.tar.xz
improved plugin loader, import hook to always use newest plugin versions
Diffstat (limited to 'module/plugins/internal')
-rw-r--r--module/plugins/internal/AbstractExtractor.py93
-rw-r--r--module/plugins/internal/MultiHoster.py90
-rw-r--r--module/plugins/internal/SimpleHoster.py12
-rw-r--r--module/plugins/internal/UnRar.py12
-rw-r--r--module/plugins/internal/UnZip.py2
5 files changed, 201 insertions, 8 deletions
diff --git a/module/plugins/internal/AbstractExtractor.py b/module/plugins/internal/AbstractExtractor.py
new file mode 100644
index 000000000..2130f910e
--- /dev/null
+++ b/module/plugins/internal/AbstractExtractor.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+class ArchiveError(Exception):
+ pass
+
+class CRCError(Exception):
+ pass
+
+class WrongPassword(Exception):
+ pass
+
+class AbtractExtractor:
+ @staticmethod
+ def checkDeps():
+ """ Check if system statisfy dependencies
+ :return: boolean
+ """
+ return True
+
+ @staticmethod
+ def getTargets(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
+ """
+ raise NotImplementedError
+
+
+ def __init__(self, m, file, out, fullpath, overwrite, renice):
+ """Initialize extractor for specific file
+
+ :param m: ExtractArchive Hook plugin
+ :param file: Absolute filepath
+ :param out: Absolute path to destination directory
+ :param fullpath: extract to fullpath
+ :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.renice = renice
+ self.files = [] # Store extracted files here
+
+
+ def init(self):
+ """ Initialize additional data structures """
+ pass
+
+
+ def checkArchive(self):
+ """Check if password if needed. Raise ArchiveError if integrity is
+ questionable.
+
+ :return: boolean
+ :raises ArchiveError
+ """
+ return False
+
+ def checkPassword(self, password):
+ """ Check if the given password is/might be correct.
+ If it can not be decided at this point return true.
+
+ :param password:
+ :return: boolean
+ """
+ return True
+
+ def extract(self, progress, password=None):
+ """Extract the archive. Raise specific errors in case of failure.
+
+ :param progress: Progress function, call this to update status
+ :param password password to use
+ :raises WrongPassword
+ :raises CRCError
+ :raises ArchiveError
+ :return:
+ """
+ raise NotImplementedError
+
+ def getDeleteFiles(self):
+ """Return list of files to delete, do *not* delete them here.
+
+ :return: List with paths of files to delete
+ """
+ raise NotImplementedError
+
+ def getExtractedFiles(self):
+ """Populate self.files at some point while extracting"""
+ return self.files \ No newline at end of file
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py
new file mode 100644
index 000000000..6f0b4b636
--- /dev/null
+++ b/module/plugins/internal/MultiHoster.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import re
+
+from module.utils import removeChars
+from module.plugins.Hook import Hook
+
+class MultiHoster(Hook):
+ """
+ Generic MultiHoster plugin
+ """
+
+ interval = 0
+ hosters = []
+ replacements = []
+ supported = []
+
+ def getHosterCached(self):
+ if not self.hosters:
+
+ try:
+ self.hosters = self.getHoster()
+ except Exception, e:
+ self.logError("%s" % str(e))
+ return []
+
+ for rep in self.replacements:
+ if rep[0] in self.hosters:
+ self.hosters.remove(rep[0])
+ if rep[1] not in self.hosters:
+ self.hosters.append(rep[1])
+
+ return self.hosters
+
+
+ def getHoster(self):
+ """Load list of supported hoster
+
+ :return: List of domain names
+ """
+ raise NotImplementedError
+
+ def coreReady(self):
+ pluginMap = {}
+ for name in self.core.pluginManager.hosterPlugins.keys():
+ pluginMap[name.lower()] = name
+
+ new_supported = []
+
+ for hoster in self.getHosterCached():
+ name = removeChars(hoster.lower(), "-.")
+
+ if name in pluginMap:
+ self.supported.append(pluginMap[name])
+ else:
+ new_supported.append(hoster)
+
+ if not self.supported and not new_supported:
+ self.logError(_("No Hoster loaded"))
+ return
+
+ module = self.core.pluginManager.getPlugin(self.__name__)
+ klass = getattr(module, self.__name__)
+
+ # inject plugin plugin
+ self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(self.supported)))
+ for hoster in self.supported:
+ dict = self.core.pluginManager.hosterPlugins[hoster]
+ dict["new_module"] = module
+ dict["new_name"] = self.__name__
+
+ self.logDebug("New Hosters: %s" % ", ".join(sorted(new_supported)))
+
+ # create new regexp
+ regexp = r".*(%s).*" % "|".join([klass.__pattern__] + [x.replace(".", "\\.") for x in new_supported])
+
+ dict = self.core.pluginManager.hosterPlugins[self.__name__]
+ dict["pattern"] = regexp
+ dict["re"] = re.compile(regexp)
+
+
+ def unload(self):
+ for hoster in self.supported:
+ dict = self.core.pluginManager.hosterPlugins[hoster]
+ if "module" in dict:
+ del dict["module"]
+
+ del dict["new_module"]
+ del dict["new_name"] \ No newline at end of file
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index a05b6e98c..e0963fd91 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -19,8 +19,10 @@
from module.plugins.Hoster import Hoster
from module.utils import html_unescape
+from module.network.RequestFactory import getURL
from re import search
+
def parseFileInfo(self, url = '', html = ''):
if not html and hasattr(self, "html"): html = self.html
name, size, status, found = '', 0, 3, 0
@@ -52,7 +54,15 @@ def parseFileInfo(self, url = '', html = ''):
if not name: name = url
- return (name, size, status, url)
+ return name, size, status, url
+
+
+def create_getInfo(plugin):
+ def getInfo(urls):
+ for url in urls:
+ file_info = parseFileInfo(plugin, url, getURL(url, decode=True))
+ yield file_info
+ return getInfo
class PluginParseError(Exception):
def __init__(self, msg):
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py
index 1943f69e0..feac4c176 100644
--- a/module/plugins/internal/UnRar.py
+++ b/module/plugins/internal/UnRar.py
@@ -23,8 +23,8 @@ from os.path import join
from glob import glob
from subprocess import Popen, PIPE
-from module.plugins.hooks.ExtractArchive import AbtractExtractor
from module.utils import save_join, decode
+from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPassword, ArchiveError, CRCError
class UnRar(AbtractExtractor):
__name__ = "UnRar"
@@ -95,7 +95,7 @@ class UnRar(AbtractExtractor):
self.listContent()
if not self.files:
- self.m.archiveError("Empty Archive")
+ raise ArchiveError("Empty Archive")
return False
@@ -123,11 +123,11 @@ class UnRar(AbtractExtractor):
progress(100)
if "CRC failed" in err and not password and not self.passwordProtected:
- self.m.crcError()
+ raise CRCError
elif "CRC failed" in err:
- self.m.wrongPassword()
+ raise WrongPassword
if err.strip(): #raise error if anything is on stderr
- self.m.archiveError(err.strip())
+ raise ArchiveError(err.strip())
if not self.files:
self.password = password
@@ -145,7 +145,7 @@ class UnRar(AbtractExtractor):
out, err = p.communicate()
if "Cannot open" in err:
- self.m.archiveError("Cannot open file")
+ raise ArchiveError("Cannot open file")
if err.strip(): # only log error at this point
self.m.logError(err.strip())
diff --git a/module/plugins/internal/UnZip.py b/module/plugins/internal/UnZip.py
index dc60c1041..9aa9ac75c 100644
--- a/module/plugins/internal/UnZip.py
+++ b/module/plugins/internal/UnZip.py
@@ -20,7 +20,7 @@
import zipfile
import sys
-from module.plugins.hooks.ExtractArchive import AbtractExtractor
+from module.plugins.internal.AbstractExtractor import AbtractExtractor
class UnZip(AbtractExtractor):
__name__ = "UnZip"