New setting: Avoid playlist randomization
Some checks are pending
continuous-integration/drone/push Build is running

This commit is contained in:
nemunaire 2025-03-25 18:35:19 +01:00
commit 8cdfde856e
4 changed files with 22 additions and 7 deletions

View file

@ -23,6 +23,7 @@ type Player struct {
MaxRunTime time.Duration
MaxVolume uint16
StartVolume uint16
NoRandom bool
Stopper chan bool
currentCmd *exec.Cmd
currentCmdCh chan bool
@ -97,11 +98,12 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error
MaxRunTime: settings.MaxRunTime * time.Minute,
MaxVolume: uint16(settings.MaxVolume),
StartVolume: uint16(settings.StartVolume),
NoRandom: settings.NoRandom,
weatherTime: settings.WeatherDelay * time.Minute,
weatherAction: wact,
claironTime: settings.GongInterval * time.Minute,
claironFile: reveil.CurrentGongPath(cfg),
reverseOrder: int(time.Now().Unix()/86400)%2 == 0,
reverseOrder: !settings.NoRandom && int(time.Now().Unix()/86400)%2 == 0,
}
// Load routines
@ -131,11 +133,13 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error
p.Playlist = append(p.Playlist, track.Path)
}
log.Println("Shuffling playlist...")
// Shuffle the playlist
rand.Shuffle(len(p.Playlist), func(i, j int) {
p.Playlist[i], p.Playlist[j] = p.Playlist[j], p.Playlist[i]
})
if !p.NoRandom {
log.Println("Shuffling playlist...")
// Shuffle the playlist
rand.Shuffle(len(p.Playlist), func(i, j int) {
p.Playlist[i], p.Playlist[j] = p.Playlist[j], p.Playlist[i]
})
}
return &p, nil
}