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

@ -39,8 +39,8 @@ type IcecastStatus struct {
type Song struct {
Time string `json:"time"`
Artist string `json:"artist"`
Title string `json:"title"`
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]})
Listeners: ts[1],
Song: ts[2]})
}
return songs, nil