♻️ Song struct to hold song logic
This commit is contained in:
parent
c845d08293
commit
16933ce0fa
4 changed files with 50 additions and 7 deletions
|
|
@ -21,12 +21,11 @@ Cobra is a CLI library for Go that empowers applications.
|
|||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conn, _ := mpd.GetConn()
|
||||
curr, _ := conn.CurrentSong()
|
||||
for k, v := range curr {
|
||||
curr, _ := mpd.GetCurrent()
|
||||
for k, v := range curr.Attrs {
|
||||
fmt.Println(k, ":", v)
|
||||
}
|
||||
sticks, _ := mpd.StickersGetFor(curr["file"])
|
||||
sticks, _ := curr.GetStickers()
|
||||
for _, v := range sticks {
|
||||
fmt.Println(v.Name, "*:", v.Value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package mpd
|
||||
|
||||
import (
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
)
|
||||
import "github.com/fhs/gompd/v2/mpd"
|
||||
|
||||
var conn *mpd.Client
|
||||
var connerror error
|
||||
|
|
|
|||
13
mpd/current.go
Normal file
13
mpd/current.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package mpd
|
||||
|
||||
func GetCurrent() (*Song, error) {
|
||||
if connerror != nil {
|
||||
return nil, connerror
|
||||
}
|
||||
curr, err := conn.CurrentSong()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newSong(curr), nil
|
||||
}
|
||||
33
mpd/song.go
Normal file
33
mpd/song.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package mpd
|
||||
|
||||
import "github.com/fhs/gompd/v2/mpd"
|
||||
|
||||
type Song struct {
|
||||
Path string
|
||||
Attrs mpd.Attrs
|
||||
stickers []mpd.Sticker
|
||||
}
|
||||
|
||||
func newSong(attrs mpd.Attrs) *Song {
|
||||
return &Song{
|
||||
Path: attrs["file"],
|
||||
Attrs: attrs,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Song) GetStickers() ([]mpd.Sticker, error) {
|
||||
if s.stickers != nil {
|
||||
return s.stickers, nil
|
||||
}
|
||||
|
||||
if connerror != nil {
|
||||
return nil, connerror
|
||||
}
|
||||
|
||||
sticks, err := StickersGetFor(s.Path)
|
||||
s.stickers = sticks
|
||||
|
||||
return s.stickers, err
|
||||
}
|
||||
|
||||
// github.com/akrennmair/slice
|
||||
Loading…
Add table
Add a link
Reference in a new issue