summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Account.py23
-rw-r--r--module/plugins/Plugin.py12
-rw-r--r--module/plugins/accounts/UploadedTo.py18
-rw-r--r--module/plugins/hoster/UploadedTo.py51
4 files changed, 53 insertions, 51 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py
index 91636bc5d..af1c4a383 100644
--- a/module/plugins/Account.py
+++ b/module/plugins/Account.py
@@ -17,12 +17,12 @@
@author: mkaay
"""
-from random import choice
+from random import randrange
import re
class Account():
__name__ = "Account"
- __version__ = "0.1"
+ __version__ = "0.2"
__type__ = "account"
__description__ = """Account Plugin"""
__author_name__ = ("mkaay")
@@ -31,16 +31,18 @@ class Account():
def __init__(self, manager, accounts):
self.manager = manager
self.core = manager.core
- self.accounts = accounts
+ self.accounts = {}
+ self.register = {}
+ self.setAccounts(accounts)
def login(self):
pass
def setAccounts(self, accounts):
- #@TODO improve
self.accounts = accounts
+ self.login()
- def getAccountInfo(self, namepass):
+ def getAccountInfo(self, name):
return {
"validuntil": None,
"login": name,
@@ -52,19 +54,24 @@ class Account():
pass
def getAccountRequest(self, plugin):
- account = self.getAccountData(plugin)
- req = self.core.requestFactory.getRequest(self.__name__, account[0])
+ user, data = self.getAccountData(plugin)
+ req = self.core.requestFactory.getRequest(self.__name__, user)
return req
def getAccountData(self, plugin):
if not len(self.accounts):
return None
if not self.register.has_key(plugin):
- account = self.accounts[randrange(0, len(self.accounts), 1)]
+ account = self.selectAccount(plugin)
+ self.register[plugin] = account
else:
account = self.register[plugin]
return account
+ def selectAccount(self, plugin):
+ account = self.accounts.items()[randrange(0, len(self.accounts), 1)]
+ return account
+
def parseTraffic(self, string): #returns kbyte
string = string.strip().lower()
p = re.compile(r"(\d+[\.,]\d+)(.*)")
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 29fdebde8..a6ea7dee7 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -81,7 +81,10 @@ class Plugin(object):
self.ocr = None # captcha reader instance
self.account = pyfile.m.core.accountManager.getAccountPlugin(self.__name__) # account handler instance
- self.req = pyfile.m.core.requestFactory.getRequest(self.__name__, self.account)
+ if self.account:
+ self.req = self.account.getAccountRequest(self)
+ else:
+ self.req = pyfile.m.core.requestFactory.getRequest(self.__name__)
self.log = logging.getLogger("log")
@@ -112,8 +115,11 @@ class Plugin(object):
def process(self, pyfile):
"""the 'main' method of every plugin"""
raise NotImplementedError
-
-
+
+ def resetAccount(self):
+ self.account = None
+ self.req = self.core.requestFactory.getRequest(self.__name__)
+
def checksum(self, local_file=None):
"""
return codes:
diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py
index a56082657..9521f2577 100644
--- a/module/plugins/accounts/UploadedTo.py
+++ b/module/plugins/accounts/UploadedTo.py
@@ -29,22 +29,22 @@ class UploadedTo(Account):
__author_name__ = ("mkaay")
__author_mail__ = ("mkaay@mkaay.de")
- def getAccountInfo(self, name):
- req = self.core.requestFactory.getRequest(self.__name__, name)
+ def getAccountInfo(self, user):
data = None
- for account in self.accounts:
- if account[0] == name:
- data = account
+ for account in self.accounts.items():
+ if account[0] == user:
+ data = account[1]
if not data:
return
+ req = self.core.requestFactory.getRequest(self.__name__, user)
html = req.load("http://uploaded.to/", cookies=True)
raw_traffic = re.search(r"Traffic left: </span><span class=.*?>(.*?)</span>", html).group(1)
raw_valid = re.search(r"Valid until: </span> <span class=.*?>(.*?)</span>", html).group(1)
traffic = int(self.parseTraffic(raw_traffic))
validuntil = int(mktime(strptime(raw_valid.strip(), "%d-%m-%Y %H:%M")))
- return {"login":name, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__}
+ return {"login":user, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__}
def login(self):
- for account in self.accounts:
- req = self.core.requestFactory.getRequest(self.__name__, account[0])
- req.load("http://uploaded.to/login", None, { "email" : account[0], "password" : account[1]}, cookies=True)
+ for user, data in self.accounts.items():
+ req = self.core.requestFactory.getRequest(self.__name__, user)
+ req.load("http://uploaded.to/login", None, { "email" : user, "password" : data["password"]}, cookies=True)
diff --git a/module/plugins/hoster/UploadedTo.py b/module/plugins/hoster/UploadedTo.py
index 2fefe5bcf..573119680 100644
--- a/module/plugins/hoster/UploadedTo.py
+++ b/module/plugins/hoster/UploadedTo.py
@@ -19,17 +19,9 @@ class UploadedTo(Hoster):
self.html = None
self.api_data = None
self.multiDL = False
- # self.usePremium = self.config['premium']
- # if self.usePremium:
- # self.account = self.parent.core.pluginManager.getAccountPlugin(self.__name__)
- # req = self.account.getAccountRequest(self)
- # if req:
- # self.req = req
- # self.multi_dl = True
- # self.req.canContinue = True
- # else:
- # self.usePremium = False
-
+ if self.account:
+ self.multiDL = True
+ self.req.canContinue = True
def process(self, pyfile):
self.url = False
@@ -51,15 +43,16 @@ class UploadedTo(Hoster):
# self.pyfile.name = self.get_file_name()
- # if self.usePremium:
- # info = self.account.getAccountInfo(self.account.getAccountData(self)[0])
- # self.logger.info(_("%s: Use Premium Account (%sGB left)") % (self.__name__, info["trafficleft"]/1024/1024))
- # if self.api_data["size"]/1024 > info["trafficleft"]:
- # self.logger.info(_("%s: Not enough traffic left" % self.__name__))
- # self.usePremium = False
- # else:
- # self.pyfile.status.url = self.parent.url
- # return True
+ if self.account:
+ info = self.account.getAccountInfo(self.account.getAccountData(self)[0])
+ self.log.debug(_("%s: Use Premium Account (%sGB left)") % (self.__name__, info["trafficleft"]/1024/1024))
+ if self.api_data["size"]/1024 > info["trafficleft"]:
+ self.log.info(_("%s: Not enough traffic left" % self.__name__))
+ self.resetAcount()
+ else:
+ self.url = self.get_file_url()
+ self.pyfile.name = self.get_file_name()
+ return True
self.url = self.get_file_url()
@@ -98,9 +91,9 @@ class UploadedTo(Hoster):
return 0
def get_file_url(self):
- # if self.usePremium:
- # self.start_dl = True
- # return self.url
+ if self.account:
+ self.start_dl = True
+ return self.cleanUrl(self.pyfile.url)
try:
file_url_pattern = r".*<form name=\"download_form\" method=\"post\" action=\"(.*)\">"
return re.search(file_url_pattern, self.html).group(1)
@@ -133,11 +126,7 @@ class UploadedTo(Hoster):
return url
def proceed(self):
- # if self.usePremium:
- # self.load(url, cookies=True, just_header=True)
- # if self.cleanUrl(self.req.lastEffectiveURL) == self.cleanUrl(url):
- # self.logger.info(_("UploadedTo indirect download"))
- # url = self.cleanUrl(url)+"?redirect"
- # self.download(url, location, cookies=True)
- # else:
- self.download(self.url, cookies=False, post={"download_submit": "Free Download"})
+ if self.account:
+ self.download(self.url+"?redirect", cookies=True)
+ else:
+ self.download(self.url, cookies=False, post={"download_submit": "Free Download"})