hass-music-assistant icon indicating copy to clipboard operation
hass-music-assistant copied to clipboard

‘Tracks’ tab inverted sorting with ‘Recently Added’ (Spotify)

Open zimmra opened this issue 1 year ago • 4 comments

What version of Music Assistant has the issue?

B97

The problem

When in the Tracks tab, sorting by Recently Added has inverted behavior from other music apps (at least with Spotify tracks)

How to reproduce

Go to tracks tab

sort by Recently Added

Relevant log output

No response

Additional information

Sorting by Recently Added in Spotify, Apple Music, and other streaming apps sorts from newest to oldest

My tracks are sorted with the oldest songs I’ve liked on Spotify as the first tracks

What version of Home Assistant Core are your running

2024.2.2

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

Generic x86-64 (e.g. Intel NUC)

zimmra avatar Feb 18 '24 16:02 zimmra

These are the first tracks I ever liked on Spotify, at the top when using this sort method:

IMG_4508

Here they are at the bottom of my Spotify liked songs when sorted by recently added:

IMG_4509

zimmra avatar Feb 18 '24 16:02 zimmra

Looks like you are comparing to the Spotify app. Can you check the website and see what order you get here,

OzGav avatar Feb 23 '24 11:02 OzGav

Looks like you are comparing to the Spotify app. Can you check the website and see what order you get here,

As far as I can tell, there's no ability to sort liked songs within the spotify web app - it just automatically sorts by newest -> oldest and doesn't give you an option otherwise

Default sorting, top of list: image

bottom of list: image

Expanding this option does not reveal any sorting options, and clicking the column headers does not either

image

zimmra avatar Feb 23 '24 17:02 zimmra

After getting a bit better understanding of code, I see now that they are all sorted backwards just from the initial import.

The spotify API reports them from newest -> oldest, so when MASS is first adding them to the MASS database it is creating records for the newest songs first, giving them an older timestamp then the songs it scans last (the older songs in spotify)

So initial scan would see something like this:

  1. newest liked song
  2. second newest liked song
  3. second oldest liked song
  4. oldest liked song

And because it's adding them to DB in that order they end up inverted:

  1. newest DB import timestamp = oldest liked song
  2. second newest DB import timestamp = second oldest liked song
  3. second oldest DB import timestamp = second newest liked song
  4. oldest DB import timestamp = newest liked song

I see two ways it can be resolved, not confident I'll be able to make a PR for this but could try to take a stab at it

  1. Instead of invoking timestamp_added here use/respect the items["added_at"] field provided by the API (if coming from Spotify) image

  2. invert the order for the initial/first import but then still use them same method to add them to recently added after that.

zimmra avatar Feb 23 '24 20:02 zimmra

You are completely mixing up 2 things here:

  1. The Music Assistant library
  2. The spotify liked songs playlist

These are unrelated. Sorting the tracks listing of MA to recently added is about the MA database and not spotify. You can open the Liked songs playlist in MA (from the playlists section) to get the spotify sorting.

marcelveldt avatar May 03 '24 17:05 marcelveldt