summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar Paul King <devnull@localhost> 2011-05-15 12:04:32 +0200
committerGravatar Paul King <devnull@localhost> 2011-05-15 12:04:32 +0200
commit6d37faed5243ad3c0b5d64d509733c42b5f39084 (patch)
tree41f3e2ab6648382163d75b16e015d6c296da0d49 /module/plugins
parentfix dlc upload (diff)
downloadpyload-6d37faed5243ad3c0b5d64d509733c42b5f39084.tar.xz
fix premium and convert to json
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/accounts/FilesonicCom.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/module/plugins/accounts/FilesonicCom.py b/module/plugins/accounts/FilesonicCom.py
index 1200550ae..7ea7ea7cb 100644
--- a/module/plugins/accounts/FilesonicCom.py
+++ b/module/plugins/accounts/FilesonicCom.py
@@ -22,29 +22,37 @@ from time import mktime, strptime
from module.plugins.Account import Account
+try:
+ from json import loads as json_loads
+except ImportError: # pragma: no cover
+ from module.lib.simplejson import loads as json_loads
+
+
class FilesonicCom(Account):
__name__ = "FilesonicCom"
- __version__ = "0.3"
+ __version__ = "0.31"
__type__ = "account"
__description__ = """filesonic.com account plugin"""
- __author_name__ = ("RaNaN")
- __author_mail__ = ("RaNaN@pyload.org")
+ __author_name__ = ("RaNaN","Paul King")
+ __author_mail__ = ("RaNaN@pyload.org","")
def getDomain(self, req):
- xml = req.load("http://api.filesonic.com/utility?method=getFilesonicDomainForCurrentIp&format=xml").decode("utf8")
- return re.search(r"response>.*?(filesonic\..*?)</resp", xml).group(1)
-
+ xml = req.load("http://api.filesonic.com/utility?method=getFilesonicDomainForCurrentIp&format=json").decode("utf8")
+ return json_loads(xml)["FSApi_Utility"]["getFilesonicDomainForCurrentIp"]["response"]
+
def loadAccountInfo(self, user, req):
- xml = req.load("http://api.filesonic.com/user?method=getInfo&format=xml",
+ xml = req.load("http://api.filesonic.com/user?method=getInfo&format=json",
post = {"u": user,
"p" : self.accounts[user]["password"]}
).decode("utf8")
- if re.search(r'<status>failed', xml):
+ self.core.log.debug(_("%s: account status retrieved from api %s" % (self.__name__,xml)))
+ json = json_loads(xml)
+ if json["FSApi_User"]["getInfo"]["status"] != "success":
self.core.log.error(_("%s: Invalid login retrieving user details" % self.__name__))
- self.wrongPassword()
- premium = bool(int(re.search(r'<is_premium>(\d+)',xml).group(1)))
+ return {"validuntil": -1, "trafficleft": -1, "premium" : False}
+ premium = json["FSApi_User"]["getInfo"]["response"]["users"]["user"]["is_premium"]
if premium:
- validuntil = re.search(r'<premium_expiration>\d+-\d+-\d+ \d+:\d+:\d+</', xml).group(1)
+ validuntil = json["FSApi_User"]["getInfo"]["response"]["users"]["user"]["premium_expiration"]
validuntil = int(mktime(strptime(validuntil, "%Y-%m-%d %H:%M:%S")))
else:
validuntil = -1
@@ -58,7 +66,7 @@ class FilesonicCom(Account):
"password": data["password"],
"rememberMe" : 1
}
- page = req.load("http://www.%s/user/login" % domain, cookies=True, post=post_vars).decode("utf8")
+ page = req.load("http://www%s/user/login" % domain, cookies=True, post=post_vars).decode("utf8")
if "Provided password does not match." in page or "You must be logged in to view this page." in page:
self.wrongPassword()