This small script polls Last.fm for a user's currently playing track and updates
Discord Rich Presence using the pypresence module.
Requirements
- Python 3.8+
- Install dependencies:
pip install -r requirements.txtUsage
You can provide credentials via a .env file.
Using a .env file
You can store sensitive credentials in a .env file and load it with --env-file (default is .env). The script uses python-dotenv to load the file before parsing arguments.
Environment variables:
LASTFM_USER— Last.fm usernameLASTFM_API_KEY— Last.fm API keyDISCORD_APP_ID— Discord Application (Client) ID
Additional optional environment variables for authenticated/signed requests:
LASTFM_API_SECRET— Last.fm API secret to computeapi_sigper the auth specLASTFM_SESSION_KEY— session key (sk) if you have an authenticated session (This can be obtained using the --auth arg (will automatically be saved to your .env file))
Options:
--interval— polling interval in seconds (default 15)--verbose— enable verbose logging
Notes
- this uses a json (default is cover_cache.json) file to store the urls of all previously accessed album art urls to reduce reliance on the Last.fm API
- Discord Rich Presence can use uploaded assets, media proxy images (
mp:{image_id}), or external URL assets when the client accepts them - map album and artist names to asset values with
--asset-map; if no match is found, the script falls back to the fetched image URL, then to text-only presence unless--large-image-defaultis set
Files