summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-07-30 21:35:29 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-07-30 21:35:29 +0200
commit2497c100de34c113304227f72015bfb3755854a3 (patch)
treee382f92368a37d623f5aea5d02609a13a1c338d8 /module/plugins
parentrestart working and client information (diff)
downloadpyload-2497c100de34c113304227f72015bfb3755854a3.tar.xz
daily commit
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Hook.py3
-rw-r--r--module/plugins/Hoster.py31
-rw-r--r--module/plugins/Plugin.py180
-rw-r--r--module/plugins/hooks/ExternalScripts.py42
-rw-r--r--module/plugins/hoster/BasePlugin.py7
5 files changed, 132 insertions, 131 deletions
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index ed62cbdb2..a928d7173 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -24,6 +24,8 @@ class Hook():
__name__ = "Hook"
__version__ = "0.2"
__type__ = "hook"
+ __threaded__ = []
+ __config__ = []
__description__ = """interface for hook"""
__author_name__ = ("mkaay", "RaNaN")
__author_mail__ = ("mkaay@mkaay.de", "RaNaN@pyload.org")
@@ -31,6 +33,7 @@ class Hook():
def __init__(self, core):
self.core = core
self.log = core.log
+ self.config = core.config
self.setup()
diff --git a/module/plugins/Hoster.py b/module/plugins/Hoster.py
index 75f925587..16c018a99 100644
--- a/module/plugins/Hoster.py
+++ b/module/plugins/Hoster.py
@@ -27,35 +27,4 @@ class Hoster(Plugin):
__description__ = """Base hoster plugin"""
__author_name__ = ("mkaay")
__author_mail__ = ("mkaay@mkaay.de")
-
- def preparePlugin(self, thread):
- self.thread = thread
- self.usePremium = False
-
- def getFileName(self):
- try:
- return re.findall("([^\/=]+)", self.pyfile.url)[-1]
- except:
- return self.pyfile.url[:20]
-
- def isOnline(self):
- return True
-
- def multiDownload(self):
- return True
-
- def prepareDownload(self):
- pass
-
- def startDownload(self):
- self.req.download(self.pyfile.url, self.pyfile.folder)
-
- def verifyDownload(self):
- return True
-
- def wait(self, until=None, reconnect=False):
- self.pyfile.status.want_reconnect = reconnect
- self.pyfile.status.waituntil = until
- if not until:
- self.pyfile.status.waituntil = 0
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index e8df540a8..d8d8aae3c 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -13,7 +13,7 @@
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: RaNaN, spoob, mkaay
"""
@@ -29,23 +29,26 @@ from os.path import exists
from os import makedirs
+from tempfile import NamedTemporaryFile
+from mimetypes import guess_type
+
def dec(func):
def new(*args):
- if args[0].pyfile.abort:
- raise Abort
- return func(*args)
+ if args[0].pyfile.abort:
+ raise Abort
+ return func(*args)
return new
class Abort(Exception):
""" raised when aborted """
-
+
class Fail(Exception):
""" raised when failed """
-
+
class Reconnect(Exception):
""" raised when reconnected """
-
+
class Retry(Exception):
""" raised when start again from beginning """
@@ -57,63 +60,64 @@ class Plugin(object):
__description__ = """Base Plugin"""
__author_name__ = ("RaNaN", "spoob", "mkaay")
__author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "mkaay@mkaay.de")
-
+
def __new__(cls, *args, **kws):
- for f in dir(cls):
- if not f.startswith("_") and f not in ("checksum"):
- setattr(cls, f, dec(getattr(cls, f)) )
-
+ for f in dir(cls):
+ if not f.startswith("_") and f not in ("checksum"):
+ setattr(cls, f, dec(getattr(cls, f)) )
+
o = super(cls.__class__, cls).__new__(cls)
- #wrap decorator around every method
- return o
-
+ #wrap decorator around every method
+ return o
+
def __init__(self, pyfile):
self.config = pyfile.m.core.config
-
+ self.core = pyfile.m.core
+
self.req = pyfile.m.core.requestFactory.getRequest(self.__name__)
-
+
self.wantReconnect = False
self.multiDL = True
-
+
self.waitUntil = 0 # time() + wait in seconds
self.premium = False
-
+
self.ocr = None # captcha reader instance
self.account = pyfile.m.core.accountManager.getAccount(self.__name__) # account handler instance
- self.req = pyfile.m.core.requestFactory.getRequest(self.__name__, self.account)
-
+ self.req = pyfile.m.core.requestFactory.getRequest(self.__name__, self.account)
+
self.log = logging.getLogger("log")
-
+
self.pyfile = pyfile
self.thread = None # holds thread in future
-
- self.setup()
-
+
+ self.setup()
+
def __call__(self):
- return self.__name__
-
+ return self.__name__
+
def setup(self):
- """ more init stuff if needed """
- pass
-
+ """ more init stuff if needed """
+ pass
+
def preprocessing(self, thread):
""" handles important things to do before starting """
self.thread = thread
-
- if not self.account:
- self.req.clearCookies()
-
- self.pyfile.setStatus("starting")
-
+
+ if not self.account:
+ self.req.clearCookies()
+
+ self.pyfile.setStatus("starting")
+
return self.process(self.pyfile)
#----------------------------------------------------------------------
def process(self, pyfile):
"""the 'main' method of every plugin"""
raise NotImplementedError
-
-
+
+
def checksum(self, local_file=None):
"""
return codes:
@@ -124,9 +128,9 @@ class Plugin(object):
20 - unknown error
"""
#@TODO checksum check hook
-
+
return (True, 10)
-
+
def setConf(self, option, value):
""" sets a config value """
@@ -139,65 +143,83 @@ class Plugin(object):
def getConf(self, option):
""" gets a config value """
return self.config.getPlugin(self.__name__, option)
-
-
+
+
def setWait(self, seconds):
""" set the wait time to specified seconds """
- self.waitUntil = time() + int(seconds)
+ self.pyfile.waitUntil = time() + int(seconds)
def wait():
""" waits the time previously set """
pass
-
+
def fail(self, reason):
""" fail and give reason """
raise Fail(reason)
-
+
def offline(self):
- """ fail and indicate file is offline """
- raise Fail("offline")
-
+ """ fail and indicate file is offline """
+ raise Fail("offline")
+
def retry(self):
""" begin again from the beginning """
raise Retry
-
- def askCaptcha(self, url):
+
+ def decryptCaptcha(self, url, get={}, post={}):
""" loads the catpcha and decrypt it or ask the user for input """
- pass
-
- def waitForCaptcha(self, captchaData, imgType):
- captchaManager = self.parent.core.captchaManager
- task = captchaManager.newTask(self)
- task.setCaptcha(captchaData, imgType)
- task.setWaiting()
- while not task.getStatus() == "done":
- if not self.parent.core.isGUIConnected():
- task.removeTask()
- raise CaptchaError
- sleep(1)
- result = task.getResult()
- task.removeTask()
+
+ content = self.load(url, get, post)
+
+ temp = NamedTemporaryFile()
+
+ f = temp.file
+ f.write(content)
+ #f.close()
+
+
+
+ ocr = self.core.pluginManager.getCaptchaPlugin(self.__name__)
+ if ocr:
+ #@TODO decrypt
+ result = ""
+ else:
+ captchaManager = self.core.captchaManager
+ mime = guess_type(temp.name)
+ task = captchaManager.newTask(self)
+ task.setCaptcha(content, mime[0])
+ task.setWaiting()
+ while not task.getStatus() == "done":
+ if not self.core.isClientConnected():
+ task.removeTask()
+ #temp.unlink(temp.name)
+ self.fail(_("No Client connected for captcha decrypting."))
+ sleep(1)
+ result = task.getResult()
+ task.removeTask()
+
+ #temp.unlink(temp.name)
return result
+
def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False):
""" returns the content loaded """
return self.req.load(url, get, post, ref, cookies, just_header)
-
+
def download(self, url, get={}, post={}, ref=True, cookies=True):
""" downloads the url content to disk """
-
- self.pyfile.setStatus("downloading")
-
+
+ self.pyfile.setStatus("downloading")
+
download_folder = self.config['general']['download_folder']
-
- location = join(download_folder, self.pyfile.package().folder.decode(sys.getfilesystemencoding()))
-
- if not exists(location):
- makedirs(location)
-
- newname = self.req.download(url, self.pyfile.name, location, get, post, ref, cookies)
-
- self.pyfile.size = self.req.dl_size
-
+
+ location = join(download_folder, self.pyfile.package().folder.decode(sys.getfilesystemencoding()))
+
+ if not exists(location):
+ makedirs(location)
+
+ newname = self.req.download(url, self.pyfile.name, location, get, post, ref, cookies)
+
+ self.pyfile.size = self.req.dl_size
+
if newname:
- self.pyfile.name = newname
+ self.pyfile.name = newname
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py
index 9e4af1f3b..c4bc76c82 100644
--- a/module/plugins/hooks/ExternalScripts.py
+++ b/module/plugins/hooks/ExternalScripts.py
@@ -13,7 +13,7 @@
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: mkaay
@interface-version: 0.1
"""
@@ -30,22 +30,22 @@ class ExternalScripts(Hook):
__description__ = """run external scripts"""
__author_name__ = ("mkaay", "RaNaN", "spoob")
__author_mail__ = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org")
-
+
def __init__(self, core):
Hook.__init__(self, core)
self.scripts = {}
-
- script_folders = [join(core.path, 'scripts','download_preparing'),
- join(core.path,'scripts','download_finished'),
- join(core.path,'scripts','package_finished'),
- join(core.path,'scripts','before_reconnect'),
- join(core.path,'scripts','after_reconnect')]
- folder = core.make_path("scripts")
+ script_folders = [join(pypath, 'scripts','download_preparing'),
+ join(pypath,'scripts','download_finished'),
+ join(pypath,'scripts','package_finished'),
+ join(pypath,'scripts','before_reconnect'),
+ join(pypath,'scripts','after_reconnect')]
+
+ folder = core.path("scripts")
self.core.check_file(folder, _("folders for scripts"), True)
self.core.check_file(script_folders, _("folders for scripts"), True)
-
+
f = lambda x: False if x.startswith("#") or x.endswith("~") else True
self.scripts = {}
@@ -58,28 +58,28 @@ class ExternalScripts(Hook):
for script_type, script_name in self.scripts.iteritems():
if script_name != []:
- self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name)))
+ self.log.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name)))
#~ self.core.logger.info("Installed Scripts: %s" % str(self.scripts))
self.folder = folder
-
+
def downloadStarts(self, pyfile):
- for script in self.scripts['download_preparing']:
+ for script in self.scripts['download_preparing']:
try:
out = subprocess.Popen([join(self.folder, 'download_preparing', script), pyfile.plugin.props['name'], pyfile.url], stdout=subprocess.PIPE)
out.wait()
except:
pass
-
+
def downloadFinished(self, pyfile):
for script in self.scripts['download_finished']:
try:
- out = subprocess.Popen([join(self.folder, 'download_finished', script), pyfile.plugin.props['name'], pyfile.url, pyfile.status.filename, \
- join(self.core.path,self.core.config['general']['download_folder'], pyfile.folder, pyfile.status.filename)], stdout=subprocess.PIPE)
- except:
- pass
-
+ out = subprocess.Popen([join(self.folder, 'download_finished', script), pyfile.plugin.__name__, pyfile.url, pyfile.name, \
+ join(self.core.config['general']['download_folder'], pyfile.package().folder, pyfile.name)], stdout=subprocess.PIPE)
+ except Exception, e:
+ print e
+
def packageFinished(self, pypack):
for script in self.scripts['package_finished']:
folder = self.core.config['general']['download_folder']
@@ -90,7 +90,7 @@ class ExternalScripts(Hook):
out = subprocess.Popen([join(self.folder, 'package_finished', script), pypack.data['package_name'], folder], stdout=subprocess.PIPE)
except:
pass
-
+
def beforeReconnecting(self, ip):
for script in self.scripts['before_reconnect']:
try:
@@ -98,7 +98,7 @@ class ExternalScripts(Hook):
out.wait()
except:
pass
-
+
def afterReconnecting(self, ip):
for script in self.scripts['after_reconnect']:
try:
diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py
index 09545d493..b64e826f8 100644
--- a/module/plugins/hoster/BasePlugin.py
+++ b/module/plugins/hoster/BasePlugin.py
@@ -16,6 +16,13 @@ class BasePlugin(Hoster):
def process(self, pyfile):
"""main function"""
+ #debug stuff
+
+ res = self.decryptCaptcha("http://www.google.com/recaptcha/api/image?c=03AHJ_VusNo91yuOYR22VR2J2XUl4x8fqcKbKato005zKhc10DT8FmIP4WQwK_5QkJZVRdCNWDPSlASuS12Y30qMjBguJpYA9fztHKFE8Lp2FGOrl6EnMcgTeyx_6FuVpMstX_XRuhusH-Z6H3Tchsj077ptyDMOPFrg")
+ print res
+
+ #end
+
if pyfile.url.startswith("http://"):
pyfile.name = re.findall("([^\/=]+)", pyfile.url)[-1]