🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add AlbumPlayCountMode config option (#2803)
vvdveen8bff1ad512f4
diff --git a/cmd/root.go b/cmd/root.goindex 44307cd46..6b91bfe4b 100644--- a/cmd/root.go+++ b/cmd/root.go@@ -192,6 +192,7 @@ func init() {rootCmd.Flags().Bool("enabletranscodingconfig", viper.GetBool("enabletranscodingconfig"), "enables transcoding configuration in the UI")rootCmd.Flags().String("transcodingcachesize", viper.GetString("transcodingcachesize"), "size of transcoding cache")rootCmd.Flags().String("imagecachesize", viper.GetString("imagecachesize"), "size of image (art work) cache. set to 0 to disable cache")+ rootCmd.Flags().String("albumplaycountmode", viper.GetString("albumplaycountmode"), "how to compute playcount for albums. absolute (default) or normalized")rootCmd.Flags().Bool("autoimportplaylists", viper.GetBool("autoimportplaylists"), "enable/disable .m3u playlist auto-import`")rootCmd.Flags().Bool("prometheus.enabled", viper.GetBool("prometheus.enabled"), "enable/disable prometheus metrics endpoint`")@@ -214,4 +215,5 @@ func init() {_ = viper.BindPFlag("enabletranscodingconfig", rootCmd.Flags().Lookup("enabletranscodingconfig"))_ = viper.BindPFlag("transcodingcachesize", rootCmd.Flags().Lookup("transcodingcachesize"))_ = viper.BindPFlag("imagecachesize", rootCmd.Flags().Lookup("imagecachesize"))+ _ = viper.BindPFlag("albumplaycountmode", rootCmd.Flags().Lookup("albumplaycountmode"))}diff --git a/conf/configuration.go b/conf/configuration.goindex cfb644143..db14f84cb 100644--- a/conf/configuration.go+++ b/conf/configuration.go@@ -44,6 +44,7 @@ type configOptions struct {EnableMediaFileCoverArt boolTranscodingCacheSize stringImageCacheSize string+ AlbumPlayCountMode stringEnableArtworkPrecache boolAutoImportPlaylists boolPlaylistsPath string@@ -289,6 +290,7 @@ func init() {viper.SetDefault("enabletranscodingconfig", false)viper.SetDefault("transcodingcachesize", "100MB")viper.SetDefault("imagecachesize", "100MB")+ viper.SetDefault("albumplaycountmode", consts.AlbumPlayCountModeAbsolute)viper.SetDefault("enableartworkprecache", true)viper.SetDefault("autoimportplaylists", true)viper.SetDefault("playlistspath", consts.DefaultPlaylistsPath)diff --git a/consts/consts.go b/consts/consts.goindex b1f284abf..b52b21684 100644--- a/consts/consts.go+++ b/consts/consts.go@@ -81,6 +81,11 @@ const (DefaultCacheCleanUpInterval = 10 * time.Minute)+const (+ AlbumPlayCountModeAbsolute = "absolute"+ AlbumPlayCountModeNormalized = "normalized"+)+var (DefaultDownsamplingFormat = "opus"DefaultTranscodings = []map[string]interface{}{diff --git a/persistence/album_repository.go b/persistence/album_repository.goindex c4aeb7678..981e55ebf 100644--- a/persistence/album_repository.go+++ b/persistence/album_repository.go@@ -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, efunc (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