homeassistantcomponent_spotifyplus icon indicating copy to clipboard operation
homeassistantcomponent_spotifyplus copied to clipboard

Liked songs for an artist

Open slunak opened this issue 5 months ago • 21 comments

Checklist

  • [x] I have filled out the template to the best of my ability.
  • [x] This only contains 1 enhancement request (if you have multiple requests, open a new request for each enhancement).
  • [x] This issue is not a duplicate enhancement request (search previous requests).

Is your enhancement request related to a problem? Please describe.

No ability to play only songs that I liked for an artist.

Describe the solution you'd like

Add a link to list of songs that I liked for a specific artist.

Describe alternatives you've considered

None.

Additional context

Image

slunak avatar Sep 26 '25 05:09 slunak

@slunak I take it you want to use the SpotifyPlus Integration Player Media Play Track Favorites service to play the track favorites list, filtering by artist name? As well as the Get Track Favorites service to retrieve the list, but filter it by artist name?

I like the idea, but it may be a time consuming service call depending on the number of track favorites that you have. The Spotify Web API does not have an endpoint to filter favorites like this, so I would have to retrieve the full list of favorites and then apply a filter. It's easy enough to do, but may be a little slow if you have a lot of track favorites.

Another Alternative

Note that you can easily do this via the SpotifyPlus Card using the Track Favorites section:

Example of a filtered list by artist name: Image

Example of an unfiltered list: Image

thlucas1 avatar Sep 26 '25 13:09 thlucas1

Hey, thanks for looking into this. The workaround will not work. It will filter and display songs for the artist, it will play the song you chose but will send various songs from various artists into the queue. In your example the first song to play will be the song you choose by Jeremy Camp, but the next song most likely will not be his. What I am looking for is to have ability to play favorite (liked) songs only from a particular artist. It is possible on mobile Spotify app, desktop app and in CarPlay too. I guess these apps dynamically build the track list or they use some other internal APIs.

Image Image

Result queue contains only songs by this artist that I liked:

Image

I have 600 songs in my Liked list, just fyi really

slunak avatar Sep 26 '25 14:09 slunak

@slunak Thanks for the detailed response.

Just released v1.0.167 of the SpotifyPlus Integration. Just released v1.0.63 of the SpotifyPlus Card. You will need to update both components for this fix.

I think the fix I provided will work for you; give it a try and let me know.

I updated the SpotifyPlus Integration Get Track Favorites and Player Media Play Track Favorites services to add the artist and album filter criteria if you want to use this functionality in automations / scripts.

I updated the SpotifyPlus Card action context menu items for all of the different sections that can display album and artist options. I added context menu items to "Play Favorite Tracks from this Artist" for artist options and "Play Favorite Tracks from this Album" for album options.

SpotifyPlus Card Artist Info Actions

Image

SpotifyPlus Card Album Info Actions

Image

SpotifyPlus Integration Release Notes

[ 1.0.167 ] - 2025/09/26

  • Updated spotifywebapipython package requirement to spotifywebapipython>=1.0.247.

[ 1.0.166 ] - 2025/09/26

  • Updated player_media_play_track_favorites service to add the filter_artist and filter_album arguments, which will filter track favorites by artist name, album name, or both.
  • Updated get_track_favorites service to add the filter_artist and filter_album arguments, which will filter track favorites by artist name, album name, or both.
  • Updated spotifywebapipython package requirement to spotifywebapipython>=1.0.246.

SpotifyPlus Card Release Notes

[ 1.0.63 ] - 2025/09/26

  • Added "Play Favorite Tracks from this Artist" context menu item to artist actions.
  • Added "Play Favorite Tracks from this Album" context menu item to album actions.
  • Added "Play Favorite Tracks from this Artist" context menu item to album actions.
  • Added "Play Favorite Tracks from this Album" context menu item to track actions.
  • Added "Play Favorite Tracks from this Artist" context menu item to track actions.
  • Added "Play Favorite Tracks from this Album" context menu item to player body track actions.
  • Added "Play Favorite Tracks from this Artist" context menu item to player body track actions.
  • Removed "Play Track Favorites for Artist x" context menu item from track actions.

thlucas1 avatar Sep 26 '25 22:09 thlucas1

Thank you @thlucas1 this solution is exactly what I was looking for. There is a little bug though. I am not sure why this is happening...

Notice the list of tracks in queue when played liked songs by artist from Spotify desktop app. All the songs in the queue list on the right correspond to the list of liked songs on the left.

Image

And now compare the list of tracks when played liked songs by artist from SpotifyPlus Card, some songs differ.

Image

Songs I highlighted in the queue are not "liked", their name matches to the song in the liked list, but the song actually is different.

slunak avatar Sep 27 '25 05:09 slunak

@slunak I see what you mean ... This could be related to a market / country code not being applied. Do you use Spotify US market / country? Or a non-US market? Note that the tracks appear in a different order in the queue due to SpotifyPlus Card shuffling them.

Also, can you verify that you have SpotifyPlus Card v1.0.63 installed?
v1.0.62 of the card filter uses the partial text of the artist name when filtering, which could cause the wrong track to be included. v1.0.63 uses the exact URI of the artist when filtering.

I would suggest calling the SpotifyPlus Integration Get Track Favorites service (via Developer Tools \ Actions) (yaml mode), and verifying the actual track URI values that are returned. If it IS a market / country value problem, then I will need to add the market value parameter when calling the service from the SpotifyPlus Card.

service: spotifyplus.get_track_favorites
data:
  entity_id: media_player.spotifyplus_john_s
  limit_total: 750

Will return something like this:

user_profile:
  country: US        
  display_name: John Smith
  email: [email protected]
  id: 3758dfdsfjk435hjk6k79lm0n3c4
  product: premium
  type: user
  uri: spotify:user:3758dfdsfjk435hjk6k79lm0n3c4
result:
  ... <data truncated for brevity - same results as Spotify Web API returns>

What do you see for the user_profile: \ country: value?

thlucas1 avatar Sep 27 '25 08:09 thlucas1

I double checked, and just in case re-downloaded the card, it is definitely on v1.0.63.

In regards to the region: country: UA

When running spotifyplus.get_track_favorites I get back lots of tracks, including the one that is mismatched in SpotifyPlus Card.

Image

Track: https://open.spotify.com/track/1PNwRnxuRfxjqnzmrmBjeo (copied from Spotify desktop app). I can see it in the list returned.

Image

The track from the queue (the wrong one): https://open.spotify.com/track/6sCtddSFg3foJn4K2pIhfQ

Image

You see, external URL of that wrong track corresponds to the track id of the correct track.

Perhaps you need to compare to linked_from: id

Image

But this linked from id is not always there. See below example of correctly selected track:

Image

Id now corresponds to external URL.

Perhaps best to compare to id_origin? As they match in both cases.

slunak avatar Sep 27 '25 09:09 slunak

@slunak Just released v1.0.168 of the SpotifyPlus Integration. You will only need to update the SpotifyPlus integration for this fix. Give it a try and let me know how it goes.

As you pointed out, track re-linking is the issue.

To quote from the above link ... Often Spotify has several instances of a track in its catalogue, each available in a different set of markets. This commonly happens when the track the album is on has been released multiple times under different licenses in different markets. These tracks are linked together so that when a user tries to play a track that isn’t available in their own market, the Spotify mobile, desktop, and web players try to play another instance of the track that is available in the user’s market.

Underlying code was changed to use the "linked from" track URI when building the list of tracks to play.

thlucas1 avatar Sep 27 '25 15:09 thlucas1

Hey, thank you! It now definitely builds the right queue and plays the right tracks.

There is one little bug still I think, but it is minor and Im not sure if you would even want to tackle it, see yourself.

Despite playing the right song, I can verify it in the Spotify app in Now Playing. The card however displays the wrong cover image and wrong "liked" status. For example, in Spotify app:

Image

I can see that this is the correct song, it is "liked" (green tick box). But in the SpotifyPlus Card I see this:

Image

Different album art and the song is not "liked" (the heart is not filled with red).

See yourself if you want to tackle it, I can help troubleshoot if you like, but I am already very much satisfied with the ability to play liked tracks from an artist!

slunak avatar Sep 28 '25 11:09 slunak

@slunak It appears to be the same issue with the track re-linking, in that the save favorites logic is not using the origin uri value when storing the favorite track.

Can you execute the following from Developer Tools \ Actions (yaml mode) and see which track id is stored for that track favorite? Just want to make sure before I change the logic.

action: spotifyplus.check_track_favorites
data:
  entity_id: media_player.spotifyplus_todd_l
  ids: 6sCtddSFg3foJn4K2pIhfQ,1PNwRnxuRfxjqnzmrmBjeo

Result should be something like this:

...
result:
  6sCtddSFg3foJn4K2pIhfQ: true
  1PNwRnxuRfxjqnzmrmBjeo: false

I appreciate your help testing this, as it's hard to find track re-linking scenarios since I live in the US. Thanks

thlucas1 avatar Sep 28 '25 14:09 thlucas1

Sure, I am happy to help.

Image

slunak avatar Sep 28 '25 17:09 slunak

@slunak I found a track that I can reproduce this on; it's the Spotify example used in their track re-linking docs, and is pretty weird (I don't recommend it on repeat)!

Here are the tracks I setup in my Card UserPresets to easily switch play between the 2 tracks:

  {
    "name": "Test US Track",
    "subtitle": "6ozxplTAjWO0BlUxN8ia0A",
    "image_url": "https://i.scdn.co/image/ab67616d0000b2730306cdd60cf3c84ceee37ace",
    "uri": "spotify:track:6ozxplTAjWO0BlUxN8ia0A",
    "type": "track"
  },
  {
    "name": "Test ES Track",
    "subtitle": "6kLCHFM39wkFjOuyPGLGeQ",
    "image_url": "https://i.scdn.co/image/ab67616d0000b2733312e753cd56d77f757d9a32",
    "uri": "spotify:track:6kLCHFM39wkFjOuyPGLGeQ",
    "type": "track"
  },

The market=ES version of the track has a GOLD border around the cover image (spotify:track:6kLCHFM39wkFjOuyPGLGeQ). The market=US version of the track has a RED border around the cover image (spotify:track:6ozxplTAjWO0BlUxN8ia0A).

Odd Spotify App Behavior

I believe there is a bug / issue with the Spotify Web App Player when displaying what is in the now playing area, what is displayed in the player transport area, and what is indicated as playing in the Liked Songs list area. This is proven by the fact that the Spotify Desktop App Player displays things differently than the Spotify Web App Player for the same playing track.

To prove this, I took screen captures of both the Spotify Web and Spotify Desktop Apps while playing the same track. If you look at Figure 1w (web) and Figure 1d (desktop) screen captures below, you can see the difference clearly based on the GOLD border color of the image in the Queue \ Now Playing area (upper right hand corner). You will also notice the playing indicator (animated green bars) next to the track with the GOLD border in the Liked Songs list.

I'm not sure how to handle your situation with this, as your Liked Songs screenshot from above (copied to Figure 3 below) is displaying the same behavior for the "Hail Mary" track. Which one is correct? (the one under the Queue \ Next Up? or the one under the "Likes Songs by 2Pac"?). The deciding factor would be whatever is returned by the Spotify Web API Get Current Playback endpoint. You can use the link and the "Try It" functionality to return the info (make sure you use market UK value so it pulls the track linking details). Note that the SpotifyPlus Card is displaying the cover image returned by the Spotify Web API Get Current Playback endpoint.

You might also try removing the favorite via the SpotifyPlus Card and re-adding it while the track is playing in the SpotifyPlus Card player (just click the heart icon on the player section to toggle favorite).

Figure 1w - Spotify Web Player Screen

Image

Figure 1d - Spotify Desktop Player Screen

Image

Figure 2 - SpotifyPlus Card Screen

Image

Figure 3 - Your Spotify Likes Songs (Hail Mary differences)

Image

thlucas1 avatar Sep 29 '25 02:09 thlucas1

Playback started with Desktop app:

Image

Playback started with SpotifyPlus card:

Image

The list of songs in the queue is identical. So this behavior is correct.

View in Web App:

Image

The view differs all right.

On the iPhone app it is the same as in the desktop app.

Which one is correct, I think any, as long as the SpotifyPlus Card can understand that the song is liked.

Here is the output of now playing call:

{
  "device": {
    ...
  },
  "repeat_state": "context",
  "shuffle_state": false,
  "context": null,
  "timestamp": 1759130579950,
  "progress_ms": 211395,
  "is_playing": true,
  "item": {
    "album": {
      "album_type": "compilation",
      "total_tracks": 11,
      "external_urls": {
        "spotify": "https://open.spotify.com/album/4Y9ISbppFbwk0r1XCLUi0I"
      },
      "href": "https://api.spotify.com/v1/albums/4Y9ISbppFbwk0r1XCLUi0I",
      "id": "4Y9ISbppFbwk0r1XCLUi0I",
      "images": [
        {
          "url": "https://i.scdn.co/image/ab67616d0000b273c1c10d28c1887c2bb1f6b2fa",
          "height": 640,
          "width": 640
        },
        {
          "url": "https://i.scdn.co/image/ab67616d00001e02c1c10d28c1887c2bb1f6b2fa",
          "height": 300,
          "width": 300
        },
        {
          "url": "https://i.scdn.co/image/ab67616d00004851c1c10d28c1887c2bb1f6b2fa",
          "height": 64,
          "width": 64
        }
      ],
      "name": "The Best of 2Pac",
      "release_date": "2007-12-03",
      "release_date_precision": "day",
      "type": "album",
      "uri": "spotify:album:4Y9ISbppFbwk0r1XCLUi0I",
      "artists": [
        {
          "external_urls": {
            "spotify": "https://open.spotify.com/artist/1ZwdS5xdxEREPySFridCfh"
          },
          "href": "https://api.spotify.com/v1/artists/1ZwdS5xdxEREPySFridCfh",
          "id": "1ZwdS5xdxEREPySFridCfh",
          "name": "2Pac",
          "type": "artist",
          "uri": "spotify:artist:1ZwdS5xdxEREPySFridCfh"
        }
      ],
      "is_playable": true
    },
    "artists": [
      {
        "external_urls": {
          "spotify": "https://open.spotify.com/artist/1ZwdS5xdxEREPySFridCfh"
        },
        "href": "https://api.spotify.com/v1/artists/1ZwdS5xdxEREPySFridCfh",
        "id": "1ZwdS5xdxEREPySFridCfh",
        "name": "2Pac",
        "type": "artist",
        "uri": "spotify:artist:1ZwdS5xdxEREPySFridCfh"
      }
    ],
    "disc_number": 1,
    "duration_ms": 309800,
    "explicit": true,
    "external_ids": {
      "isrc": "USKO10403725"
    },
    "external_urls": {
      "spotify": "https://open.spotify.com/track/6sCtddSFg3foJn4K2pIhfQ"
    },
    "href": "https://api.spotify.com/v1/tracks/6sCtddSFg3foJn4K2pIhfQ",
    "id": "6sCtddSFg3foJn4K2pIhfQ",
    "is_playable": true,
    "linked_from": {
      "external_urls": {
        "spotify": "https://open.spotify.com/track/1PNwRnxuRfxjqnzmrmBjeo"
      },
      "href": "https://api.spotify.com/v1/tracks/1PNwRnxuRfxjqnzmrmBjeo",
      "id": "1PNwRnxuRfxjqnzmrmBjeo",
      "type": "track",
      "uri": "spotify:track:1PNwRnxuRfxjqnzmrmBjeo"
    },
    "name": "Hail Mary",
    "popularity": 68,
    "preview_url": null,
    "track_number": 2,
    "type": "track",
    "uri": "spotify:track:6sCtddSFg3foJn4K2pIhfQ",
    "is_local": false
  },
  "currently_playing_type": "track",
  "actions": {
    "disallows": {
      "resuming": true
    }
  },
  "smart_shuffle": false
}

slunak avatar Sep 29 '25 07:09 slunak

It sounds like the only thing wrong here is that the track is not showing as favorited in the SpotifyPlus Card display. Is that correct?

Based on that assumption, I did a chatGPT query to see how Spotify favorites get stored - here's its response (who knows if this is correct, but it sounds solid to me): Question: "when storing a spotify track favorite via the spotify web api, which track id is stored as the favorite? the linked_from id? or the regular id?" Answer: When you add a track to Your Library (via PUT /v1/me/tracks), or when you “like” it in the Spotify apps:

  • The canonical id is what gets stored.
  • The linked_from is metadata telling you which track this was relinked from. Spotify will always normalize to the playable canonical track ID in your region. When storing a Spotify track as a favorite, Spotify saves the regular id (the playable canonical track), not the linked_from id.

So here is what we know based on the conversation history ...

  1. the track that is actually playing is using the canonical id value 6sCtddSFg3foJn4K2pIhfQ. This is proven by the now playing output results.

  2. what's odd is that the id stored in your track favorites is the "linked from id". Per the chatGPT explanation, it should have stored the canonical id; with that said, chatGPT has been wrong about things before. :) This is based on the values returned from the call to the check_track_favorites service: 6sCtddSFg3foJn4K2pIhfQ: false (canonical id) 1PNwRnxuRfxjqnzmrmBjeo: true (linked from id)

The big question is: how did the "linked from id" get stored in the favorite (and not the canonical id)? In playing around with the official Spotify Apps, there are multiple ways to "like" a track and add it to favorites.

  • the "linked from id" value is used when liking the track using the "Now Playing Queue" menu text.
  • the "canonical id" value is used when liking the track using the "Track Information" menu text (e.g. using the direct link to the track: https://open.spotify.com/track/6ozxplTAjWO0BlUxN8ia0A).
  1. It seems the official Spotify App is marking it as a favorite if either the canonical id OR the linked id are present in the favorites. The SpotifyPlus Card is only checking for the canonical id value, which is why it marks it as NOT a favorite since the linked from id is what's stored in your favorites. I think I can add logic to test for this condition.

thlucas1 avatar Oct 01 '25 00:10 thlucas1

@slunak I just released Spotify Integration v1.0.169. I just released Spotify Card v1.0.64.

Give these a try - it should report the track favorite status correctly for the re-linked track. You need to update both components.

Change log summary

SpotifyPlus Integration [ 1.0.169 ] - 2025/09/30

  • Added service get_id_from_uri to get the Id portion (e.g. 6vc9OTcyd3hyzabCmsdnwE) of a Spotify URI value (e.g. spotify:track:6vc9OTcyd3hyzabCmsdnwE).
  • Updated service volume_set_step to add the level_percent argument, which can be used to express the step level as a percentage (1 to 100) instead of a float value.
  • Added state refresh call for all add / remove favorites services.
  • Added folder automations under the base spotifyplus folder that will house sample automations for HA Voice Assist commands for SpotifyPlus.
  • Updated spotifywebapipython package requirement to spotifywebapipython>=1.0.249.

SpotifyPlus Card [ 1.0.64 ] - 2025/09/30

  • Added logic to calls made to CheckTrackFavorites to account for track relinking; we will check both the canonical id and the linked from id for favorite status, as this appears to be what the Spotify Apps do. Track is considered a favorite if either id value appears in the favorites list.
  • Added origin fields to the EpisodeSimplified object, to match those of TrackSimplified. Note that linkfrom details do not exist for episodes; These are helper properties, and are not part of the Spotify Web API specification.
  • Moved call of VolumeSetStepLevel method from player body base to the card first-time logic; any custom volume step values were getting reset when the player body refreshed.

thlucas1 avatar Oct 01 '25 01:10 thlucas1

I have tested and I am afraid the issue is still the same...

slunak avatar Oct 03 '25 14:10 slunak

@slunak To verify, the favorite status in the SpotifyPlus Card did not change? Still no red heart? The album art may still be different, but the song should have been marked as "liked" (the heart is filled with red).

thlucas1 avatar Oct 03 '25 15:10 thlucas1

Yes, that's exactly the issue. The heart is not filled with red.

slunak avatar Oct 03 '25 15:10 slunak

@slunak Apologies for the delay - it's been a busy weekend.

Let's try this ...

Start playing the 2Pac, Hail Mary track, and verify that the favorite status is NOT set in the SpotifyPlus Card. Then do the following while that track is still playing to retrieve the current player state details ...

Go to HA Developer Tools \ States and look for the following attributes (reply to this thread with the values):

sp_track_uri_origin: 
media_content_id: 
media_title: 
media_artist: 
media_album_name: 
sp_item_type: 
sp_nowplaying_image_url: 
sp_user_country: 
sp_artist_uri: 

Then execute the following from Developer Tools \ Actions (yaml mode) to check the favorite status of the id and origin values.
Change the ids: argument to the id values of the media_content_id and sp_track_uri_origin state values (separated by a comma). Be sure to use just the ID (e.g. 6kLCHFM39wkFjOuyPGLGeQ) portion of the URI (e.g. spotify:track:6kLCHFM39wkFjOuyPGLGeQ) values. Reply to this thread with the results of this call.

action: spotifyplus.check_track_favorites
data:
  entity_id: media_player.spotifyplus_todd_l
  ids: 6kLCHFM39wkFjOuyPGLGeQ, 6ozxplTAjWO0BlUxN8ia0A

It should set the favorite status correctly if either of the returned values are true.

thlucas1 avatar Oct 06 '25 12:10 thlucas1

Sure, here are the results:

sp_track_uri_origin: spotify:track:1PNwRnxuRfxjqnzmrmBjeo
media_content_id: spotify:track:6sCtddSFg3foJn4K2pIhfQ
media_title: Hail Mary
media_artist: 2Pac
media_album_name: The Best of 2Pac
sp_item_type: track
sp_nowplaying_image_url: https://i.scdn.co/image/ab67616d0000b273c1c10d28c1887c2bb1f6b2fa
sp_user_country: UA
sp_artist_uri: spotify:artist:1ZwdS5xdxEREPySFridCfh

Call:

action: spotifyplus.check_track_favorites
data:
  entity_id: media_player.spotifyplus_serhiy
  ids: 6sCtddSFg3foJn4K2pIhfQ,1PNwRnxuRfxjqnzmrmBjeo

Result (reducted):

user_profile:
  country: UA
  ...
  product: premium
  type: user
  ...
result:
  6sCtddSFg3foJn4K2pIhfQ: false
  1PNwRnxuRfxjqnzmrmBjeo: true

Image

Somthing I have noticed while getting state values for you, is that I also have official spotify integration, and here is the media_content_id state value it has while playing this song:

media_content_id: spotify:track:1PNwRnxuRfxjqnzmrmBjeo

slunak avatar Oct 06 '25 14:10 slunak

@slunak Based on the check_track_favorites results, the SpotifyPlus Card should have detected it as a favorite (assuming you have SpotifyPlus Card v1.0.64 installed).

Let's see what the card is actually doing ...

If you have Google Chrome browser, let's turn on front-end logging for the SpotifyPlus Card.

  • Bring up the HA UI to the Spotify Card display.
  • Start play of the 2Pac - Hail Mary track from your track favorites.
  • Press F12 to show the Chrome Developer Tools slide out area (to the right).
  • Press F5 to reload the page (ensures SpotifyPlus Card version is shown in the developer tools area). Your developer tools area should look something like this:
Image
  • Verify that SPOTIFYPLUS-CARD 1.0.64 IS INSTALLED is shown. If the version number is not 1.0.64, then you need to update the SpotifyPlus Card via HACS.
  • Click the little expand triangle to the left of the SPOTIFYPLUS-CARD ... IS INSTALLED entry. This will display the SpotifyPlus Card debug logging console command options.
  • Copy the following command that will be used to enable front-end debugging: localStorage.setItem('debug', 'spotifyplus-card:*');
  • Paste the command in the developer tools area prompt (to the right of the > symbol) and press enter. Debug logging is now enabled.
  • Press F5 to reload the page; you should now start seeing debug messages for the card.
  • Press CTL-F to display the Find command prompt.
Image
  • Enter check_track_favorites in the find command prompt area and press enter.
  • You should see a call made to the check_track_favorites service. Yours should contain the 2 track "ids:" though 6sCtddSFg3foJn4K2pIhfQ,1PNwRnxuRfxjqnzmrmBjeo (instead of 1 in my example). If it does not contain those id's, then you can find the previous entry of the text. If you still can't find it, then ensure that you are playing the 2Pac - Hail Mary track from your track favorites.
Image
  • Copy the following command that will be used to disable front-end debugging: localStorage.setItem('debug', '');
  • Paste the command in the developer tools area prompt (to the right of the > symbol) and press enter. Debug logging is now disabled.

thlucas1 avatar Oct 06 '25 19:10 thlucas1

To confirm the version installed:

Image

There is only one id, not two...

Image

slunak avatar Oct 07 '25 20:10 slunak