summaryrefslogtreecommitdiffstats
path: root/module/plugins/addon/SkipRev.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/addon/SkipRev.py')
-rw-r--r--module/plugins/addon/SkipRev.py87
1 files changed, 54 insertions, 33 deletions
diff --git a/module/plugins/addon/SkipRev.py b/module/plugins/addon/SkipRev.py
index d6908614d..0bbdec3b2 100644
--- a/module/plugins/addon/SkipRev.py
+++ b/module/plugins/addon/SkipRev.py
@@ -1,16 +1,24 @@
# -*- coding: utf-8 -*-
+from types import MethodType
from urllib import unquote
from urlparse import urlparse
-from pyload.plugin.Addon import Addon
-from pyload.plugin.Plugin import SkipDownload
+from module.PyFile import PyFile
+from module.plugins.Hook import Hook
+from module.plugins.Plugin import SkipDownload
-class SkipRev(Adoon):
+def _setup(self):
+ self.pyfile.plugin._setup()
+ if self.pyfile.hasStatus("skipped"):
+ raise SkipDownload(self.pyfile.statusname or self.pyfile.pluginname)
+
+
+class SkipRev(Hook):
__name__ = "SkipRev"
- __type__ = "addon"
- __version__ = "0.15"
+ __type__ = "hook"
+ __version__ = "0.25"
__config__ = [("tokeep", "int", "Number of rev files to keep for package (-1 to auto)", -1)]
@@ -19,59 +27,72 @@ class SkipRev(Adoon):
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- def _setup(self):
- super(self.pyfile.plugin, self).setup()
- if self.pyfile.hasStatus("skipped"):
- raise SkipDownload(self.pyfile.getStatusName() or self.pyfile.pluginname)
-
-
- def pyname(self, pyfile):
- url = pyfile.url
- plugin = pyfile.plugin
-
- if hasattr(plugin, "info") and 'name' in plugin.info and plugin.info['name']:
- name = plugin.info['name']
-
- elif hasattr(plugin, "parseInfos"):
- name = next(plugin.parseInfos([url]))['name']
+ #@TODO: Remove in 0.4.10
+ def initPeriodical(self):
+ pass
- elif hasattr(plugin, "getInfo"): #@NOTE: if parseInfos was not found, getInfo should be missing too
- name = plugin.getInfo(url)['name']
+ def _pyname(self, pyfile):
+ if hasattr(pyfile.pluginmodule, "getInfo"):
+ return getattr(pyfile.pluginmodule, "getInfo")([pyfile.url]).next()[0]
else:
self.logWarning("Unable to grab file name")
- name = urlparse(unquote(url)).path.split('/')[-1])
+ return urlparse(unquote(pyfile.url)).path.split('/')[-1]
- return name
+
+ def _pyfile(self, link):
+ return PyFile(self.core.files,
+ link.fid,
+ link.url,
+ link.name,
+ link.size,
+ link.status,
+ link.error,
+ link.plugin,
+ link.packageID,
+ link.order)
def downloadPreparing(self, pyfile):
- if pyfile.getStatusName() is "unskipped" or not pyname(pyfile).endswith(".rev"):
+ if pyfile.statusname is "unskipped" or not self._pyname(pyfile).endswith(".rev"):
return
tokeep = self.getConfig("tokeep")
if tokeep:
- saved = [True for link in pyfile.package().getChildren() \
- if link.name.endswith(".rev") and (link.hasStatus("finished") or link.hasStatus("downloading"))].count(True)
+ status_list = (1, 4, 8, 9, 14) if tokeep < 0 else (1, 3, 4, 8, 9, 14)
+
+ queued = [True for link in self.core.api.getPackageData(pyfile.package().id).links \
+ if link.name.endswith(".rev") and link.status not in status_list].count(True)
- if not saved or saved < tokeep: #: keep one rev at least in auto mode
+ if not queued or queued < tokeep: #: keep one rev at least in auto mode
return
pyfile.setCustomStatus("SkipRev", "skipped")
- pyfile.plugin.setup = _setup #: work-around: inject status checker inside the preprocessing routine of the plugin
+ pyfile.plugin._setup = pyfile.plugin.setup
+ pyfile.plugin.setup = MethodType(_setup, pyfile.plugin) #: work-around: inject status checker inside the preprocessing routine of the plugin
def downloadFailed(self, pyfile):
+ #: Check if pyfile is still "failed",
+ # maybe might has been restarted in meantime
+ if pyfile.status != 8:
+ return
+
tokeep = self.getConfig("tokeep")
if not tokeep:
return
- for link in pyfile.package().getChildren():
- if link.hasStatus("skipped") and link.name.endswith(".rev"):
+ for link in self.core.api.getPackageData(pyfile.package().id).links:
+ if link.status is 4 and link.name.endswith(".rev"):
+ pylink = self._pyfile(link)
+
if tokeep > -1 or pyfile.name.endswith(".rev"):
- link.setStatus("queued")
+ pylink.setStatus("queued")
else:
- link.setCustomStatus("unskipped", "queued")
+ pylink.setCustomStatus("unskipped", "queued")
+
+ self.core.files.save()
+ pylink.release()
return