diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index e74b43e86..24cf2602d 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -157,7 +157,7 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child if ok && player.ReportRealPath { child.Path = mf.Path } else { - child.Path = fmt.Sprintf("%s/%s/%s.%s", mapSlashToDash(mf.AlbumArtist), mapSlashToDash(mf.Album), mapSlashToDash(mf.Title), mf.Suffix) + child.Path = fakePath(mf) } child.DiscNumber = mf.DiscNumber child.Created = &mf.CreatedAt @@ -182,6 +182,14 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child return child } +func fakePath(mf model.MediaFile) string { + filename := mapSlashToDash(mf.Title) + if mf.TrackNumber != 0 { + filename = fmt.Sprintf("%02d - %s", mf.TrackNumber, filename) + } + return fmt.Sprintf("%s/%s/%s.%s", mapSlashToDash(mf.AlbumArtist), mapSlashToDash(mf.Album), filename, mf.Suffix) +} + func mapSlashToDash(target string) string { return strings.ReplaceAll(target, "/", "_") } diff --git a/server/subsonic/helpers_test.go b/server/subsonic/helpers_test.go new file mode 100644 index 000000000..91b2f1000 --- /dev/null +++ b/server/subsonic/helpers_test.go @@ -0,0 +1,36 @@ +package subsonic + +import ( + "github.com/navidrome/navidrome/model" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("helpers", func() { + Describe("fakePath", func() { + var mf model.MediaFile + BeforeEach(func() { + mf.AlbumArtist = "Brock Berrigan" + mf.Album = "Point Pleasant" + mf.Title = "Split Decision" + mf.Suffix = "flac" + }) + When("TrackNumber is not available", func() { + It("does not add any number to the filename", func() { + Expect(fakePath(mf)).To(Equal("Brock Berrigan/Point Pleasant/Split Decision.flac")) + }) + }) + When("TrackNumber is available", func() { + It("adds the trackNumber to the path", func() { + mf.TrackNumber = 4 + Expect(fakePath(mf)).To(Equal("Brock Berrigan/Point Pleasant/04 - Split Decision.flac")) + }) + }) + }) + + Describe("mapSlashToDash", func() { + It("maps / to _", func() { + Expect(mapSlashToDash("AC/DC")).To(Equal("AC_DC")) + }) + }) +})