Add AlbumPlayCountMode config option (#2803)
Closes #1032 * feat(album_repository.go): add kodi-style album playcount option - #1032 Signed-off-by: Victor van der Veen <vvdveen@gmail.com> * fix format issue and remove reference to kodi (now normalized) Signed-off-by: Victor van der Veen <vvdveen@gmail.com> * reduced complexity but added rounding Signed-off-by: Victor van der Veen <vvdveen@gmail.com> * Use constants for AlbumPlayCountMode values --------- Signed-off-by: Victor van der Veen <vvdveen@gmail.com> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
. "github.com/Masterminds/squirrel"
|
||||
"github.com/deluan/rest"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/pocketbase/dbx"
|
||||
@@ -172,6 +173,9 @@ func (r *albumRepository) GetAll(options ...model.QueryOptions) (model.Albums, e
|
||||
func (r *albumRepository) toModels(dba []dbAlbum) model.Albums {
|
||||
res := model.Albums{}
|
||||
for i := range dba {
|
||||
if conf.Server.AlbumPlayCountMode == consts.AlbumPlayCountModeNormalized && dba[i].Album.SongCount != 0 {
|
||||
dba[i].Album.PlayCount = (dba[i].Album.PlayCount + (int64(dba[i].Album.SongCount) - 1)) / int64(dba[i].Album.SongCount)
|
||||
}
|
||||
res = append(res, *dba[i].Album)
|
||||
}
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user