summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-08-07 15:45:17 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-08-07 15:45:17 +0200
commit921627014e243fb2dd9b4f9a9dfade26d1e11c12 (patch)
tree2fde2ac7ab11bbca41f2e065095232f46257ab0b
parentfixes, closed #361 (diff)
downloadpyload-921627014e243fb2dd9b4f9a9dfade26d1e11c12.tar.xz
closed #375
-rw-r--r--module/Api.py4
-rw-r--r--module/HookManager.py4
-rw-r--r--module/network/Browser.py1
-rw-r--r--module/network/HTTPRequest.py14
-rw-r--r--module/plugins/accounts/FileserveCom.py118
-rw-r--r--module/plugins/hooks/ExternalScripts.py2
-rw-r--r--module/plugins/hoster/FileserveCom.py12
7 files changed, 122 insertions, 33 deletions
diff --git a/module/Api.py b/module/Api.py
index 18aaf7460..1a69a0a27 100644
--- a/module/Api.py
+++ b/module/Api.py
@@ -59,7 +59,7 @@ class Api(Iface):
item = ConfigItem()
item.name = key
item.description = data["desc"]
- item.value = str(data["value"]) if type(data["value"]) != basestring else data["value"]
+ item.value = str(data["value"]) if not isinstance(data["value"], basestring) else data["value"]
item.type = data["type"]
items.append(item)
section.items = items
@@ -81,7 +81,7 @@ class Api(Iface):
else:
value = self.core.config.getPlugin(category, option)
- return str(value) if type(value) != basestring else value
+ return str(value) if not isinstance(value, basestring) else value
def setConfigValue(self, category, option, value, section="core"):
"""Set new config value.
diff --git a/module/HookManager.py b/module/HookManager.py
index 464f5af99..1adc07117 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -264,14 +264,14 @@ class HookManager:
for name, plugin in self.pluginMap.iteritems():
if plugin.info:
#copy and convert so str
- info[name] = dict([(x, str(y) if type(y) != basestring else y) for x, y in plugin.info.iteritems()])
+ info[name] = dict([(x, str(y) if not isinstance(y, basestring) else y) for x, y in plugin.info.iteritems()])
return info
def getInfo(self, plugin):
info = {}
if plugin in self.pluginMap and self.pluginMap[plugin].info:
- info = dict([(x, str(y) if type(y) != basestring else y)
+ info = dict([(x, str(y) if not isinstance(y, basestring) else y)
for x, y in self.pluginMap[plugin].info.iteritems()])
return info
diff --git a/module/network/Browser.py b/module/network/Browser.py
index 8bcedb773..822e2ed6d 100644
--- a/module/network/Browser.py
+++ b/module/network/Browser.py
@@ -92,7 +92,6 @@ class Browser(object):
""" retrieves page """
return self.http.load(*args, **kwargs)
-
def putHeader(self, name, value):
""" add a header to the request """
self.http.putHeader(name, value)
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index 52c5474ba..315cb7d23 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -30,9 +30,10 @@ def myquote(url):
return quote(url, safe="%/:=&?~#+!$,;'@()*[]")
class BadHeader(Exception):
- def __init__(self, code):
+ def __init__(self, code, content):
Exception.__init__(self, "Bad server response: %s"% code)
self.code = code
+ self.content = content
class HTTPRequest():
@@ -137,7 +138,13 @@ class HTTPRequest():
if post:
self.c.setopt(pycurl.POST, 1)
if not multipart:
- post = urlencode(post)
+ if type(post) == unicode:
+ post = str(post) #unicode not allowed
+ elif type(post) == str:
+ pass
+ else:
+ post = urlencode(post)
+
self.c.setopt(pycurl.POSTFIELDS, post)
else:
post = [(x, str(quote(y)) if type(y) in (str, unicode) else y ) for x,y in post.iteritems()]
@@ -177,6 +184,7 @@ class HTTPRequest():
self.c.perform()
rep = self.getResponse()
+ self.c.setopt(pycurl.POSTFIELDS, "")
self.lastEffectiveURL = self.c.getinfo(pycurl.EFFECTIVE_URL)
self.code = self.verifyHeader()
@@ -192,7 +200,7 @@ class HTTPRequest():
code = int(self.c.getinfo(pycurl.RESPONSE_CODE))
if code in range(400,404) or code in range(405,418) or code in range(500,506):
#404 will NOT raise an exception
- raise BadHeader(code)
+ raise BadHeader(code, self.getResponse())
return code
def getResponse(self):
diff --git a/module/plugins/accounts/FileserveCom.py b/module/plugins/accounts/FileserveCom.py
index 44b3f5be5..e8b4547c5 100644
--- a/module/plugins/accounts/FileserveCom.py
+++ b/module/plugins/accounts/FileserveCom.py
@@ -17,9 +17,40 @@
@author: mkaay
"""
-from module.plugins.Account import Account
import re
-from time import strptime, mktime
+from base64 import standard_b64decode
+
+from Crypto.Cipher import AES
+
+from module.plugins.Account import Account
+
+def decrypt(data):
+ data = standard_b64decode(data)
+ key = standard_b64decode("L3hpTDJGaFNPVVlnc2FUdg==")
+
+ obj = AES.new(key, AES.MODE_ECB)
+
+ return obj.decrypt(data)
+
+
+def parse(data):
+ ret = {}
+ for line in data.splitlines():
+ line = line.strip()
+ k, none, v = line.partition("=")
+ ret[k] = v
+
+ return ret
+
+def loadSoap(req, soap):
+ req.putHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.4952)")
+ req.putHeader("SOAPAction", "\"urn:FileserveAPIWebServiceAction\"")
+
+ ret = req.load("http://api.fileserve.com/api/fileserveAPIServer.php", post=soap, cookies=False, referer=False)
+
+ req.clearHeaders()
+
+ return ret
class FileserveCom(Account):
__name__ = "FileserveCom"
@@ -28,30 +59,71 @@ class FileserveCom(Account):
__description__ = """fileserve.com account plugin"""
__author_name__ = ("mkaay")
__author_mail__ = ("mkaay@mkaay.de")
-
- def loadAccountInfo(self, user, req):
- src = req.load("http://fileserve.com/dashboard.php", cookies=True)
+ LOGIN_RE = re.compile(r"<loginReturn.*?>(.*?)</loginReturn")
+ SHORTEN_RE = re.compile(r"<downloadGetShortenReturn.*?>(.*?)</downloadGetShortenReturn")
+ DIRECT_RE = re.compile(r"<downloadDirectLinkReturn.*?>(.*?)</downloadDirectLinkReturn")
+
+
+ def loginApi(self, user, req, data=None):
+ if not data:
+ data = self.getAccountData(user)
+
+ soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"urn:FileserveAPI\" xmlns:types=\"urn:FileserveAPI/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><tns:login><username xsi:type=\"xsd:string\">%s</username><password xsi:type=\"xsd:string\">%s</password></tns:login></soap:Body></soap:Envelope>" % (
+ user, data["password"])
+
+ rep = loadSoap(req, soap)
+
+ match = self.LOGIN_RE.search(rep)
+ if not match:
+ return False
- m = re.search(r"<td><h4>Premium Until</h4></th> <td><h5>(.*?) E(.)T</h5></td>", src)
- if m:
- zone = -5 if m.group(2) == "S" else -4
- validuntil = int(mktime(strptime(m.group(1), "%d %B %Y"))) + 24*3600 + (zone*3600)
- tmp = {"validuntil":validuntil, "trafficleft":-1}
- elif 'Account Type</h4></td> <td><h5 class="inline">Free' in src:
- tmp = {"premium": False, "trafficleft": None, "validuntil": None}
+ data = parse(decrypt(match.group(1)))
+
+ self.logDebug("Login: %s" % data)
+
+ return data
+
+
+ def getShorten(self, req, token, fileid):
+ soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"urn:FileserveAPI\" xmlns:types=\"urn:FileserveAPI/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><tns:downloadGetShorten><token xsi:type=\"xsd:string\">%s</token><shorten xsi:type=\"xsd:string\">%s</shorten></tns:downloadGetShorten></soap:Body></soap:Envelope>" % (
+ token, fileid)
+
+ rep = loadSoap(req, soap)
+
+ match = self.SHORTEN_RE.search(rep)
+ data = parse(decrypt(match.group(1)))
+ self.logDebug("Shorten: %s" % data)
+
+ return data
+
+
+ def getDirectLink(self, req, token):
+ soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"urn:FileserveAPI\" xmlns:types=\"urn:FileserveAPI/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><tns:downloadDirectLink><token xsi:type=\"xsd:string\">%s</token></tns:downloadDirectLink></soap:Body></soap:Envelope>" % token
+
+ rep = loadSoap(req, soap)
+
+ match = self.DIRECT_RE.search(rep)
+ data = parse(decrypt(match.group(1)))
+ self.logDebug("getDirect: %s" % data)
+
+ return data
+
+
+ def loadAccountInfo(self, user, req):
+ data = self.loginApi(user, req)
+
+ if data["user_type"] == "PREMIUM":
+ validuntil = int(data["expiry_date"])
+ return {"trafficleft": -1, "validuntil": validuntil}
else:
- tmp = {"trafficleft": None}
- return tmp
-
- def login(self, user, data, req):
-
- html = req.load("http://fileserve.com/login.php",
- post={"loginUserName": user, "loginUserPassword": data["password"],
- "autoLogin": "on", "loginFormSubmit": "Login"}, cookies=True)
+ return {"premium": False, "trafficleft": None, "validuntil": None}
+
- if r'Please Enter a valid user name.' in html or "Username doesn't exist." in html:
+ def login(self, user, data, req):
+ ret = self.loginApi(user, req, data)
+ if not ret:
+ self.wrongPassword()
+ elif ret["error"] == "LOGIN_FAIL":
self.wrongPassword()
- req.load("http://fileserve.com/dashboard.php", cookies=True)
-
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py
index 36e026721..e8d929b71 100644
--- a/module/plugins/hooks/ExternalScripts.py
+++ b/module/plugins/hooks/ExternalScripts.py
@@ -73,7 +73,7 @@ class ExternalScripts(Hook):
def callScript(self, script, *args):
try:
- cmd = [script] + [str(x) if type(x) != basestring else x for x in args]
+ cmd = [script] + [str(x) if not isinstance(x, basestring) else x for x in args]
#output goes to pyload
subprocess.Popen(cmd, bufsize=-1)
except Exception, e:
diff --git a/module/plugins/hoster/FileserveCom.py b/module/plugins/hoster/FileserveCom.py
index 6cd842941..4654e4a7e 100644
--- a/module/plugins/hoster/FileserveCom.py
+++ b/module/plugins/hoster/FileserveCom.py
@@ -80,7 +80,17 @@ class FileserveCom(Hoster):
def handlePremium(self):
- self.download(self.pyfile.url, post={"download": "premium"})
+
+ ret = self.account.loginApi(self.user, self.req)
+ ret = self.account.getShorten(self.req, ret["token"].strip("\x00"), self.file_id)
+
+ #110 offline
+ if ret["result_code"] == "110":
+ self.offline()
+
+ data = self.account.getDirectLink(self.req, ret["token"].strip("\x00"))
+
+ self.download(data['result_string'])
def handleFree(self):
self.html = self.load(self.pyfile.url)