summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/MultiHoster.py
diff options
context:
space:
mode:
authorGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-09-24 23:54:50 +0200
committerGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-09-24 23:54:50 +0200
commitb65c4091d5c5e793d8a9df17a46657d45c3a1292 (patch)
tree40a420e5213d28634b75408059a2dc3687e461d1 /module/plugins/internal/MultiHoster.py
parentupdate hellshare/hellspy patterns (diff)
downloadpyload-b65c4091d5c5e793d8a9df17a46657d45c3a1292.tar.xz
multihosters - closed #618, store http/ftp accounts, add uptobox.com premium
Diffstat (limited to 'module/plugins/internal/MultiHoster.py')
-rw-r--r--module/plugins/internal/MultiHoster.py111
1 files changed, 78 insertions, 33 deletions
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py
index e9e321c06..0f25eb8d2 100644
--- a/module/plugins/internal/MultiHoster.py
+++ b/module/plugins/internal/MultiHoster.py
@@ -11,32 +11,54 @@ class MultiHoster(Hook):
Generic MultiHoster plugin
"""
- __version__ = "0.12"
+ __version__ = "0.15"
interval = 0
hosters = []
- replacements = []
+ replacements = [("2shared.com", "twoshared.com"), ("4shared.com", "fourshared.com"), ("cloudnator.com", "shragle.com"),
+ ("ifile.it", "filecloud.io"), ("easy-share.com","crocko.com"), ("freakshare.net","freakshare.com"),
+ ("hellshare.com", "hellshare.cz"), ("share-rapid.cz","sharerapid.com"),
+ ("ul.to","uploaded.to"), ("uploaded.net","uploaded.to")]
supported = []
ignored = []
+ new_supported = []
def getHosterCached(self):
if not self.hosters:
try:
- self.hosters = [x.strip() for x in self.getHoster()]
- self.hosters = filter(lambda x: x and x not in self.ignored, self.hosters)
+ hosterSet = self.toHosterSet(self.getHoster()) - set(self.ignored)
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])
+
+ try:
+ configMode = self.getConfig('hosterListMode')
+ if configMode in ("listed", "unlisted"):
+ configSet = self.toHosterSet(self.getConfig('hosterList').replace('|',',').replace(';',',').split(','))
+
+ if configMode == "listed":
+ hosterSet &= configSet
+ else:
+ hosterSet -= configSet
+
+ except Exception, e:
+ self.logError("%s" % str(e))
+
+ self.hosters = list(hosterSet)
return self.hosters
-
+
+ def toHosterSet(self, hosters):
+ hosters = set((x.strip().lower() for x in hosters))
+
+ for rep in self.replacements:
+ if rep[0] in hosters:
+ hosters.remove(rep[0])
+ hosters.add(rep[1])
+
+ hosters.discard(u'')
+ return hosters
def getHoster(self):
"""Load list of supported hoster
@@ -49,23 +71,29 @@ class MultiHoster(Hook):
pluginMap = {}
for name in self.core.pluginManager.hosterPlugins.keys():
pluginMap[name.lower()] = name
-
- new_supported = []
+
+ accountList = [ name.lower() for name, data in self.core.accountManager.accounts.items() if data ]
+ excludedList = []
for hoster in self.getHosterCached():
name = remove_chars(hoster.lower(), "-.")
- if name in pluginMap:
- self.supported.append(pluginMap[name])
+ if name in accountList:
+ excludedList.append(hoster)
else:
- new_supported.append(hoster)
+ if name in pluginMap:
+ self.supported.append(pluginMap[name])
+ else:
+ self.new_supported.append(hoster)
- if not self.supported and not new_supported:
+ if not self.supported and not self.new_supported:
self.logError(_("No Hoster loaded"))
return
module = self.core.pluginManager.getPlugin(self.__name__)
klass = getattr(module, self.__name__)
+
+ print module, klass
# inject plugin plugin
self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(self.supported)))
@@ -73,25 +101,42 @@ class MultiHoster(Hook):
dict = self.core.pluginManager.hosterPlugins[hoster]
dict["new_module"] = module
dict["new_name"] = self.__name__
+
+ if excludedList:
+ self.logInfo("The following hosters were not overwritten - account exists: %s" % ", ".join(sorted(excludedList)))
+
+ if self.new_supported:
+ self.logDebug("New Hosters: %s" % ", ".join(sorted(self.new_supported)))
+
+ # create new regexp
+ if not klass.__pattern__:
+ regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in new_supported])
+ else:
+ regexp = r"%s|.*(%s).*" % ([klass.__pattern__], "|".join([x.replace(".", "\\.") for x in self.new_supported]))
+ self.logDebug("Regexp: %s" % regexp)
+
+ dict = self.core.pluginManager.hosterPlugins[self.__name__]
+ dict["pattern"] = regexp
+ dict["re"] = re.compile(regexp)
- self.logDebug("New Hosters: %s" % ", ".join(sorted(new_supported)))
-
- # create new regexp
- if not klass.__pattern__:
- regexp = r".*(%s).*" % "|".join([x.replace(".", "\\.") for x in new_supported])
- else:
- 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 unloadHoster(self, hoster):
+ dict = self.core.pluginManager.hosterPlugins[hoster]
+ self.logDebug(dict)
+ if "module" in dict:
+ del dict["module"]
+ if "new_module" in dict:
+ del dict["new_module"]
+ del dict["new_name"]
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"]
+ self.unloadHoster(hoster)
+
+ def downloadFailed(self, pyfile):
+ hdict = self.core.pluginManager.hosterPlugins[pyfile.pluginname]
+ self.logDebug("Unload MultiHoster", pyfile.pluginname, hdict)
+ if "new_name" in hdict and hdict['new_name'] == self.__name__:
+ self.unloadHoster(pyfile.pluginname)
+ pyfile.setStatus("queued") \ No newline at end of file