Skip to content

Instantly share code, notes, and snippets.

@Vocaned
Last active September 12, 2025 11:49
Show Gist options
  • Select an option

  • Save Vocaned/b485b053c99a2081e67f0bd059a08cc4 to your computer and use it in GitHub Desktop.

Select an option

Save Vocaned/b485b053c99a2081e67f0bd059a08cc4 to your computer and use it in GitHub Desktop.
import requests
import hashlib
from urllib.parse import urlencode
import json
api_key = input('API Key: ')
secret = input('Secret: ')
print(f'Open http://www.last.fm/api/auth/?api_key={api_key}')
token = input('Enter the token: ')
api = 'https://ws.audioscrobbler.com/2.0/'
params = {
'api_key': api_key,
'method': 'auth.getSession',
'token': token
}
sig = hashlib.md5(''.join([f'{k}{v}' for k,v in sorted(params.items())]).encode('utf-8') + secret.encode('utf-8')).hexdigest()
session = requests.get(f'https://ws.audioscrobbler.com/2.0/?{urlencode(params)}&api_sig={sig}&format=json').json()
print(json.dumps({'session': session['session']['key'], 'apikey': api_key, 'apisecret': secret}, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment