Add TrackNumber to "fake" generated filenames. Fixes #1912

This commit is contained in:
Deluan
2022-11-02 12:11:01 -04:00
parent ca2cb26d8e
commit 80b7311453
2 changed files with 45 additions and 1 deletions
+9 -1
View File
@@ -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, "/", "_")
}