1
0

Now last played songs are consist of time, listeners and song name combined with artist.

This commit is contained in:
Alexander Andreev 2022-03-31 20:01:13 +04:00
parent 93f50458ec
commit 0844b917dc
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -38,9 +38,9 @@ type IcecastStatus struct {
} }
type Song struct { type Song struct {
Time string `json:"time"` Time string `json:"time"`
Artist string `json:"artist"` Listeners string `json:"listeners"`
Title string `json:"title"` Song string `json:"song"`
} }
func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) { func IcecastGetStatus(icecastURL string) (*IcecastStatus, error) {
@ -91,7 +91,7 @@ func IcecastLastSong(playlistPath string) (Song, error) {
func lastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) { func lastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) {
songs := make([]Song, 0) 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() out, err := exec.Command("bash", "-c", cmd).CombinedOutput()
if err != nil { if err != nil {
return songs, err return songs, err
@ -101,19 +101,18 @@ func lastPlayedSongs(lastNSongs int, playlistPath string) ([]Song, error) {
return songs, nil 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, "|") ts := strings.Split(song, "|")
if len(ts) <= 1 { if len(ts) <= 1 {
continue continue
} }
tim, _ := time.Parse("02/Jan/2006:15:04:05 -0700", ts[0]) tim, _ := time.Parse("02/Jan/2006:15:04:05 -0700", ts[0])
at := strings.Split(ts[1], " - ")
songs = append(songs, Song{ songs = append(songs, Song{
Time: tim.Format("15:04-0700"), Time: tim.Format("15:04-0700"),
Artist: at[0], Listeners: ts[1],
Title: at[1]}) Song: ts[2]})
} }
return songs, nil return songs, nil