Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from xml.dom import minidom
from _md5 import md5
import urllib.request
import webbrowser
import json
last_fm_api_key = "asdasd"
secret = "asdasd"
url = "http://ws.audioscrobbler.com/2.0/?method=auth.gettoken&api_key=" + last_fm_api_key
response = urllib.request.urlopen(url)
content = response.read().decode('utf-8')
file = open("token.xml", 'w')
file.write(content)
file.close()
xmldoc = minidom.parse("token.xml")
lfm = xmldoc.getElementsByTagName("lfm")[0]
token = lfm.getElementsByTagName("token")[0].firstChild.data
print("Token: {}".format(token))
#webbrowser.open("http://www.last.fm/api/auth/?api_key=" + last_fm_api_key + "&token=" + token)
api_signature = md5(("api_key" + last_fm_api_key + "methodauth.getSessiontoken" + token + secret).encode('utf-8'))
print("API Signature: {}".format(api_signature.hexdigest()))
class AppURLopener(urllib.request.FancyURLopener):
version = "App/1.7"
opener = AppURLopener()
session_key = opener.open("http://ws.audioscrobbler.com/2.0/?method=auth.getSession&format=json&api_key=" + \
last_fm_api_key + "&token=" + token + "&api_sig=" + api_signature.hexdigest()).read().decode('utf-8')
json_obj = json.loads(session_key)
print(json_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.