make getDecode more useful
This commit is contained in:
@@ -77,7 +77,7 @@ func (j *Jukebox) Start(sockPath string, mpvExtraArgs []string) error {
|
||||
}
|
||||
|
||||
var mpvVersionStr string
|
||||
if err := j.getDecode(&mpvVersionStr, "mpv-version"); err != nil {
|
||||
if err := getDecode(j.conn, &mpvVersionStr, "mpv-version"); err != nil {
|
||||
return fmt.Errorf("get mpv version: %w", err)
|
||||
}
|
||||
if major, minor, patch := parseMPVVersion(mpvVersionStr); major == 0 && minor < 34 {
|
||||
@@ -104,7 +104,7 @@ func (j *Jukebox) GetPlaylist() ([]string, error) {
|
||||
defer lockr(&j.mu)()
|
||||
|
||||
var playlist mpvPlaylist
|
||||
if err := j.getDecode(&playlist, "playlist"); err != nil {
|
||||
if err := getDecode(j.conn, &playlist, "playlist"); err != nil {
|
||||
return nil, fmt.Errorf("get playlist: %w", err)
|
||||
}
|
||||
var items []string
|
||||
@@ -118,7 +118,7 @@ func (j *Jukebox) SetPlaylist(items []string) error {
|
||||
defer lock(&j.mu)()
|
||||
|
||||
var playlist mpvPlaylist
|
||||
if err := j.getDecode(&playlist, "playlist"); err != nil {
|
||||
if err := getDecode(j.conn, &playlist, "playlist"); err != nil {
|
||||
return fmt.Errorf("get playlist: %w", err)
|
||||
}
|
||||
current, currentIndex := find(playlist, func(item mpvPlaylistItem) bool {
|
||||
@@ -260,7 +260,7 @@ func (j *Jukebox) GetVolumePct() (float64, error) {
|
||||
defer lockr(&j.mu)()
|
||||
|
||||
var volume float64
|
||||
if err := j.getDecode(&volume, "volume"); err != nil {
|
||||
if err := getDecode(j.conn, &volume, "volume"); err != nil {
|
||||
return 0, fmt.Errorf("get volume: %w", err)
|
||||
}
|
||||
return volume, nil
|
||||
@@ -279,11 +279,11 @@ func (j *Jukebox) GetStatus() (*Status, error) {
|
||||
defer lockr(&j.mu)()
|
||||
|
||||
var status Status
|
||||
_ = j.getDecode(&status.Position, "time-pos") // property may not always be there
|
||||
_ = j.getDecode(&status.GainPct, "volume") // property may not always be there
|
||||
_ = getDecode(j.conn, &status.Position, "time-pos") // property may not always be there
|
||||
_ = getDecode(j.conn, &status.GainPct, "volume") // property may not always be there
|
||||
|
||||
var playlist mpvPlaylist
|
||||
_ = j.getDecode(&playlist, "playlist")
|
||||
_ = getDecode(j.conn, &playlist, "playlist")
|
||||
|
||||
status.CurrentIndex = slices.IndexFunc(playlist, func(pl mpvPlaylistItem) bool {
|
||||
return pl.Current
|
||||
@@ -298,7 +298,7 @@ func (j *Jukebox) GetStatus() (*Status, error) {
|
||||
status.CurrentFilename = playlist[status.CurrentIndex].Filename
|
||||
|
||||
var paused bool
|
||||
_ = j.getDecode(&paused, "pause") // property may not always be there
|
||||
_ = getDecode(j.conn, &paused, "pause") // property may not always be there
|
||||
status.Playing = !paused
|
||||
|
||||
return &status, nil
|
||||
@@ -324,8 +324,8 @@ func (j *Jukebox) Quit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *Jukebox) getDecode(dest any, property string) error {
|
||||
raw, err := j.conn.Get(property)
|
||||
func getDecode(conn *mpvipc.Connection, dest any, property string) error {
|
||||
raw, err := conn.Get(property)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get property: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user