Add TrackNumber to "fake" generated filenames. Fixes #1912
This commit is contained in:
@@ -157,7 +157,7 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
|
|||||||
if ok && player.ReportRealPath {
|
if ok && player.ReportRealPath {
|
||||||
child.Path = mf.Path
|
child.Path = mf.Path
|
||||||
} else {
|
} 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.DiscNumber = mf.DiscNumber
|
||||||
child.Created = &mf.CreatedAt
|
child.Created = &mf.CreatedAt
|
||||||
@@ -182,6 +182,14 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
|
|||||||
return 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 {
|
func mapSlashToDash(target string) string {
|
||||||
return strings.ReplaceAll(target, "/", "_")
|
return strings.ReplaceAll(target, "/", "_")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user