summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-12-22 13:45:30 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-12-22 13:45:30 +0100
commitdde6a329fdaa5dca48080770dee82cb51cf12585 (patch)
treed665099c49a0ef1f5c09a9d2f8b19ba09f531437 /module
parentat least its downloading now (diff)
downloadpyload-dde6a329fdaa5dca48080770dee82cb51cf12585.tar.xz
refactoring part 1: deprecation warnings, reduced debug, cookie compatibility
Diffstat (limited to 'module')
-rw-r--r--module/RequestFactory.py36
-rw-r--r--module/network/Browser.py40
-rw-r--r--module/network/HTTPBase.py4
-rw-r--r--module/plugins/Account.py4
-rw-r--r--module/plugins/accounts/DepositfilesCom.py6
-rw-r--r--module/plugins/accounts/FileserveCom.py6
-rw-r--r--module/plugins/accounts/FreakshareCom.py4
-rw-r--r--module/plugins/accounts/HotfileCom.py8
-rw-r--r--module/plugins/accounts/MegauploadCom.py6
-rw-r--r--module/plugins/accounts/NetloadIn.py4
-rw-r--r--module/plugins/accounts/RapidshareCom.py4
-rw-r--r--module/plugins/accounts/ShareonlineBiz.py4
-rw-r--r--module/plugins/accounts/UploadedTo.py4
13 files changed, 67 insertions, 63 deletions
diff --git a/module/RequestFactory.py b/module/RequestFactory.py
index 8bd27a275..5eaa32ed9 100644
--- a/module/RequestFactory.py
+++ b/module/RequestFactory.py
@@ -23,6 +23,8 @@ from module.network.Browser import Browser
from module.network.XdccRequest import XdccRequest
from module.network.FtpRequest import FtpRequest
from time import time
+from cookielib import CookieJar
+from cookielib import Cookie
class RequestFactory():
def __init__(self, core):
@@ -40,7 +42,7 @@ class RequestFactory():
cj = self.getCookieJar(pluginName, account)
req.setCookieJar(cj)
else:
- req.setCookieJar(CookieJar(pluginName))
+ req.setCookieJar(PyLoadCookieJar(pluginName))
elif type == "XDCC":
req = XdccRequest()
@@ -62,12 +64,13 @@ class RequestFactory():
for cj in self.cookiejars:
if (cj.plugin, cj.account) == (plugin, account):
return cj
- cj = CookieJar(plugin, account)
+ cj = PyLoadCookieJar(plugin, account)
self.cookiejars.append(cj)
return cj
-class CookieJar():
+class PyLoadCookieJar(CookieJar):
def __init__(self, plugin, account=None):
+ CookieJar.__init__(self)
self.cookies = {}
self.plugin = plugin
self.account = account
@@ -78,23 +81,14 @@ class CookieJar():
if hasattr(self, "plugin"):
del self.plugin
- def addCookies(self, clist):
- for c in clist:
- name = c.split("\t")[5]
- self.cookies[name] = c
-
- def getCookies(self):
- return self.cookies.values()
-
- def parseCookie(self, name):
- if self.cookies.has_key(name):
- return self.cookies[name].split("\t")[6]
- else:
- return None
-
def getCookie(self, name):
- return self.parseCookie(name)
+ print "getCookie not implemented!"
+ return None
- def setCookie(self, domain, name, value, path="/", exp=time()+3600*24*180):
- s = ".%s TRUE %s FALSE %s %s %s" % (domain, path, exp, name, value)
- self.cookies[name] = s
+ def setCookie(self, domain, name, value, path="/"):
+ c = Cookie(version=0, name=name, value=value, port=None, port_specified=False,
+ domain=domain, domain_specified=False,
+ domain_initial_dot=(domain.startswith(".")), path=path, path_specified=True,
+ secure=False, expires=None, discard=True, comment=None,
+ comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
+ self.set_cookie(c)
diff --git a/module/network/Browser.py b/module/network/Browser.py
index 3db2299f0..df0f24b4d 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -10,13 +10,14 @@ from HTTPDownload import HTTPDownload
from FTPBase import FTPDownload
from XDCCBase import XDCCDownload
+from traceback import print_stack
+
class Browser(object):
def __init__(self, interface=None, cookieJar=CookieJar(), bucket=None, proxies={}):
self.log = getLogger("log")
self.lastURL = None
self.interface = interface
- self.cookieJar = cookieJar
self.bucket = bucket
self.http = HTTPBase(interface=interface, proxies=proxies)
@@ -24,10 +25,11 @@ class Browser(object):
self.proxies = proxies
def setCookieJar(self, cookieJar):
- self.http.cookieJar = cookieJar
+ self.cookieJar = cookieJar
+ self.http.cookieJar = self.cookieJar
def clearCookies(self):
- pass #@TODO
+ self.cookieJar.clear()
def clearReferer(self):
self.lastURL = None
@@ -77,15 +79,6 @@ class Browser(object):
pass
return location
- def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False):
- #@TODO
-
- filename = join(folder, file_name)
- d = self.httpDownload(url, filename, get, post)
- waitFor(d)
-
- return filename
-
def httpDownload(self, url, filename, get={}, post={}, referer=None, cookies=True, customHeaders={}, chunks=1,
resume=False):
if not referer:
@@ -112,6 +105,27 @@ class Browser(object):
d = dwnld.download()
return d
+
+ #compatibility wrapper
+ def clean(self):
+ self.log.warning("Browser: deprecated call 'clean'")
+ print_stack()
+
+ def load(self, *args, **kwargs):
+ self.log.warning("Browser: deprecated call 'load'")
+ print_stack()
+ return self.getPage(*args, **kwargs)
+
+ def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False):
+ #@TODO
+ self.log.warning("Browser: deprecated call 'download'")
+ print_stack()
+
+ filename = join(folder, file_name)
+ d = self.httpDownload(url, filename, get, post)
+ waitFor(d)
+
+ return filename
if __name__ == "__main__":
browser = Browser()#proxies={"socks5": "localhost:5000"})
@@ -127,4 +141,4 @@ if __name__ == "__main__":
from time import sleep
while True:
- sleep(1) \ No newline at end of file
+ sleep(1)
diff --git a/module/network/HTTPBase.py b/module/network/HTTPBase.py
index 753c6c0f1..fead2f4ed 100644
--- a/module/network/HTTPBase.py
+++ b/module/network/HTTPBase.py
@@ -49,7 +49,7 @@ import socks
from MultipartPostHandler import MultipartPostHandler
-DEBUG = 1
+DEBUG = 0
HANDLE_ERRORS = 1
class PyLoadHTTPResponse(HTTPResponse):
@@ -293,7 +293,7 @@ class HTTPBase():
self.cookieJar = CookieJar()
- self.debug = True
+ self.debug = DEBUG
def createOpener(self, cookies=True):
opener = OpenerDirector()
diff --git a/module/plugins/Account.py b/module/plugins/Account.py
index 7867ccdcd..0c2bcb770 100644
--- a/module/plugins/Account.py
+++ b/module/plugins/Account.py
@@ -56,8 +56,6 @@ class Account():
data["valid"] = False
if self.core.debug:
print_exc()
- finally:
- req.clean()
def setAccounts(self, accounts):
self.accounts = accounts
@@ -96,8 +94,6 @@ class Account():
raise Exception("Wrong return format")
except Exception, e:
infos = {"error": str(e)}
- finally:
- req.clean()
self.core.log.debug("Account Info: %s" % str(infos))
self.infos[name] = infos
diff --git a/module/plugins/accounts/DepositfilesCom.py b/module/plugins/accounts/DepositfilesCom.py
index b0730de8e..b33083da9 100644
--- a/module/plugins/accounts/DepositfilesCom.py
+++ b/module/plugins/accounts/DepositfilesCom.py
@@ -31,7 +31,7 @@ class DepositfilesCom(Account):
def loadAccountInfo(self, user, req):
- src = req.load("http://depositfiles.com/de/gold/")
+ src = req.getPage("http://depositfiles.com/de/gold/")
validuntil = re.search("noch den Gold-Zugriff: <b>(.*?)</b></div>", src).group(1)
validuntil = int(mktime(strptime(validuntil, "%Y-%m-%d %H:%M:%S")))
@@ -41,7 +41,7 @@ class DepositfilesCom(Account):
def login(self, user, data, req):
- req.load("http://depositfiles.com/de/gold/payment.php")
- src = req.load("http://depositfiles.com/de/login.php", get={"return": "/de/gold/payment.php"}, post={"login": user, "password": data["password"]})
+ req.getPage("http://depositfiles.com/de/gold/payment.php")
+ src = req.getPage("http://depositfiles.com/de/login.php", get={"return": "/de/gold/payment.php"}, post={"login": user, "password": data["password"]})
if r'<div class="error_message">Sie haben eine falsche Benutzername-Passwort-Kombination verwendet.</div>' in src:
self.wrongPassword()
diff --git a/module/plugins/accounts/FileserveCom.py b/module/plugins/accounts/FileserveCom.py
index 7754de253..76fc485ed 100644
--- a/module/plugins/accounts/FileserveCom.py
+++ b/module/plugins/accounts/FileserveCom.py
@@ -31,7 +31,7 @@ class FileserveCom(Account):
def loadAccountInfo(self, user, req):
- src = req.load("http://fileserve.com/dashboard.php", cookies=True)
+ src = req.getPage("http://fileserve.com/dashboard.php", cookies=True)
m = re.search(r"<td><h4>Premium Until</h4></th> <td><h5>(.*?) E(.)T</h5></td>", src)
if m:
@@ -44,12 +44,12 @@ class FileserveCom(Account):
def login(self, user, data, req):
- html = req.load("http://fileserve.com/login.php",
+ html = req.getPage("http://fileserve.com/login.php",
post={"loginUserName": user, "loginUserPassword": data["password"],
"autoLogin": "on", "loginFormSubmit": "Login"}, cookies=True)
if r'Please Enter a valid user name.' in html:
self.wrongPassword()
- req.load("http://fileserve.com/dashboard.php", cookies=True)
+ req.getPage("http://fileserve.com/dashboard.php", cookies=True)
diff --git a/module/plugins/accounts/FreakshareCom.py b/module/plugins/accounts/FreakshareCom.py
index 732f9e203..fcab247cb 100644
--- a/module/plugins/accounts/FreakshareCom.py
+++ b/module/plugins/accounts/FreakshareCom.py
@@ -30,7 +30,7 @@ class FreakshareCom(Account):
__author_mail__ = ("RaNaN@pyload.org")
def loadAccountInfo(self, user, req):
- page = req.load("http://freakshare.com/")
+ page = req.getPage("http://freakshare.com/")
validuntil = r"ltig bis:</td>\s*<td><b>([0-9 \-:.]+)</b></td>"
validuntil = re.search(validuntil, page, re.MULTILINE)
@@ -45,7 +45,7 @@ class FreakshareCom(Account):
return {"validuntil": validuntil, "trafficleft": traffic}
def login(self, user, data, req):
- page = req.load("http://freakshare.com/login.html", None, { "submit" : "Login", "user" : user, "pass" : data['password']}, cookies=True)
+ page = req.getPage("http://freakshare.com/login.html", None, { "submit" : "Login", "user" : user, "pass" : data['password']}, cookies=True)
if "Falsche Logindaten!" in page or "Wrong Username or Password!" in page:
self.wrongPassword()
diff --git a/module/plugins/accounts/HotfileCom.py b/module/plugins/accounts/HotfileCom.py
index a4354eb2e..579267af3 100644
--- a/module/plugins/accounts/HotfileCom.py
+++ b/module/plugins/accounts/HotfileCom.py
@@ -57,7 +57,7 @@ class HotfileCom(Account):
req = self.getAccountRequest(user)
- digest = req.load("http://api.hotfile.com/", post={"action":"getdigest"})
+ digest = req.getPage("http://api.hotfile.com/", post={"action":"getdigest"})
h = hashlib.md5()
h.update(data["password"])
hp = h.hexdigest()
@@ -68,7 +68,7 @@ class HotfileCom(Account):
post.update({"action": method})
post.update({"username":user, "passwordmd5dig":pwhash, "digest":digest})
- resp = req.load("http://api.hotfile.com/", post=post)
+ resp = req.getPage("http://api.hotfile.com/", post=post)
req.clean()
return resp
@@ -76,7 +76,7 @@ class HotfileCom(Account):
cj = self.getAccountCookies(user)
cj.setCookie("hotfile.com", "lang", "en")
req.load("http://hotfile.com/", cookies=True)
- page = req.load("http://hotfile.com/login.php", post={"returnto": "/", "user": user, "pass": data["password"]}, cookies=True)
+ page = req.getPage("http://hotfile.com/login.php", post={"returnto": "/", "user": user, "pass": data["password"]}, cookies=True)
if "Bad username/password" in page:
- self.wrongPassword() \ No newline at end of file
+ self.wrongPassword()
diff --git a/module/plugins/accounts/MegauploadCom.py b/module/plugins/accounts/MegauploadCom.py
index e14cf7a28..d50008b70 100644
--- a/module/plugins/accounts/MegauploadCom.py
+++ b/module/plugins/accounts/MegauploadCom.py
@@ -31,7 +31,7 @@ class MegauploadCom(Account):
__author_mail__ = ("RaNaN@pyload.org")
def loadAccountInfo(self, user, req):
- page = req.load("http://www.megaupload.com/?c=account")
+ page = req.getPage("http://www.megaupload.com/?c=account")
free = re.findall(r"Account type:</TD>\s*<TD><b>Regular</b>",page,re.IGNORECASE+re.MULTILINE)
if free:
@@ -47,6 +47,6 @@ class MegauploadCom(Account):
def login(self, user, data, req):
- page = req.load("http://www.megaupload.com/?c=login&next=c%3Dpremium", post={ "username" : user, "password" : data["password"], "login" :"1"}, cookies=True)
+ page = req.getPage("http://www.megaupload.com/?c=login&next=c%3Dpremium", post={ "username" : user, "password" : data["password"], "login" :"1"}, cookies=True)
if "Username and password do not match" in page:
- self.wrongPassword() \ No newline at end of file
+ self.wrongPassword()
diff --git a/module/plugins/accounts/NetloadIn.py b/module/plugins/accounts/NetloadIn.py
index 4f5b08689..89e4c0037 100644
--- a/module/plugins/accounts/NetloadIn.py
+++ b/module/plugins/accounts/NetloadIn.py
@@ -30,13 +30,13 @@ class NetloadIn(Account):
__author_mail__ = ("RaNaN@pyload.org")
def loadAccountInfo(self, user, req):
- page = req.load("http://netload.in/index.php?id=2")
+ page = req.getPage("http://netload.in/index.php?id=2")
left = r">(\d+) Tage, (\d+) Stunden<"
left = re.search(left, page)
validuntil = time() + int(left.group(1)) * 24 * 60 * 60 + int(left.group(2)) * 60 * 60
return {"validuntil": validuntil, "trafficleft": -1}
def login(self, user, data,req):
- page = req.load("http://netload.in/index.php", None, { "txtuser" : user, "txtpass" : data['password'], "txtcheck" : "login", "txtlogin" : ""}, cookies=True)
+ page = req.getPage("http://netload.in/index.php", None, { "txtuser" : user, "txtpass" : data['password'], "txtcheck" : "login", "txtlogin" : ""}, cookies=True)
if "password or it might be invalid!" in page:
self.wrongPassword()
diff --git a/module/plugins/accounts/RapidshareCom.py b/module/plugins/accounts/RapidshareCom.py
index a2bb30211..e4472a4db 100644
--- a/module/plugins/accounts/RapidshareCom.py
+++ b/module/plugins/accounts/RapidshareCom.py
@@ -31,7 +31,7 @@ class RapidshareCom(Account):
data = self.getAccountData(user)
api_url_base = "http://api.rapidshare.com/cgi-bin/rsapi.cgi"
api_param_prem = {"sub": "getaccountdetails_v1", "type": "prem", "login": user, "password": data["password"], "withcookie": 1}
- src = req.load(api_url_base, cookies=False, get=api_param_prem)
+ src = req.getPage(api_url_base, cookies=False, get=api_param_prem)
if src.startswith("ERROR"):
raise Exception(src)
fields = src.split("\n")
@@ -51,7 +51,7 @@ class RapidshareCom(Account):
def login(self, user, data, req):
api_url_base = "http://api.rapidshare.com/cgi-bin/rsapi.cgi"
api_param_prem = {"sub": "getaccountdetails_v1", "type": "prem", "login": user, "password": data["password"], "withcookie": 1}
- src = req.load(api_url_base, cookies=False, get=api_param_prem)
+ src = req.getPage(api_url_base, cookies=False, get=api_param_prem)
if src.startswith("ERROR"):
raise Exception(src+"### Note you have to use your account number for login, instead of name.")
fields = src.split("\n")
diff --git a/module/plugins/accounts/ShareonlineBiz.py b/module/plugins/accounts/ShareonlineBiz.py
index 3564d489c..e868b65b2 100644
--- a/module/plugins/accounts/ShareonlineBiz.py
+++ b/module/plugins/accounts/ShareonlineBiz.py
@@ -30,7 +30,7 @@ class ShareonlineBiz(Account):
__author_mail__ = ("mkaay@mkaay.de")
def loadAccountInfo(self, user, req):
- src = req.load("http://www.share-online.biz/members.php?setlang=en")
+ src = req.getPage("http://www.share-online.biz/members.php?setlang=en")
validuntil = re.search(r'<td align="left"><b>Package Expire Date:</b></td>\s*<td align="left">(\d+/\d+/\d+)</td>', src).group(1)
validuntil = int(mktime(strptime(validuntil, "%m/%d/%y")))
@@ -47,4 +47,4 @@ class ShareonlineBiz(Account):
"login": "Login"
}
req.lastURL = "http://www.share-online.biz/"
- req.load("https://www.share-online.biz/login.php", cookies=True, post=post_vars)
+ req.getPage("https://www.share-online.biz/login.php", cookies=True, post=post_vars)
diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py
index 2cb447877..fcc2daf22 100644
--- a/module/plugins/accounts/UploadedTo.py
+++ b/module/plugins/accounts/UploadedTo.py
@@ -30,7 +30,7 @@ class UploadedTo(Account):
__author_mail__ = ("mkaay@mkaay.de")
def loadAccountInfo(self, user, req):
- html = req.load("http://uploaded.to/?setlang=en", cookies=True)
+ html = req.getPage("http://uploaded.to/?setlang=en", 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))
@@ -40,6 +40,6 @@ class UploadedTo(Account):
return tmp
def login(self, user, data, req):
- page = req.load("http://uploaded.to/login", post={ "email" : user, "password" : data["password"]}, cookies=True)
+ page = req.getPage("http://uploaded.to/login", post={ "email" : user, "password" : data["password"]}, cookies=True)
if "Login failed!" in page:
self.wrongPassword()