diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-21 15:56:34 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-21 15:56:34 +0200 |
| commit | d1558cf352f24c311b8505661143973d11d9edba (patch) | |
| tree | ea5d01b8644f51603ef04e7e6187baca908cb7ad | |
| parent | 9cb08df11d7446357c5d480d08d256b906d4988e (diff) | |
| download | WRMS-d1558cf352f24c311b8505661143973d11d9edba.tar.gz WRMS-d1558cf352f24c311b8505661143973d11d9edba.zip | |
backend: support an incremental time bonus
| -rw-r--r-- | TODO.md | 1 | ||||
| -rw-r--r-- | config.go | 1 | ||||
| -rw-r--r-- | main.go | 2 | ||||
| -rw-r--r-- | playlist.go | 8 | ||||
| -rw-r--r-- | wrms.go | 7 |
5 files changed, 18 insertions, 1 deletions
@@ -18,6 +18,7 @@ - [X] support incremental search results - [X] distinguish different search queries - [X] do not apply obsolete events +- [ ] support timeBonus ## Web Backend @@ -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 { @@ -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") +} @@ -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) |
