diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-08-18 12:20:21 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-08-18 12:20:21 +0200 |
commit | a9f070cebd0af09e9942a595946a2eb84bacde13 (patch) | |
tree | 37926f5c3411122ef474b8440520385f4b82c9bf | |
parent | forgot to comment line in (diff) | |
download | pyload-a9f070cebd0af09e9942a595946a2eb84bacde13.tar.xz |
generic multihoster plugin
-rw-r--r-- | module/common/MultiHoster.py | 90 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 7 | ||||
-rw-r--r-- | module/plugins/hooks/RealdebridCom.py | 61 | ||||
-rw-r--r-- | module/plugins/hooks/RehostTo.py | 57 | ||||
-rw-r--r-- | module/plugins/hoster/RehostTo.py | 1 |
5 files changed, 109 insertions, 107 deletions
diff --git a/module/common/MultiHoster.py b/module/common/MultiHoster.py new file mode 100644 index 000000000..6f0b4b636 --- /dev/null +++ b/module/common/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/network/HTTPDownload.py b/module/network/HTTPDownload.py index b5f6313d5..440a3defa 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -151,6 +151,7 @@ class HTTPDownload(): lastTimeCheck = 0 chunksDone = set() chunksCreated = False + done = False if self.info.getCount() > 1: # This is a resume, if we were chunked originally assume still can self.chunkSupport=True @@ -206,9 +207,13 @@ class HTTPDownload(): chunksDone.add(c[0]) if not num_q: lastFinishCheck = t + + if len(chunksDone) == len(self.chunks): + done = True #all chunks loaded + break - if len(chunksDone) == len(self.chunks): + if done: break #all chunks loaded # calc speed once per second diff --git a/module/plugins/hooks/RealdebridCom.py b/module/plugins/hooks/RealdebridCom.py index 59035926a..4ec109de4 100644 --- a/module/plugins/hooks/RealdebridCom.py +++ b/module/plugins/hooks/RealdebridCom.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -import re -from module.network.RequestFactory import getURL -from module.plugins.Hook import Hook -from module.utils import removeChars +from module.network.RequestFactory import getURL +from module.common.MultiHoster import MultiHoster -class RealdebridCom(Hook): +class RealdebridCom(MultiHoster): __name__ = "RealdebridCom" __version__ = "0.4" __type__ = "hook" @@ -18,55 +16,10 @@ class RealdebridCom(Hook): __author_name__ = ("Devirex, Hazzard") __author_mail__ = ("naibaf_11@yahoo.de") - interval = 0 - hosters = [] - replacements = [("freakshare.net", "freakshare.com")] - def getHostersCached(self): - if not self.hosters: - https = "https" if self.getConfig("https") else "http" - page = getURL(https + "://real-debrid.com/api/hosters.php").replace("\"","").strip() - - self.hosters = [x.strip() for x in page.split(",") if x.strip()] - - for rep in self.replacements: - if rep[0] in self.hosters: - self.hosters.remove(rep[0]) - self.hosters.append(rep[1]) - - return self.hosters - - def coreReady(self): - pluginMap = {} - for name in self.core.pluginManager.hosterPlugins.keys(): - pluginMap[name.lower()] = name - - supported = [] - new_supported = [] - - for hoster in self.getHostersCached(): - name = removeChars(hoster.lower(), "-.") - - if name in pluginMap: - supported.append(pluginMap[name]) - else: - new_supported.append(hoster) - - module = self.core.pluginManager.getPlugin("RealdebridCom") - klass = getattr(module, "RealdebridCom") - #inject real debrid plugin - self.logDebug("Overwritten Hosters: %s" % ", ".join(sorted(supported))) - for hoster in supported: - dict = self.core.pluginManager.hosterPlugins[hoster] - dict["new_module"] = module - dict["new_name"] = "RealdebridCom" - - 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]) + def getHoster(self): + https = "https" if self.getConfig("https") else "http" + page = getURL(https + "://real-debrid.com/api/hosters.php").replace("\"","").strip() - dict = self.core.pluginManager.hosterPlugins["RealdebridCom"] - dict["pattern"] = regexp - dict["re"] = re.compile(regexp) + return[x.strip() for x in page.split(",") if x.strip()]
\ No newline at end of file diff --git a/module/plugins/hooks/RehostTo.py b/module/plugins/hooks/RehostTo.py index 48b0fd826..f0a95d925 100644 --- a/module/plugins/hooks/RehostTo.py +++ b/module/plugins/hooks/RehostTo.py @@ -1,12 +1,9 @@ # -*- coding: utf-8 -*- -import re from module.network.RequestFactory import getURL -from module.plugins.Hook import Hook +from module.common.MultiHoster import MultiHoster -from module.utils import removeChars - -class RehostTo(Hook): +class RehostTo(MultiHoster): __name__ = "RehostTo" __version__ = "0.4" __type__ = "hook" @@ -17,24 +14,13 @@ class RehostTo(Hook): __author_name__ = ("RaNaN") __author_mail__ = ("RaNaN@pyload.org") - interval = 0 - hosters = [] - replacements = [("freakshare.net", "freakshare.com")] - def getHostersCached(self): - if not self.hosters: - - page = getURL("http://rehost.to/api.php?cmd=get_supported_och_dl&long_ses=%s" % self.long_ses) + def getHoster(self): - self.hosters = [x.strip() for x in page.replace("\"", "").split(",")] + page = getURL("http://rehost.to/api.php?cmd=get_supported_och_dl&long_ses=%s" % self.long_ses) + return [x.strip() for x in page.replace("\"", "").split(",")] - for rep in self.replacements: - if rep[0] in self.hosters: - self.hosters.remove(rep[0]) - self.hosters.append(rep[1]) - - return self.hosters def coreReady(self): @@ -50,35 +36,4 @@ class RehostTo(Hook): self.ses = data["ses"] self.long_ses = data["long_ses"] - pluginMap = {} - for name in self.core.pluginManager.hosterPlugins.keys(): - pluginMap[name.lower()] = name - - supported = [] - new_supported = [] - - for hoster in self.getHostersCached(): - name = removeChars(hoster.lower(), "-.") - - if name in pluginMap: - supported.append(pluginMap[name]) - else: - new_supported.append(hoster) - - module = self.core.pluginManager.getPlugin("RehostTo") - klass = getattr(module, "RehostTo") - #inject real debrid plugin - self.core.log.debug("Rehost.to: Overwritten Hosters: %s" % ", ".join(sorted(supported))) - for hoster in supported: - dict = self.core.pluginManager.hosterPlugins[hoster] - dict["new_module"] = module - dict["new_name"] = "RehostTo" - - self.core.log.debug("Rehost.to: 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["RehostTo"] - dict["pattern"] = regexp - dict["re"] = re.compile(regexp) + return MultiHoster.coreReady(self) diff --git a/module/plugins/hoster/RehostTo.py b/module/plugins/hoster/RehostTo.py index 2755facb7..2531d7dbe 100644 --- a/module/plugins/hoster/RehostTo.py +++ b/module/plugins/hoster/RehostTo.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import re from urllib import quote, unquote from module.plugins.Hoster import Hoster |