sentriz / gonic

music streaming server / free-software subsonic server API implementation
ircs://irc.libera.chat/#gonic
GNU General Public License v3.0
1.62k stars 115 forks source link

Add playlists with no user to admin's playlist list. #499

Closed xxxserxxx closed 6 months ago

xxxserxxx commented 7 months ago

This is carrying on from the various tickets under which playlists have been discussed.

For reasons well-known (#306, #311, #307, #311... but mainly #306), the Subsonic API forces playlists to be by user ID. The solution in gonic was to expect a directory layout with <playlistpath>/<userid>/.../<whatever>.m3u. This is inconvenient for users for whom gonic is not the only application using the playlist directory, and maybe not even the main one, an inconvenience exacerbated by the fact that fs.DirEntry.IsDir() returns false for directory symlinks.

This extremely trivial change does one thing: instead of throwing an error when the directory structure does not contain user IDs as the second element in the path, it merely adds those playlists to the admin's playlist list. This change has two impacts:

  1. These playlists would otherwise be entirely ignored by gonic. It's possible some users are leveraging that to have playlists in the same directory used by some other program that they intentionally hide from gonic.
  2. admin might suddenly see a bunch of playlists they didn't before, because there were playlists that were being ignored

What it accomplishes is that it allows gonic to share playlists with all of the other non-Subsonic apps that don't put playlists into int-named subdirectories.

sentriz commented 7 months ago

interesting. what happens then when the admin goes to edit the playlist then

sentriz commented 7 months ago

havent tried but I think it end up making a copy of it or something when you go to update

xxxserxxx commented 7 months ago

I don't know; I'm not using a client that allows editing the playlist, but from a quick scan of the code CreateOrSave handler reloads all the playlists and only constructs a new file path if it doesn't find a matching playlist. I believe if Admin edits an existing playlist from the parent playlist directory, it'll actually edit the playlist and not create a new one.

c.f. server/ctrlsubsonic/handlers_playlist.go#78, where it tries to load the playlist by ID using this same Load() function. The user ID doesn't come into play unless the playlist is new, in which case SaveCreateOrUpdatePlaylist() creates a new playlist path using the user ID on line 104.

What I'm not sure about is what happens when Gonic encounters duplicate playlists names -- although, this is already an issue if 3 different users all create playlists with the same name, and mark them all GLOBAL.

sentriz commented 6 months ago

thanks, seems to work fine. as for muliple playlists with the same name, i think its fine since they have unique ids that match the filesystem