fix(server): add disc number to fake path.

Also revert "feat(server): enable "Report Real Path" by default"

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2024-12-02 09:35:39 -05:00
parent 2b0bfbd75a
commit 627417dae3
3 changed files with 20 additions and 8 deletions

View file

@ -45,7 +45,6 @@ func (p *players) Register(ctx context.Context, id, client, userAgent, ip string
UserId: user.ID, UserId: user.ID,
Client: client, Client: client,
ScrobbleEnabled: true, ScrobbleEnabled: true,
ReportRealPath: true,
} }
log.Info(ctx, "Registering new player", "id", plr.ID, "client", client, "username", userName(ctx), "type", userAgent) log.Info(ctx, "Registering new player", "id", plr.ID, "client", client, "username", userName(ctx), "type", userAgent)
} }

View file

@ -187,14 +187,20 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
} }
func fakePath(mf model.MediaFile) string { func fakePath(mf model.MediaFile) string {
filename := mapSlashToDash(mf.Title) builder := strings.Builder{}
if mf.TrackNumber != 0 {
filename = fmt.Sprintf("%02d - %s", mf.TrackNumber, filename) builder.WriteString(fmt.Sprintf("%s/%s/", sanitizeSlashes(mf.AlbumArtist), sanitizeSlashes(mf.Album)))
if mf.DiscNumber != 0 {
builder.WriteString(fmt.Sprintf("%02d-", mf.DiscNumber))
} }
return fmt.Sprintf("%s/%s/%s.%s", mapSlashToDash(mf.AlbumArtist), mapSlashToDash(mf.Album), filename, mf.Suffix) if mf.TrackNumber != 0 {
builder.WriteString(fmt.Sprintf("%02d - ", mf.TrackNumber))
}
builder.WriteString(fmt.Sprintf("%s.%s", sanitizeSlashes(mf.Title), mf.Suffix))
return builder.String()
} }
func mapSlashToDash(target string) string { func sanitizeSlashes(target string) string {
return strings.ReplaceAll(target, "/", "_") return strings.ReplaceAll(target, "/", "_")
} }

View file

@ -27,11 +27,18 @@ var _ = Describe("helpers", func() {
Expect(fakePath(mf)).To(Equal("Brock Berrigan/Point Pleasant/04 - Split Decision.flac")) Expect(fakePath(mf)).To(Equal("Brock Berrigan/Point Pleasant/04 - Split Decision.flac"))
}) })
}) })
When("TrackNumber and DiscNumber are available", func() {
It("adds the trackNumber to the path", func() {
mf.TrackNumber = 4
mf.DiscNumber = 1
Expect(fakePath(mf)).To(Equal("Brock Berrigan/Point Pleasant/01-04 - Split Decision.flac"))
})
})
}) })
Describe("mapSlashToDash", func() { Describe("sanitizeSlashes", func() {
It("maps / to _", func() { It("maps / to _", func() {
Expect(mapSlashToDash("AC/DC")).To(Equal("AC_DC")) Expect(sanitizeSlashes("AC/DC")).To(Equal("AC_DC"))
}) })
}) })