hass-music-assistant
hass-music-assistant copied to clipboard
‘Tracks’ tab inverted sorting with ‘Recently Added’ (Spotify)
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)
These are the first tracks I ever liked on Spotify, at the top when using this sort method:
Here they are at the bottom of my Spotify liked songs when sorted by recently added:
Looks like you are comparing to the Spotify app. Can you check the website and see what order you get here,
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:
bottom of list:
Expanding this option does not reveal any sorting options, and clicking the column headers does not either
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:
- newest liked song
- second newest liked song
- second oldest liked song
- oldest liked song
And because it's adding them to DB in that order they end up inverted:
- newest DB import timestamp = oldest liked song
- second newest DB import timestamp = second oldest liked song
- second oldest DB import timestamp = second newest liked song
- 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
-
Instead of invoking
timestamp_added
here use/respect theitems["added_at"]
field provided by the API (if coming from Spotify) -
invert the order for the initial/first import but then still use them same method to add them to recently added after that.
You are completely mixing up 2 things here:
- The Music Assistant library
- 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.