Now last played songs are consist of time, listeners and song name combined with artist.
This commit is contained in:
parent
93f50458ec
commit
0844b917dc
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user