mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Merge pull request #293 from duckfromdiscord/as2.0-xml
make `auth.getMobileSession` return XML
This commit is contained in:
commit
b35bfdc2e4
@ -28,6 +28,15 @@ class Audioscrobbler(APIHandler):
|
|||||||
Exception: (500, {"error": 8, "message": "Operation failed"})
|
Exception: (500, {"error": 8, "message": "Operation failed"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# xml string escaping: https://stackoverflow.com/a/28703510
|
||||||
|
def xml_escape(self, str_xml: str):
|
||||||
|
str_xml = str_xml.replace("&", "&")
|
||||||
|
str_xml = str_xml.replace("<", "<")
|
||||||
|
str_xml = str_xml.replace("<", "<")
|
||||||
|
str_xml = str_xml.replace("\"", """)
|
||||||
|
str_xml = str_xml.replace("'", "'")
|
||||||
|
return str_xml
|
||||||
|
|
||||||
def get_method(self,pathnodes,keys):
|
def get_method(self,pathnodes,keys):
|
||||||
return keys.get("method")
|
return keys.get("method")
|
||||||
|
|
||||||
@ -45,12 +54,22 @@ class Audioscrobbler(APIHandler):
|
|||||||
token = keys.get("authToken")
|
token = keys.get("authToken")
|
||||||
user = keys.get("username")
|
user = keys.get("username")
|
||||||
password = keys.get("password")
|
password = keys.get("password")
|
||||||
|
format = keys.get("format") or "xml" # Audioscrobbler 2.0 uses XML by default
|
||||||
# either username and password
|
# either username and password
|
||||||
if user is not None and password is not None:
|
if user is not None and password is not None:
|
||||||
client = apikeystore.check_and_identify_key(password)
|
client = apikeystore.check_and_identify_key(password)
|
||||||
if client:
|
if client:
|
||||||
sessionkey = self.generate_key(client)
|
sessionkey = self.generate_key(client)
|
||||||
|
if format == "json":
|
||||||
return 200,{"session":{"key":sessionkey}}
|
return 200,{"session":{"key":sessionkey}}
|
||||||
|
else:
|
||||||
|
return 200,"""<lfm status="ok">
|
||||||
|
<session>
|
||||||
|
<name>%s</name>
|
||||||
|
<key>%s</key>
|
||||||
|
<subscriber>0</subscriber>
|
||||||
|
</session>
|
||||||
|
</lfm>""" % (self.xml_escape(user), self.xml_escape(sessionkey))
|
||||||
else:
|
else:
|
||||||
raise InvalidAuthException()
|
raise InvalidAuthException()
|
||||||
# or username and token (deprecated by lastfm)
|
# or username and token (deprecated by lastfm)
|
||||||
@ -59,7 +78,16 @@ class Audioscrobbler(APIHandler):
|
|||||||
key = apikeystore[client]
|
key = apikeystore[client]
|
||||||
if md5(user + md5(key)) == token:
|
if md5(user + md5(key)) == token:
|
||||||
sessionkey = self.generate_key(client)
|
sessionkey = self.generate_key(client)
|
||||||
|
if format == "json":
|
||||||
return 200,{"session":{"key":sessionkey}}
|
return 200,{"session":{"key":sessionkey}}
|
||||||
|
else:
|
||||||
|
return 200,"""<lfm status="ok">
|
||||||
|
<session>
|
||||||
|
<name>%s</name>
|
||||||
|
<key>%s</key>
|
||||||
|
<subscriber>0</subscriber>
|
||||||
|
</session>
|
||||||
|
</lfm>""" % (self.xml_escape(user), self.xml_escape(sessionkey))
|
||||||
raise InvalidAuthException()
|
raise InvalidAuthException()
|
||||||
else:
|
else:
|
||||||
raise BadAuthException()
|
raise BadAuthException()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user