diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-31 10:23:22 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-31 10:23:22 +0200 |
| commit | 78dc143e4585a3ab5a4d173f50571b4842a4e347 (patch) | |
| tree | 3c0526a95237b2d853590c3c001dde854fc6a28f /wrms.go | |
| parent | c162743200466b6d8d9e52d5666e1220c9cf67a2 (diff) | |
| download | WRMS-78dc143e4585a3ab5a4d173f50571b4842a4e347.tar.gz WRMS-78dc143e4585a3ab5a4d173f50571b4842a4e347.zip | |
implement initial loading of spotify playlists
Playlist can now be added to the initial play queue with the
-playlists command line flag or the playlists yaml key in the
config file.
To load a spotify playlist the link obtained when sharing the playlist
from spotify is used.
Diffstat (limited to 'wrms.go')
| -rw-r--r-- | wrms.go | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -54,6 +54,11 @@ func NewWrms(config Config) *Wrms { wrms := Wrms{} wrms.Config = config wrms.Player = NewMpvPlayer(&wrms, config.Backends) + + if len(wrms.Config.Playlists) > 0 { + wrms.loadPlaylists(wrms.Config.Playlists) + } + return &wrms } @@ -134,6 +139,11 @@ func (wrms *Wrms) Broadcast(ev Event) { }) } +func (wrms *Wrms) _addSong(song *Song) { + wrms.Songs = append(wrms.Songs, song) + wrms.queue.Add(song) +} + func (wrms *Wrms) AddSong(song *Song) { wrms.rwlock.Lock() @@ -144,14 +154,12 @@ func (wrms *Wrms) AddSong(song *Song) { wrms.queue.applyTimeBonus(wrms.Config.timeBonus) } - wrms.Songs = append(wrms.Songs, song) - s := wrms.Songs[len(wrms.Songs)-1] - wrms.queue.Add(s) + wrms._addSong(song) ev := wrms.newEvent("add", []*Song{song}) wrms.rwlock.Unlock() - llog.Info("Added song %s (ptr=%p) to Songs", s.Uri, s) + llog.Info("Added song %s (ptr=%p) to Songs", song.Uri, song) wrms.Broadcast(ev) if startPlayingAgain { @@ -343,3 +351,17 @@ func (wrms *Wrms) AdjustSongWeight(connId uuid.UUID, songUri string, vote string func (wrms *Wrms) Search(pattern map[string]string) chan []*Song { return wrms.Player.Search(pattern) } + +func (wrms *Wrms) loadPlaylists(playlists []string) { + for _, playlist := range playlists { + wrms.appendPlaylist(playlist) + } +} + +func (wrms *Wrms) appendPlaylist(playlist string) { + songs := wrms.Player.LoadPlaylist(playlist) + + for _, song := range songs { + wrms._addSong(song) + } +} |
