//Updates the library func (l *library) update() error { var conn *mpd.Client fmt.Println("Connecting to MPD") conn, err := mpd.Dial("tcp", "127.0.0.1:6600") if err != nil { fmt.Println("Error: could not connect to MPD for lib update") return errors.New("Could not connect to MPD!") } defer conn.Close() _, err = conn.Update("") if err != nil { fmt.Println("Error: could not update library!") return err } //Let the update happen time.Sleep(2 * time.Second) songs, err := conn.ListAllInfo("/") if err != nil { fmt.Println("Error: could not retrieve new library!") return err } l.library = songs return nil }
//Create a new queue func newLibrary() *library { var conn *mpd.Client fmt.Println("Connecting to MPD") conn, err := mpd.Dial("tcp", "127.0.0.1:6600") if err != nil { fmt.Println("Error: could not connect to MPD, exiting") os.Exit(1) } defer conn.Close() songs, err := conn.ListAllInfo("/") if err != nil { fmt.Println("Error: could not connect to MPD, exiting") os.Exit(1) } shuffle(songs) return &library{ library: songs, } }