diff options
author | mkaay <mkaay@mkaay.de> | 2010-05-07 15:39:28 +0200 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-05-07 15:39:28 +0200 |
commit | f5a65922f5272c8cb5630d462725534e7d72d7db (patch) | |
tree | d7b4c01cea505911531b5ac944d7483441a0b797 | |
parent | modified hookmanager (diff) | |
download | pyload-f5a65922f5272c8cb5630d462725534e7d72d7db.tar.xz |
better cookie handling, rapidshare fix
-rw-r--r-- | module/RequestFactory.py | 47 | ||||
-rwxr-xr-x | module/network/Request.py | 32 | ||||
-rw-r--r-- | module/plugins/accounts/RapidshareCom.py | 6 | ||||
-rw-r--r-- | module/plugins/hoster/RapidshareCom.py | 6 |
4 files changed, 39 insertions, 52 deletions
diff --git a/module/RequestFactory.py b/module/RequestFactory.py index 803e12814..37796be6c 100644 --- a/module/RequestFactory.py +++ b/module/RequestFactory.py @@ -19,7 +19,6 @@ from threading import Lock from module.network.Request import Request -from tempfile import NamedTemporaryFile import pycurl class RequestFactory(): @@ -27,28 +26,13 @@ class RequestFactory(): self.lock = Lock() self.core = core self.requests = [] - self.cookiejars = {} + self.cookiejars = [] def getRequest(self, pluginName, account=None): self.lock.acquire() - cookieFile = None - for req in self.requests: - if req[0:2] == (pluginName, account): - cookieFile = req[2].cookieFile - break - - if not cookieFile: - name = pluginName - if account: - name += "_" - name += account - th = NamedTemporaryFile(mode="w", prefix="pyload_cookies_%s" % name, delete=False) - cookieFile = th.name - th.close() - - req = Request(str(cookieFile)) - s = self.getCookieJar(str(cookieFile)) - req.setCookieJar(s) + req = Request() + cj = self.getCookieJar(pluginName, account) + req.setCookieJar(cj) self.requests.append((pluginName, account, req)) self.lock.release() return req @@ -59,16 +43,19 @@ class RequestFactory(): req[2].clean() self.lock.release() - def getCookieJar(self, cookieFile): - if self.cookiejars.has_key(cookieFile): - return self.cookiejars[cookieFile] - j = CookieJar() - self.cookiejars[cookieFile] = j - return j + def getCookieJar(self, plugin, account=None): + for cj in self.cookiejars: + if (cj.plugin, cj.account) == (plugin, account): + return cj + cj = CookieJar(plugin, account) + self.cookiejars.append(cj) + return cj class CookieJar(): - def __init__(self): + def __init__(self, plugin, account=None): self.cookies = {} + self.plugin = plugin + self.account = account def addCookies(self, clist): for c in clist: @@ -77,3 +64,9 @@ class CookieJar(): def getCookies(self): return self.cookies.values() + + def parseCookie(self, name): + return self.cookies[name].split("\t")[6] + + def getCookie(self, name): + return self.parseCookie(name) diff --git a/module/network/Request.py b/module/network/Request.py index b66dd8a0f..a1d1f91c9 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -27,14 +27,12 @@ from os.path import exists import urllib from cStringIO import StringIO import pycurl -from tempfile import NamedTemporaryFile -from os import remove class AbortDownload(Exception): pass class Request: - def __init__(self, cookieFile=None): + def __init__(self): self.dl_time = 0 self.dl_finished = 0 @@ -65,12 +63,6 @@ class Request: self.speedLimitActive = False self.maxSpeed = 0 self.isSlow = False - - if not cookieFile: - th = NamedTemporaryFile(mode="w", prefix="pyload_cookies", delete=False) - cookieFile = th.name - th.close() - self.cookieFile = cookieFile self.cookieJar = None self.init_curl() @@ -107,13 +99,21 @@ class Request: self.cookieJar = j def addCookies(self): - #self.cookieJar.addCookies(self.pycurl.getinfo(pycurl.INFO_COOKIELIST)) + if self.cookieJar: + self.cookieJar.addCookies(self.pycurl.getinfo(pycurl.INFO_COOKIELIST)) return def getCookies(self): - #self.pycurl.setopt(pycurl.COOKIELIST, self.cookieJar.getCookies()) + if self.cookieJar: + for c in self.cookieJar.getCookies(): + self.pycurl.setopt(pycurl.COOKIELIST, c) return + def getCookie(self, name): + if self.cookieJar: + return self.cookieJar.getCookie(name) + return None + def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False): url = str(url) @@ -154,7 +154,6 @@ class Request: self.pycurl.perform() self.lastEffectiveURL = self.pycurl.getinfo(pycurl.EFFECTIVE_URL) - self.pycurl.setopt(pycurl.COOKIELIST, "FLUSH") self.addCookies() self.lastURL = url @@ -163,8 +162,8 @@ class Request: return self.get_rep() def curl_enable_cookies(self): - self.pycurl.setopt(pycurl.COOKIEFILE, self.cookieFile) - self.pycurl.setopt(pycurl.COOKIEJAR, self.cookieFile) + self.pycurl.setopt(pycurl.COOKIEFILE, "") + self.pycurl.setopt(pycurl.COOKIEJAR, "") def add_auth(self, user, pw): @@ -282,7 +281,6 @@ class Request: if not code == 23: raise Exception, e - self.pycurl.setopt(pycurl.COOKIELIST, "FLUSH") self.addCookies() self.fp.close() @@ -370,10 +368,6 @@ class Request: self.pycurl.close() except: pass - try: - remove(self.cookieFile) - except: - pass def getURL(url): """ diff --git a/module/plugins/accounts/RapidshareCom.py b/module/plugins/accounts/RapidshareCom.py index bd1b944b3..f18fadd15 100644 --- a/module/plugins/accounts/RapidshareCom.py +++ b/module/plugins/accounts/RapidshareCom.py @@ -33,6 +33,6 @@ class RapidshareCom(Account): def login(self): for account in self.accounts: req = self.core.requestFactory.getRequest(self.__name__, account[0]) - html = req.load("http://ssl.rapidshare.com/cgi-bin/premiumzone.cgi", get={"login":account[0], "password":account[1]}, cookies=True) - with open("dump%s.html" % account[0], "w") as f: - f.write(html) + html = req.load("https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi", post={"login":account[0], "password":account[1], "uselandingpage":1}, cookies=True) + + diff --git a/module/plugins/hoster/RapidshareCom.py b/module/plugins/hoster/RapidshareCom.py index da38d4b3a..6f7283d2f 100644 --- a/module/plugins/hoster/RapidshareCom.py +++ b/module/plugins/hoster/RapidshareCom.py @@ -178,9 +178,9 @@ class RapidshareCom(Hoster): return self.url.split("/")[-1] def proceed(self, url, location): - #if self.config['premium']: - # data = self.account.getAccountData(self) - # self.req.add_auth(data[0], data[1]) + if self.config['premium']: + data = self.account.getAccountData(self) + self.req.add_auth(data[0], data[1]) self.download(url, location, cookies=True) def check_file(self, local_file): |