Skip to content

feat: add support for last played Spotify activity - #318

Open
itshakemd wants to merge 3 commits into
Phineas:mainfrom
itshakemd:main
Open

itshakemd wants to merge 3 commits into
Phineas:mainfrom
itshakemd:main

Conversation

@itshakemd

Copy link
Copy Markdown

Pull Request: Add Support for Last Played Spotify Activity

Description

This PR introduces a new "Last Played Spotify" feature. Previously, when a user paused their Spotify music or went offline, their Lanyard presence would simply drop the Spotify data and show them as "idle" (or no active Spotify).
With this change, Lanyard will now cache the user's last played Spotify song in Redis and return it in the presence payload whenever they are not currently listening to anything. This provides a more meaningful historical presence instead of a blank state.

Changes Made

  1. Presence Struct Update: Added the last_played_spotify field to Lanyard.Presence.PrettyPresence (in lib/presence/presence.ex).
  2. Redis Caching: Added get_last_played_spotify/1 and set_last_played_spotify/2 helper functions to Lanyard.Connectivity.Redis for storing and retrieving the JSON serialized Spotify activity.
  3. Presence Builder Logic: Modified build_pretty_presence/1:
    • Spawns an async task to cache the spotify_activity to Redis when it is active.
    • Queries Redis to retrieve the cached last_played_spotify data when spotify_activity is nil (e.g. music paused or user offline).

@pxseu

pxseu commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

This, alongside with the Last Seen Pr's l will be in limbo due to the amount of data saved into Redis, per second. I ought to implement both at once (last RPC?, update in general) but I'm not sure what's the best way to not hammer Redis

@dustinrouillard

dustinrouillard commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Adding to this, when/if we actually implement previous activities/songs, we'll want to consider not just throwing it all in the existing route, we shouldn't make the lanyard object response size all that much bigger for features most won't even use, of course this is just my thoughts and its open for discussion with maintainers.

Perhaps a query parameter to return the "stale" data rather then adding another route

@itztrmin

itztrmin commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Agree with dustinrouillard on opt-in data fetching (eg.. using a ?include_history=true query param or dedicated endpoint) to keep default API response sizes light.

@itshakemd

Copy link
Copy Markdown
Author

This, alongside with the Last Seen Pr's l will be in limbo due to the amount of data saved into Redis, per second. I ought to implement both at once (last RPC?, update in general) but I'm not sure what's the best way to not hammer Redis

That makes sense. I agree that writing to Redis on every presence update could create unnecessary load. I’ll update Redis only when the value actually changes, using local caching where appropriate. I’ll look into implementing this if there’s actual interest in the feature. Thanks for pointing this out

@Phineas

Phineas commented Sep 3, 2026

Copy link
Copy Markdown
Owner

I don't want us to introduce a Redis call per presence query. Lanyard was designed to be extremely efficient on the lookup path (memory operations only) so we don't need to introduce rate limits. Lanyard is also currently able to operate if Redis is down/unavailable for whatever reason, which is a nice bonus.

If we do ever introduce something like this, it must be cached within the Presence GenServer state.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants