SubmarinerApp / Submariner

A Subsonic client for macOS
https://submarinerapp.com
BSD 3-Clause "New" or "Revised" License
123 stars 3 forks source link

Songs in remote playlists do not respect playlist order. #116

Closed Porco-Rosso closed 1 year ago

Porco-Rosso commented 1 year ago

Hi, I've noticed that when streaming from Navidrome to Submariner, the songs inside playlists are in a seemingly random order. Since track order are an important part of playlists, I'm hoping song order can be implemented. PS: thanks for fixing the playlist sidebar order!

NattyNarwhal commented 1 year ago

This seems to be because:

I think I see how to fix this ideally (make playlist item a many to many relationship between playlist and track, with ordering), but it'll be very annoying and requires another schema change.

NattyNarwhal commented 1 year ago

If we do treat playlist indices as volatile, then it does actually come out to be pretty simple:

diff --git a/Submariner/SBSubsonicParsingOperation.m b/Submariner/SBSubsonicParsingOperation.m
index c876ede..5ea7bf1 100644
--- a/Submariner/SBSubsonicParsingOperation.m
+++ b/Submariner/SBSubsonicParsingOperation.m
@@ -503,6 +503,7 @@ NSString *SBSubsonicPodcastsUpdatedNotification         = @"SBSubsonicPodcastsUp
                     exists = YES;
                 }
             }
+            track.playlistIndex = [NSNumber numberWithInteger: playlistIndex++];

             if(!exists) {
                 [currentPlaylist addTracksObject:track];
@@ -512,6 +513,7 @@ NSString *SBSubsonicPodcastsUpdatedNotification         = @"SBSubsonicPodcastsUp
         } else {
             // create it
             track = [self createTrackWithAttribute:attributeDict];
+            track.playlistIndex = [NSNumber numberWithInteger: playlistIndex++];
             [currentPlaylist addTracksObject:track];
             [track setServer:server];
             [track setPlaylist:currentPlaylist];

...though persisting the changes is another problem - I think just call createPlaylist with the full body (since updatePlaylist only does adds/deletes, not reordering).

Seems to work otherwise though. You may need to reload the playlist for it to correct when the change is made though.