summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-07 20:11:16 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-07 20:11:16 +0100
commit1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6 (patch)
treec09084a44bcde0528db1007c026ef2eb6a349c05 /module/plugins
parentclosed #486 (diff)
downloadpyload-1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6.tar.xz
MultiHoster plugin type, some fixes, new documentation structure
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Account.py3
-rw-r--r--module/plugins/Crypter.py5
-rw-r--r--module/plugins/Hook.py27
-rw-r--r--module/plugins/MultiHoster.py58
-rw-r--r--module/plugins/internal/MultiHoster.py2
5 files changed, 79 insertions, 16 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py
index 59ce87ed2..e5b90d95e 100644
--- a/module/plugins/Account.py
+++ b/module/plugins/Account.py
@@ -4,12 +4,13 @@ from time import time
from traceback import print_exc
from threading import RLock
-from Plugin import Base
from module.utils import compare_time, parseFileSize, lock
from module.config.converter import from_string
from module.Api import AccountInfo
from module.network.CookieJar import CookieJar
+from Base import Base
+
class WrongPassword(Exception):
pass
diff --git a/module/plugins/Crypter.py b/module/plugins/Crypter.py
index 5d164da64..3e423881e 100644
--- a/module/plugins/Crypter.py
+++ b/module/plugins/Crypter.py
@@ -23,7 +23,10 @@ class Package:
return self.name == other.name and self.urls == other.urls
def __repr__(self):
- return "<CrypterPackage name=%s, links=%s, dest=%s" % (self.name, self.urls, self.dest)
+ return u"<CrypterPackage name=%s, links=%s, dest=%s" % (self.name, self.urls, self.dest)
+
+ def __hash__(self):
+ return hash(self.name) ^ hash(frozenset(self.urls)) ^ hash(self.dest)
class PyFileMockup:
""" Legacy class needed by old crypter plugins """
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index 76bc19dbe..c1090aa70 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -136,30 +136,31 @@ class Hook(Base):
""" Used to deactivate the hook. """
pass
- def downloadPreparing(self, pyfile):
+ def periodical(self):
pass
-
- def downloadFinished(self, pyfile):
+
+ def newCaptchaTask(self, task):
+ """ new captcha task for the plugin, it MUST set the handler and timeout or will be ignored """
pass
- def packageFinished(self, pypack):
+ def captchaCorrect(self, task):
pass
- def beforeReconnecting(self, ip):
+ def captchaInvalid(self, task):
pass
-
- def afterReconnecting(self, ip):
+
+ # public events starts from here
+ def downloadPreparing(self, pyfile):
pass
- def periodical(self):
+ def downloadFinished(self, pyfile):
pass
- def newCaptchaTask(self, task):
- """ new captcha task for the plugin, it MUST set the handler and timeout or will be ignored """
+ def packageFinished(self, pypack):
pass
- def captchaCorrect(self, task):
+ def beforeReconnecting(self, ip):
pass
-
- def captchaInvalid(self, task):
+
+ def afterReconnecting(self, ip):
pass \ No newline at end of file
diff --git a/module/plugins/MultiHoster.py b/module/plugins/MultiHoster.py
new file mode 100644
index 000000000..f7e560c10
--- /dev/null
+++ b/module/plugins/MultiHoster.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+from time import time
+
+from Account import Account
+
+#noinspection PyUnresolvedReferences
+class MultiHoster(Account):
+ """
+ Base class for MultiHoster services.
+ This is also an Account instance so you should see :class:`Account` and overwrite necessary methods.
+ Multihoster becomes only active when an Account was entered and the MultiHoster hook was activated.
+ You need to overwrite `loadHosterList` and a corresponding :class:`Hoster` plugin with the same name should
+ be available to make your service working.
+ """
+
+ #: List of hoster names that will be replaced so pyLoad will recognize them: (orig_name, pyload_name)
+ replacements = [("freakshare.net", "freakshare.com")]
+
+ #: Load new hoster list every x seconds
+ hoster_timeout = 300
+
+ def __init__(self, *args, **kwargs):
+
+ # Hoster list
+ self.hoster = []
+ # Timestamp
+ self.ts = 0
+
+ Account.__init__(*args, **kwargs)
+
+ def loadHosterList(self, req):
+ """Load list of supported hoster
+
+ :return: List of domain names
+ """
+ raise NotImplementedError
+
+ def getHosterList(self, force=False):
+ if self.ts + self.hoster_timeout < time() or force:
+ req = self.getAccountRequest()
+ try:
+ self.hoster = self.loadHosterList(req)
+ except Exception, e:
+ self.logError(e)
+ return []
+ finally:
+ req.close()
+
+ for rep in self.replacements:
+ if rep[0] in self.hosters:
+ self.hosters.remove(rep[0])
+ if rep[1] not in self.hosters:
+ self.hosters.append(rep[1])
+
+ self.ts = time()
+
+ return self.hosters \ No newline at end of file
diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py
index 1629fdc5f..2252c4460 100644
--- a/module/plugins/internal/MultiHoster.py
+++ b/module/plugins/internal/MultiHoster.py
@@ -23,7 +23,7 @@ class MultiHoster(Hook):
try:
self.hosters = self.getHoster()
except Exception, e:
- self.logError("%s" % str(e))
+ self.logError(e)
return []
for rep in self.replacements: