summaryrefslogtreecommitdiffstats
path: root/module
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
parentclosed #486 (diff)
downloadpyload-1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6.tar.xz
MultiHoster plugin type, some fixes, new documentation structure
Diffstat (limited to 'module')
-rw-r--r--module/HookManager.py2
-rw-r--r--module/network/HTTPDownload.py6
-rw-r--r--module/network/HTTPRequest.py2
-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
-rw-r--r--module/remote/thriftbackend/pyload.thrift5
-rw-r--r--module/threads/DecrypterThread.py2
10 files changed, 87 insertions, 25 deletions
diff --git a/module/HookManager.py b/module/HookManager.py
index d0ceb89b2..51bc706ca 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -63,7 +63,7 @@ class HookManager:
func = getattr(hook, f)
return func(*args)
except Exception, e:
- plugin.logError(_("Error executing %s" % event), e)
+ hook.logError(_("Error when executing %s" % f), e)
if self.core.debug:
print_exc()
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index fe8075539..0d5fc59c9 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -17,9 +17,9 @@
@author: RaNaN
"""
-from os import remove, fsync
+from os import remove
from os.path import dirname
-from time import sleep, time
+from time import time
from shutil import move
from logging import getLogger
@@ -28,7 +28,7 @@ import pycurl
from HTTPChunk import ChunkInfo, HTTPChunk
from HTTPRequest import BadHeader
-from module.plugins.Plugin import Abort
+from module.plugins.Hoster import Abort
from module.utils import save_join, fs_encode
class HTTPDownload():
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index d4c33bbff..cd13dd01f 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -25,7 +25,7 @@ from httplib import responses
from logging import getLogger
from cStringIO import StringIO
-from module.plugins.Plugin import Abort
+from module.plugins.Hoster import Abort
def myquote(url):
return quote(url.encode('utf_8') if isinstance(url, unicode) else url, safe="%/:=&?~#+!$,;'@()*[]")
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:
diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift
index d33b468c3..98e678c8e 100644
--- a/module/remote/thriftbackend/pyload.thrift
+++ b/module/remote/thriftbackend/pyload.thrift
@@ -2,7 +2,6 @@ namespace java org.pyload.thrift
typedef i32 FileID
typedef i32 PackageID
-typedef i32 TaskID
typedef i32 ResultID
typedef i32 InteractionID
typedef list<string> LinkList
@@ -334,6 +333,6 @@ service Pyload {
//captcha
bool isCaptchaWaiting(),
CaptchaTask getCaptchaTask(1: bool exclusive),
- string getCaptchaTaskStatus(1: TaskID tid),
- void setCaptchaResult(1: TaskID tid, 2: string result),
+ string getCaptchaTaskStatus(1: InteractionID tid),
+ void setCaptchaResult(1: InteractionID tid, 2: string result),
}
diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py
index 8edb97c34..ce3c8cd83 100644
--- a/module/threads/DecrypterThread.py
+++ b/module/threads/DecrypterThread.py
@@ -72,7 +72,7 @@ class DecrypterThread(BaseThread):
self.log.info(_("Decrypted %(count)d links into package %(name)s") % {"count": len(urls), "name": pack.name})
self.m.core.api.addFiles(self.pid, urls)
- for p in pack_names:
+ for p in pack_names.itervalues():
self.m.core.api.addPackage(p.name, p.urls, p.dest, pack.password)
if not result: