summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/SkipRev.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/SkipRev.py')
-rw-r--r--module/plugins/hooks/SkipRev.py68
1 files changed, 47 insertions, 21 deletions
diff --git a/module/plugins/hooks/SkipRev.py b/module/plugins/hooks/SkipRev.py
index feed16a2b..107740a3d 100644
--- a/module/plugins/hooks/SkipRev.py
+++ b/module/plugins/hooks/SkipRev.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-import re
+from urllib import unquote
+from urlparse import urlparse
from module.plugins.Hook import Hook
from module.plugins.Plugin import SkipDownload
@@ -9,48 +10,73 @@ from module.plugins.Plugin import SkipDownload
class SkipRev(Hook):
__name__ = "SkipRev"
__type__ = "hook"
- __version__ = "0.11"
+ __version__ = "0.15"
- __config__ = [("auto", "bool", "Automatically keep all rev files needed by package", True),
- ("tokeep", "int" , "Min number of rev files to keep for package" , 1),
- ("unskip", "bool", "Restart a skipped rev when download fails" , True)]
+ __config__ = [("tokeep", "int", "Number of rev files to keep for package (-1 to auto)", -1)]
__description__ = """Skip files ending with extension rev"""
__license__ = "GPLv3"
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- event_list = ["downloadStarts"]
+ #@TODO: Remove in 0.4.10
+ def initPeriodical(self):
+ pass
- REV = re.compile(r'\.part(\d+)\.rev$')
+ def _setup(self):
+ super(self.pyfile.plugin, self).setup()
+ if self.pyfile.hasStatus("skipped"):
+ raise SkipDownload(self.pyfile.getStatusName() or self.pyfile.pluginname)
- def downloadStarts(self, pyfile, url, filename):
- if self.REV.search(pyfile.name) is None or pyfile.getStatusName() is "unskipped":
+
+ 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']
+
+ elif hasattr(plugin, "getInfo"): #@NOTE: if parseInfos was not found, getInfo should be missing too
+ name = plugin.getInfo(url)['name']
+
+ else:
+ self.logWarning("Unable to grab file name")
+ name = urlparse(unquote(url)).path.split('/')[-1])
+
+ return name
+
+
+ def downloadPreparing(self, pyfile):
+ if pyfile.getStatusName() is "unskipped" or not pyname(pyfile).endswith(".rev"):
return
tokeep = self.getConfig("tokeep")
- if tokeep > 0:
+ if tokeep:
saved = [True for link in pyfile.package().getChildren() \
- if link.hasStatus("finished") or link.hasStatus("downloading") and self.REV.search(link.name)].count(True)
+ if link.name.endswith(".rev") and (link.hasStatus("finished") or link.hasStatus("downloading"))].count(True)
- if saved < tokeep:
+ if not saved or saved < tokeep: #: keep one rev at least in auto mode
return
- raise SkipDownload("SkipRev")
+ pyfile.setCustomStatus("SkipRev", "skipped")
+ pyfile.plugin.setup = _setup #: work-around: inject status checker inside the preprocessing routine of the plugin
def downloadFailed(self, pyfile):
- if self.getConfig("auto") is False:
-
- if self.getConfig("unskip") is False:
- return
+ tokeep = self.getConfig("tokeep")
- if self.REV.search(pyfile.name) is None:
- return
+ if not tokeep:
+ return
for link in pyfile.package().getChildren():
- if link.hasStatus("skipped") and self.REV.search(link.name):
- link.setCustomStatus("unskipped", "queued")
+ if link.hasStatus("skipped") and link.name.endswith(".rev"):
+ if tokeep > -1 or pyfile.name.endswith(".rev"):
+ link.setStatus("queued")
+ else:
+ link.setCustomStatus("unskipped", "queued")
return