diff --git a/server/subsonic/engine/common.go b/server/subsonic/engine/common.go index d8bb92dc2..53f15f357 100644 --- a/server/subsonic/engine/common.go +++ b/server/subsonic/engine/common.go @@ -2,8 +2,10 @@ package engine import ( "context" + "fmt" "time" + "github.com/deluan/navidrome/consts" "github.com/deluan/navidrome/model" "github.com/deluan/navidrome/model/request" ) @@ -40,6 +42,7 @@ type Entry struct { PlayerName string AlbumCount int BookmarkPosition int64 + AbsolutePath string } type Entries []Entry @@ -101,7 +104,11 @@ func FromMediaFile(mf *model.MediaFile) Entry { e.CoverArt = "al-" + mf.AlbumID } e.ContentType = mf.ContentType() - e.Path = mf.Path + e.AbsolutePath = mf.Path + // Creates a "pseudo" Path, to avoid sending absolute paths to the client + if mf.Path != "" { + e.Path = fmt.Sprintf("%s/%s/%s.%s", realArtistName(mf), mf.Album, mf.Title, mf.Suffix) + } e.DiscNumber = mf.DiscNumber e.Created = mf.CreatedAt e.AlbumId = mf.AlbumID @@ -116,6 +123,17 @@ func FromMediaFile(mf *model.MediaFile) Entry { return e } +func realArtistName(mf *model.MediaFile) string { + switch { + case mf.Compilation: + return consts.VariousArtists + case mf.AlbumArtist != "": + return mf.AlbumArtist + } + + return mf.Artist +} + func FromAlbums(albums model.Albums) Entries { entries := make(Entries, len(albums)) for i := range albums {