aboutsummaryrefslogtreecommitdiff
path: root/wrms.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-07-16 13:30:35 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-07-16 14:17:17 +0200
commita9b6aa1652166eb7f871735ba6833e2bdb888e50 (patch)
tree35f820f0af629ba62e4c5e41a28e487351581603 /wrms.go
parent53d46753d0c4b312df9c0151089eae3891aa4add (diff)
downloadWRMS-a9b6aa1652166eb7f871735ba6833e2bdb888e50.tar.gz
WRMS-a9b6aa1652166eb7f871735ba6833e2bdb888e50.zip
add more song info and preparations for advanced search
Diffstat (limited to 'wrms.go')
-rw-r--r--wrms.go34
1 files changed, 27 insertions, 7 deletions
diff --git a/wrms.go b/wrms.go
index 9371d93..056848c 100644
--- a/wrms.go
+++ b/wrms.go
@@ -19,13 +19,29 @@ type Song struct {
Source string `json:"source"`
Uri string `json:"uri"`
Weight int `json:"weight"`
+ Album string `json:"album"`
+ Year int `json:"year"`
index int `json:"-"` // used by heap.Interface
Upvotes map[uuid.UUID]struct{} `json:"-"`
Downvotes map[uuid.UUID]struct{} `json:"-"`
}
func NewSong(title, artist, source, uri string) Song {
- return Song{title, artist, source, uri, 0, 0, map[uuid.UUID]struct{}{}, map[uuid.UUID]struct{}{}}
+ return Song{
+ Title: title,
+ Artist: artist,
+ Source: source,
+ Uri: uri,
+ Upvotes: map[uuid.UUID]struct{}{},
+ Downvotes: map[uuid.UUID]struct{}{},
+ }
+}
+
+func NewDetailedSong(title, artist, source, uri, album string, year int) Song {
+ s := NewSong(title, artist, source, uri)
+ s.Album = album
+ s.Year = year
+ return s
}
func NewSongFromJson(data []byte) (Song, error) {
@@ -165,7 +181,7 @@ type Wrms struct {
queue Playlist
CurrentSong atomic.Pointer[Song]
Player Player
- Playing bool
+ playing bool
Config Config
eventId atomic.Uint64
}
@@ -197,7 +213,7 @@ func (wrms *Wrms) initConn(conn *Connection) error {
conn.nextEvent = curEventId + 1
initialCmds := []Event{}
- if wrms.Playing {
+ if wrms.playing {
var songs []Song
if currentSong := wrms.CurrentSong.Load(); currentSong != nil {
songs = []Song{*currentSong}
@@ -261,7 +277,7 @@ func (wrms *Wrms) Broadcast(ev Event) {
func (wrms *Wrms) AddSong(song Song) {
wrms.rwlock.Lock()
- startPlayingAgain := wrms.Playing && wrms.CurrentSong.Load() == nil
+ startPlayingAgain := wrms.playing && wrms.CurrentSong.Load() == nil
wrms.Songs = append(wrms.Songs, song)
s := &wrms.Songs[len(wrms.Songs)-1]
wrms.queue.Add(s)
@@ -338,7 +354,7 @@ func (wrms *Wrms) _next() {
cmd := "next"
// We are playing -> start playing the next song
- if wrms.Playing {
+ if wrms.playing {
wrms.Player.Play(next)
cmd = "play"
}
@@ -351,10 +367,10 @@ func (wrms *Wrms) _next() {
func (wrms *Wrms) PlayPause() {
wrms.rwlock.Lock()
// Toggle the playback state
- wrms.Playing = !wrms.Playing
+ wrms.playing = !wrms.playing
// Wrms was playing -> pause the player
- if !wrms.Playing {
+ if !wrms.playing {
wrms.Player.Pause()
wrms.rwlock.Unlock()
wrms.Broadcast(newNotification("pause"))
@@ -452,3 +468,7 @@ func (wrms *Wrms) AdjustSongWeight(connId uuid.UUID, songUri string, vote string
break
}
}
+
+func (wrms *Wrms) Search(pattern map[string]string) chan []Song {
+ return wrms.Player.Search(pattern)
+}