Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
96013554e0 | |||
6fc6cec502 | |||
95d2a1e1a4 | |||
0a02d8ffc5 | |||
e5f6becf97 | |||
86c9dc0cc5 | |||
e425b08ef8 | |||
f413f97824 | |||
5eb15eb7a5 |
@ -23,6 +23,12 @@ func LoadFile(socket string, file string, flags LoadFileFlag) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShufflePlaylist(socket string) error {
|
||||||
|
cmd := &Command{Command: []interface{}{"playlist-shuffle"}}
|
||||||
|
_, err := SendCommand[any](socket, cmd)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func Quit(socket string) error {
|
func Quit(socket string) error {
|
||||||
cmd := &Command{Command: []interface{}{"quit"}}
|
cmd := &Command{Command: []interface{}{"quit"}}
|
||||||
_, err := SendCommand[any](socket, cmd)
|
_, err := SendCommand[any](socket, cmd)
|
||||||
|
74
loopstate.go
Normal file
74
loopstate.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package mpvipc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LoopState is an integer representing the amount of loops.
|
||||||
|
// Specially handled values are LoopInfinite, LoopForced and LoopInvalid.
|
||||||
|
// There is also the alias value LoopNo which is equal to 1
|
||||||
|
type LoopState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
LoopInfinite LoopState = -2
|
||||||
|
LoopForced LoopState = -1
|
||||||
|
LoopInvalid LoopState = 0
|
||||||
|
LoopNo LoopState = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
func Loop(amount int) LoopState {
|
||||||
|
if amount < int(LoopInfinite) {
|
||||||
|
amount = int(LoopInfinite)
|
||||||
|
} else if amount == 0 {
|
||||||
|
amount = int(LoopNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoopState(amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseLoopState(value any) (LoopState, error) {
|
||||||
|
switch v := value.(type) {
|
||||||
|
case string:
|
||||||
|
switch strings.ToLower(v) {
|
||||||
|
case "no":
|
||||||
|
return LoopNo, nil
|
||||||
|
case "inf":
|
||||||
|
return LoopInfinite, nil
|
||||||
|
case "force":
|
||||||
|
return LoopForced, nil
|
||||||
|
}
|
||||||
|
case int:
|
||||||
|
return Loop(v), nil
|
||||||
|
case float64:
|
||||||
|
return Loop(int(v)), nil
|
||||||
|
case bool:
|
||||||
|
if v {
|
||||||
|
return LoopInfinite, nil
|
||||||
|
} else {
|
||||||
|
return LoopNo, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoopInvalid, fmt.Errorf("could not parse value as valid loop state: %#v (type: %#v)", value, reflect.TypeOf(value).Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s LoopState) String() string {
|
||||||
|
switch s {
|
||||||
|
case LoopInfinite:
|
||||||
|
return "inf"
|
||||||
|
case LoopNo:
|
||||||
|
return "no"
|
||||||
|
case LoopForced:
|
||||||
|
return "force"
|
||||||
|
default:
|
||||||
|
return strconv.Itoa(int(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepeatAgain returns true if the song will be repeated again after the end of the song is reached
|
||||||
|
func (s LoopState) RepeatAgain() bool {
|
||||||
|
return s == LoopInfinite || s == LoopForced || s > LoopNo
|
||||||
|
}
|
34
props_get.go
34
props_get.go
@ -9,11 +9,11 @@ func GetDisplayNames(socket string) ([]string, error) {
|
|||||||
return GetProperty[[]string](socket, "display-names")
|
return GetProperty[[]string](socket, "display-names")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsFullscreen(socket string) (bool, error) {
|
func GetFullscreen(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "fullscreen")
|
return GetProperty[bool](socket, "fullscreen")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPaused(socket string) (bool, error) {
|
func GetPaused(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "pause")
|
return GetProperty[bool](socket, "pause")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ func GetPlaylist(socket string) ([]PlaylistEntry, error) {
|
|||||||
return GetProperty[[]PlaylistEntry](socket, "playlist")
|
return GetProperty[[]PlaylistEntry](socket, "playlist")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPlaylistPosition(socket string, index int) error {
|
func GetPlaylistPosition(socket string) (int, error) {
|
||||||
return SetProperty(socket, "playlist-pos", index)
|
return GetProperty[int](socket, "playlist-pos")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDuration(socket string) (time.Duration, error) {
|
func GetDuration(socket string) (time.Duration, error) {
|
||||||
@ -97,7 +97,7 @@ func GetTimeRemaining(socket string) (time.Duration, error) {
|
|||||||
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSeeking(socket string) (bool, error) {
|
func GetSeeking(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "seeking")
|
return GetProperty[bool](socket, "seeking")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,18 +141,36 @@ func GetChapterList(socket string) ([]Chapter, error) {
|
|||||||
return GetProperty[[]Chapter](socket, "chapter-list")
|
return GetProperty[[]Chapter](socket, "chapter-list")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSeekable(socket string) (bool, error) {
|
func GetSeekable(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "seekable")
|
return GetProperty[bool](socket, "seekable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPartiallySeekable(socket string) (bool, error) {
|
func GetPartiallySeekable(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "partially-seekable")
|
return GetProperty[bool](socket, "partially-seekable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPlaybackAborted(socket string) (bool, error) {
|
func GetPlaybackAborted(socket string) (bool, error) {
|
||||||
return GetProperty[bool](socket, "playback-abort")
|
return GetProperty[bool](socket, "playback-abort")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPropertyList(socket string) ([]string, error) {
|
func GetPropertyList(socket string) ([]string, error) {
|
||||||
return GetProperty[[]string](socket, "property-list")
|
return GetProperty[[]string](socket, "property-list")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLoopFile(socket string) (LoopState, error) {
|
||||||
|
value, err := GetProperty[any](socket, "loop-file")
|
||||||
|
if err != nil {
|
||||||
|
return LoopInvalid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParseLoopState(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetLoopPlaylist(socket string) (LoopState, error) {
|
||||||
|
value, err := GetProperty[any](socket, "loop-playlist")
|
||||||
|
if err != nil {
|
||||||
|
return LoopInvalid, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParseLoopState(value)
|
||||||
|
}
|
||||||
|
22
props_set.go
22
props_set.go
@ -3,21 +3,33 @@ package mpvipc
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
func SetFullscreen(socket string, fullscreen bool) error {
|
func SetFullscreen(socket string, fullscreen bool) error {
|
||||||
return SetProperty[bool](socket, "fullscreen", fullscreen)
|
return SetProperty(socket, "fullscreen", fullscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPause(socket string, pause bool) error {
|
func SetPause(socket string, pause bool) error {
|
||||||
return SetProperty[bool](socket, "pause", pause)
|
return SetProperty(socket, "pause", pause)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTimePos(socket string, timePos time.Duration) error {
|
func SetTimePos(socket string, timePos time.Duration) error {
|
||||||
return SetProperty[float64](socket, "time-pos", float64(timePos)/float64(time.Second))
|
return SetProperty(socket, "time-pos", float64(timePos)/float64(time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPercentPos(socket string, percentPos float64) error {
|
func SetPercentPos(socket string, percentPos float64) error {
|
||||||
return SetProperty[float64](socket, "percent-pos", percentPos)
|
return SetProperty(socket, "percent-pos", percentPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetVolume(socket string, volume float64) error {
|
func SetVolume(socket string, volume float64) error {
|
||||||
return SetProperty[float64](socket, "volume", volume)
|
return SetProperty(socket, "volume", volume)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetPlaylistPosition(socket string, index int) error {
|
||||||
|
return SetProperty(socket, "playlist-pos", index)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLoopFile(socket string, loopFile LoopState) error {
|
||||||
|
return SetProperty(socket, "loop-file", loopFile.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLoopPlaylist(socket string, loopPlaylist LoopState) error {
|
||||||
|
return SetProperty(socket, "loop-playlist", loopPlaylist.String())
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func SendCommand[T any](socket string, cmd *Command) (*Response[T], error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetProperty[T any](socket string, propertyName string) (T, error) {
|
func GetProperty[T any](socket string, propertyName string) (T, error) {
|
||||||
cmd := &Command{[]interface{}{"get_property", propertyName}}
|
cmd := &Command{[]any{"get_property", propertyName}}
|
||||||
resp, err := SendCommand[T](socket, cmd)
|
resp, err := SendCommand[T](socket, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *new(T), err
|
return *new(T), err
|
||||||
@ -61,7 +61,7 @@ func GetProperty[T any](socket string, propertyName string) (T, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetProperty[T any](socket string, propertyName string, propertyValue T) error {
|
func SetProperty[T any](socket string, propertyName string, propertyValue T) error {
|
||||||
cmd := &Command{[]interface{}{"set_property", propertyName, propertyValue}}
|
cmd := &Command{[]any{"set_property", propertyName, propertyValue}}
|
||||||
resp, err := SendCommand[T](socket, cmd)
|
resp, err := SendCommand[T](socket, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user