summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/plugins/hooks/DeleteFinished.py61
-rw-r--r--module/plugins/hooks/RestartFailed.py124
-rw-r--r--module/plugins/hoster/RyushareCom.py6
3 files changed, 178 insertions, 13 deletions
diff --git a/module/plugins/hooks/DeleteFinished.py b/module/plugins/hooks/DeleteFinished.py
index be83d6ced..e0df69eef 100644
--- a/module/plugins/hooks/DeleteFinished.py
+++ b/module/plugins/hooks/DeleteFinished.py
@@ -23,7 +23,7 @@ from time import time
class DeleteFinished(Hook):
__name__ = "DeleteFinished"
- __version__ = "0.2"
+ __version__ = "0.5"
__description__ = "Automatically delete finished packages from queue"
__config__ = [
("activated", "bool", "Activated", "False"),
@@ -32,16 +32,55 @@ class DeleteFinished(Hook):
__author_name__ = ("Walter Purcaro")
__author_mail__ = ("vuolter@gmail.com")
- #: event_map don't load periodical anyway
+ def wakeup(self, pypack):
+ # self.logDebug("self.wakeup")
+ self.removeEvent("packageFinished", self.wakeup)
+ self.info["sleep"] = False
+
def periodical(self):
- now = time()
- deletetime = self.getConfig("interval") * 3600 + self.info["lastdelete"]
- if now >= deletetime:
+ # self.logDebug("self.periodical")
+ if not self.info["sleep"]:
self.core.api.deleteFinished()
- self.logDebug("called self.core.api.deleteFinished()")
- self.info["lastdelete"] = now
+ self.logDebug("called self.core.api.deleteFinished")
+ self.info["sleep"] = True
+ self.addEvent("packageFinished", self.wakeup)
+
+ def addEvent(self, event, handler):
+ if event in self.manager.events:
+ if handler not in self.manager.events[event]:
+ self.manager.events[event].append(handler)
+ # self.logDebug("self.addEvent: " + event + ": added handler")
+ else:
+ # self.logDebug("self.addEvent: " + event + ": NOT added handler")
+ return False
+ else:
+ self.manager.events[event] = [handler]
+ # self.logDebug("self.addEvent: " + event + ": added event and handler")
+ return True
+
+ def removeEvent(self, event, handler):
+ if event in self.manager.events and handler in self.manager.events[event]:
+ self.manager.events[event].remove(handler)
+ # self.logDebug("self.removeEvent: " + event + ": removed handler")
+ return True
+ else:
+ # self.logDebug("self.removeEvent: " + event + ": NOT removed handler")
+ return False
+
+ def configEvents(self, plugin=None, name=None, value=None):
+ # self.logDebug("self.configEvents")
+ interval = self.getConfig("interval") * 3600
+ if interval != self.interval:
+ self.interval = interval
+
+ def unload(self):
+ # self.logDebug("self.unload")
+ self.removeEvent("pluginConfigChanged", self.configEvents)
+ self.removeEvent("packageFinished", self.wakeup)
- def setup(self):
- now = time()
- self.info = {"lastdelete": now}
- self.interval = 3600
+ def coreReady(self):
+ # self.logDebug("self.coreReady")
+ self.info = {"sleep": True}
+ self.addEvent("pluginConfigChanged", self.configEvents)
+ self.configEvents()
+ self.addEvent("packageFinished", self.wakeup)
diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py
new file mode 100644
index 000000000..7ee53deb9
--- /dev/null
+++ b/module/plugins/hooks/RestartFailed.py
@@ -0,0 +1,124 @@
+ # -*- coding: utf-8 -*-
+
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ @author: Walter Purcaro
+"""
+
+from module.plugins.Hook import Hook
+from time import time
+
+
+class RestartFailed(Hook):
+ __name__ = "RestartFailed"
+ __version__ = "1.5"
+ __description__ = "Automatically restart failed/aborted downloads"
+ __config__ = [
+ ("activated", "bool", "Activated", "True"),
+ ("dlFail", "bool", "Restart when download fail", "True"),
+ ("dlFail_n", "int", "Only when failed downloads are at least", "5"),
+ ("dlFail_i", "int", "Only when elapsed time since last restart is (min)", "10"),
+ ("dlPrcs", "bool", "Restart after all downloads are processed", "True"),
+ ("recnt", "bool", "Restart after reconnecting", "True"),
+ ("rsLoad", "bool", "Restart on plugin activation", "False")
+ ]
+ __author_name__ = ("Walter Purcaro")
+ __author_mail__ = ("vuolter@gmail.com")
+
+ def restart(self, arg=None):
+ # self.logDebug("self.restart")
+ self.info["timerflag"] = False
+ self.info["dlfailed"] = 0
+ self.core.api.restartFailed()
+ self.logDebug("self.restart: self.core.api.restartFailed")
+ self.info["lastrstime"] = time()
+
+ def periodical(self):
+ # self.logDebug("self.periodical")
+ if self.info["timerflag"]:
+ self.restart()
+
+ def checkInterval(self, arg=None):
+ # self.logDebug("self.checkInterval")
+ now = time()
+ lastrstime = self.info["lastrstime"]
+ interval = self.getConfig("dlFail_i") * 60
+ if now < lastrstime + interval:
+ self.info["timerflag"] = True
+ else:
+ self.restart()
+
+ def checkFailed(self, pyfile):
+ # self.logDebug("self.checkFailed")
+ self.info["dlfailed"] += 1
+ curr = self.info["dlfailed"]
+ max = self.getConfig("dlFail_n")
+ if curr >= max:
+ self.checkInterval()
+
+ def addEvent(self, event, handler):
+ if event in self.manager.events:
+ if handler not in self.manager.events[event]:
+ self.manager.events[event].append(handler)
+ # self.logDebug("self.addEvent: " + event + ": added handler")
+ else:
+ # self.logDebug("self.addEvent: " + event + ": NOT added handler")
+ return False
+ else:
+ self.manager.events[event] = [handler]
+ # self.logDebug("self.addEvent: " + event + ": added event and handler")
+ return True
+
+ def removeEvent(self, event, handler):
+ if event in self.manager.events and handler in self.manager.events[event]:
+ self.manager.events[event].remove(handler)
+ # self.logDebug("self.removeEvent: " + event + ": removed handler")
+ return True
+ else:
+ # self.logDebug("self.removeEvent: " + event + ": NOT removed handler")
+ return False
+
+ def configEvents(self, plugin=None, name=None, value=None):
+ # self.logDebug("self.configEvents")
+ self.interval = self.getConfig("dlFail_i") * 60
+ dlFail = self.getConfig("dlFail")
+ dlPrcs = self.getConfig("dlPrcs")
+ recnt = self.getConfig("recnt")
+ if dlPrcs:
+ self.addEvent("allDownloadsProcessed", self.checkInterval)
+ else:
+ self.removeEvent("allDownloadsProcessed", self.checkInterval)
+ if not dlFail:
+ self.info["timerflag"] = False
+ if recnt:
+ self.addEvent("afterReconnecting", self.restart)
+ else:
+ self.removeEvent("afterReconnecting", self.restart)
+
+ def unload(self):
+ # self.logDebug("self.unload")
+ self.removeEvent("pluginConfigChanged", self.configEvents)
+ self.removeEvent("downloadFailed", self.checkFailed)
+ self.removeEvent("allDownloadsProcessed", self.checkInterval)
+ self.removeEvent("afterReconnecting", self.restart)
+
+ def coreReady(self):
+ # self.logDebug("self.coreReady")
+ self.info = {"dlfailed": 0, "lastrstime": 0, "timerflag": False}
+ if self.getConfig("rsLoad"):
+ self.restart()
+ self.addEvent("downloadFailed", self.checkFailed)
+ self.addEvent("pluginConfigChanged", self.configEvents)
+ self.configEvents()
diff --git a/module/plugins/hoster/RyushareCom.py b/module/plugins/hoster/RyushareCom.py
index c2ff54e0c..7bfe4e8fe 100644
--- a/module/plugins/hoster/RyushareCom.py
+++ b/module/plugins/hoster/RyushareCom.py
@@ -7,7 +7,7 @@ class RyushareCom(XFileSharingPro):
__name__ = "RyushareCom"
__type__ = "hoster"
__pattern__ = r"http://(?:\w*\.)*?ryushare.com/\w{11,}"
- __version__ = "0.10"
+ __version__ = "0.11"
__description__ = """ryushare.com hoster plugin"""
__author_name__ = ("zoidberg", "stickell")
__author_mail__ = ("zoidberg@mujmail.cz", "l.stickell@yahoo.it")
@@ -18,7 +18,9 @@ class RyushareCom(XFileSharingPro):
DIRECT_LINK_PATTERN = r'<a href="([^"]+)">Click here to download</a>'
def setup(self):
- self.resumeDownload = self.multiDL = self.premium
+ self.resumeDownload = self.multiDL = True
+ if not self.premium:
+ self.limitDL = 2
# Up to 3 chunks allowed in free downloads. Unknown for premium
self.chunkLimit = 3