aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md1
-rw-r--r--config.go1
-rw-r--r--main.go2
-rw-r--r--playlist.go8
-rw-r--r--wrms.go7
5 files changed, 18 insertions, 1 deletions
diff --git a/TODO.md b/TODO.md
index 38baf55..2448bf4 100644
--- a/TODO.md
+++ b/TODO.md
@@ -18,6 +18,7 @@
- [X] support incremental search results
- [X] distinguish different search queries
- [X] do not apply obsolete events
+- [ ] support timeBonus
## Web Backend
diff --git a/config.go b/config.go
index 2483079..32b94ca 100644
--- a/config.go
+++ b/config.go
@@ -22,6 +22,7 @@ type Config struct {
Admins []uuid.UUID `yaml:"admins"`
Spotify *SpotifyConfig `yaml:"spotify"`
HasUpload bool
+ timeBonus float64 `yaml:time-bonus`
}
func defaultConfig() Config {
diff --git a/main.go b/main.go
index ec0b20a..a5cc794 100644
--- a/main.go
+++ b/main.go
@@ -268,6 +268,7 @@ func main() {
flag.StringVar(&config.LogLevel, "loglevel", config.LogLevel, "log level")
flag.IntVar(&config.Port, "port", config.Port, "port to listen to")
+ flag.Float64Var(&config.timeBonus, "time-bonus", config.timeBonus, "weight bonus granted over time")
backends := flag.String("backends", "", "music backend to use")
flag.StringVar(&config.LocalMusicDir,
"serve-music-dir", config.LocalMusicDir, "local music directory to serve")
@@ -281,6 +282,7 @@ func main() {
llog.SetLogLevelFromString(config.LogLevel)
config.HasUpload = slices.Contains(config.Backends, "upload")
+ llog.Info("%v", config)
wrms = NewWrms(config)
setupRoutes()
diff --git a/playlist.go b/playlist.go
index 1fbd344..aeb1297 100644
--- a/playlist.go
+++ b/playlist.go
@@ -74,3 +74,11 @@ func (pl *Playlist) OrderedList() []*Song {
return songs
}
+
+func (pl *Playlist) applyTimeBonus(timeBonus float64) {
+ for _, s := range *pl {
+ s.Weight += timeBonus
+ }
+ heap.Init(pl)
+ llog.DDebug("applying time bonus to the playlist")
+}
diff --git a/wrms.go b/wrms.go
index a345767..1f1332e 100644
--- a/wrms.go
+++ b/wrms.go
@@ -18,7 +18,7 @@ type Song struct {
Artist string `json:"artist"`
Source string `json:"source"`
Uri string `json:"uri"`
- Weight int `json:"weight"`
+ Weight float64 `json:"weight"`
Album string `json:"album"`
Year int `json:"year"`
index int `json:"-"` // used by heap.Interface
@@ -296,6 +296,11 @@ func (wrms *Wrms) AddSong(song Song) {
s := &wrms.Songs[len(wrms.Songs)-1]
wrms.queue.Add(s)
+ if wrms.Config.timeBonus != 0 {
+ llog.Info("Apply time bonus %v", wrms.Config.timeBonus)
+ wrms.queue.applyTimeBonus(wrms.Config.timeBonus)
+ }
+
wrms.rwlock.Unlock()
llog.Info("Added song %s (ptr=%p) to Songs", s.Uri, s)