From 0844b917dc2d8c077668fc18f21aebd7f3a2645f Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 31 Mar 2022 20:01:13 +0400 Subject: [PATCH] Now last played songs are consist of time, listeners and song name combined with artist. --- internal/radio/icecast.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 81dfe57..db3bd42 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -38,9 +38,9 @@ type IcecastStatus struct { } type Song struct { - Time string `json:"time"` - Artist string `json:"artist"` - Title string `json:"title"` + Time string `json:"time"` + Listeners string `json:"listeners"` + Song string `json:"song"` } func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) { @@ -91,7 +91,7 @@ func IcecastLastSong(playlistPath string) (Song, error) { func lastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { songs := make([]Song, 0) - cmd := fmt.Sprintf("tail -n%d %s | head -n-1 | cut -d'|' -f1,4", lastNSongs+1, playlistPath) + cmd := fmt.Sprintf("tail -n%d %s | head -n-1 | cut -d'|' -f1,3,4", lastNSongs+1, playlistPath) out, err := exec.Command("bash", "-c", cmd).CombinedOutput() if err != nil { return songs, err @@ -101,19 +101,18 @@ func lastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { return songs, nil } - songs_ := strings.Split(string(out), "\n") + lines := strings.Split(string(out), "\n") - for _, song := range songs_ { + for _, song := range lines { ts := strings.Split(song, "|") if len(ts) <= 1 { continue } tim, _ := time.Parse("02/Jan/2006:15:04:05 -0700", ts[0]) - at := strings.Split(ts[1], " - ") songs = append(songs, Song{ - Time: tim.Format("15:04-0700"), - Artist: at[0], - Title: at[1]}) + Time: tim.Format("15:04-0700"), + Listeners: ts[1], + Song: ts[2]}) } return songs, nil