summaryrefslogtreecommitdiffstats
path: root/module/plugins/Plugin.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-09-30 16:19:37 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-09-30 16:19:37 +0200
commit8092da86ec029b3a4b16ba68762e8caa1445a270 (patch)
tree424aada934b7951e8d45e2aa4d99d5edf9320c39 /module/plugins/Plugin.py
parentNEW: 1fichier.com hoster plugin, not info API support yet. (diff)
downloadpyload-8092da86ec029b3a4b16ba68762e8caa1445a270.tar.xz
fixed proxy support, downloadCheck function
Diffstat (limited to 'module/plugins/Plugin.py')
-rw-r--r--module/plugins/Plugin.py46
1 files changed, 42 insertions, 4 deletions
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index ba65370c5..8009c8f01 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -18,7 +18,6 @@
"""
import logging
-from os.path import join
from time import time
from time import sleep
@@ -26,12 +25,14 @@ from time import sleep
from random import randint
import sys
-from os.path import exists
import os
from os import remove
from os import makedirs
from os import chmod
+from os import stat
+from os.path import exists
+from os.path import join
if os.name != "nt":
from os import chown
@@ -96,6 +97,7 @@ class Plugin(object):
if self.account and not self.account.canUse(): self.account = None
if self.account:
self.req = self.account.getAccountRequest(self)
+ #self.req.canContinue = True
else:
self.req = pyfile.m.core.requestFactory.getRequest(self.__name__)
@@ -104,6 +106,8 @@ class Plugin(object):
self.pyfile = pyfile
self.thread = None # holds thread in future
+ self.lastDownload = "" #location where the last call to download was saved
+
self.setup()
def __call__(self):
@@ -120,6 +124,9 @@ class Plugin(object):
if not self.account:
self.req.clearCookies()
+ if self.core.config["proxy"]["activated"]:
+ self.req.add_proxy(None, self.core.config["proxy"]["address"])
+
self.pyfile.setStatus("starting")
return self.process(self.pyfile)
@@ -288,7 +295,8 @@ class Plugin(object):
self.pyfile.size = self.req.dl_size
- if newname:
+ if newname and newname != name:
+ self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname})
name = newname
self.pyfile.name = newname
@@ -304,4 +312,34 @@ class Plugin(object):
except Exception,e:
self.log.warning(_("Setting User and Group failed: %s") % str(e))
- return join(location, name) \ No newline at end of file
+ self.lastDownload = join(location, name)
+ return self.lastDownload
+
+ def checkDownload(self, rules, api_size=0 ,max_size=50000, delete=True):
+ """ checks the content of the last downloaded file
+ rules - dict with names and rules to match(re or strings)
+ size - excpected size
+ @return name of first rule matched or None"""
+
+ if not exists(self.lastDownload): return None
+
+ size = stat(self.lastDownload)
+ size = size.st_size
+
+ if api_size and api_size <= size: return None
+ elif size > max_size: return None
+
+ f = open(self.lastDownload, "rb")
+ content = f.read()
+ f.close()
+ for name, rule in rules.iteritems():
+ if type(rule) in (str, unicode):
+ if rule in content:
+ if delete:
+ remove(self.lastDownload)
+ return name
+ elif hasattr(rule, "match"):
+ if rule.match(content):
+ if delete:
+ remove(self.lastDownload)
+ return name