Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a02d8ffc5 | |||
e5f6becf97 | |||
86c9dc0cc5 | |||
e425b08ef8 | |||
f413f97824 | |||
5eb15eb7a5 | |||
3e68bbda29 | |||
bca0e0bf3a | |||
4fef37ceca | |||
0e44626c13 | |||
195b00abf2 | |||
cb478e8b4d | |||
0e93c0cafb | |||
ddb1e3af17 |
21
commands.go
21
commands.go
@ -2,7 +2,6 @@ package mpvipc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,27 +23,41 @@ 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)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Ping(socket string) bool {
|
||||||
|
_, err := GetPID(socket)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
func IsReady(ctx context.Context, socket string) <-chan bool {
|
func IsReady(ctx context.Context, socket string) <-chan bool {
|
||||||
out := make(chan bool, 1)
|
out := make(chan bool, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
|
|
||||||
|
if Ping(socket) {
|
||||||
|
out <- true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(100 * time.Millisecond)
|
ticker := time.NewTicker(100 * time.Millisecond)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
conn, err := net.Dial("unix", socket)
|
if Ping(socket) {
|
||||||
if err == nil {
|
|
||||||
defer conn.Close()
|
|
||||||
out <- true
|
out <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
8
go.mod
8
go.mod
@ -1,5 +1,7 @@
|
|||||||
module git.milar.in/milarin/mpvipc
|
module git.tordarus.net/tordarus/mpvipc
|
||||||
|
|
||||||
go 1.21.5
|
go 1.23
|
||||||
|
|
||||||
require git.milar.in/milarin/channel v0.1.1
|
toolchain go1.24.4
|
||||||
|
|
||||||
|
require git.tordarus.net/tordarus/channel v0.1.19
|
||||||
|
4
go.sum
4
go.sum
@ -1,2 +1,2 @@
|
|||||||
git.milar.in/milarin/channel v0.1.1 h1:s8+BdiOMmuRUDmChQ2i4G5GWsDCK9tKNHt1knLJx9zM=
|
git.tordarus.net/tordarus/channel v0.1.19 h1:d9xnSwFyvBh4B1/82mt0A7Gpm2nIZJTc+9ceJMIOu5Q=
|
||||||
git.milar.in/milarin/channel v0.1.1/go.mod h1:We83LTI8S7u7II3pD+A2ChCDWJfCkcBUCUqii9HjTtM=
|
git.tordarus.net/tordarus/channel v0.1.19/go.mod h1:8/dWFTdGO7g4AeSZ7cF6GerkGbe9c4dBVMVDBxOd9m4=
|
||||||
|
8
playlist_entry.go
Normal file
8
playlist_entry.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package mpvipc
|
||||||
|
|
||||||
|
type PlaylistEntry struct {
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
Current bool `json:"current"`
|
||||||
|
Playing bool `json:"playing"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
}
|
41
props_get.go
41
props_get.go
@ -9,14 +9,18 @@ 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVolume(socket string) (float64, error) {
|
||||||
|
return GetProperty[float64](socket, "volume")
|
||||||
|
}
|
||||||
|
|
||||||
func GetFilename(socket string) (string, error) {
|
func GetFilename(socket string) (string, error) {
|
||||||
return GetProperty[string](socket, "filename")
|
return GetProperty[string](socket, "filename")
|
||||||
}
|
}
|
||||||
@ -45,6 +49,14 @@ func GetFileFormat(socket string) (string, error) {
|
|||||||
return GetProperty[string](socket, "file-format")
|
return GetProperty[string](socket, "file-format")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPlaylist(socket string) ([]PlaylistEntry, error) {
|
||||||
|
return GetProperty[[]PlaylistEntry](socket, "playlist")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPlaylistPosition(socket string) (int, error) {
|
||||||
|
return GetProperty[int](socket, "playlist-pos")
|
||||||
|
}
|
||||||
|
|
||||||
func GetDuration(socket string) (time.Duration, error) {
|
func GetDuration(socket string) (time.Duration, error) {
|
||||||
durationInSeconds, err := GetProperty[float64](socket, "duration")
|
durationInSeconds, err := GetProperty[float64](socket, "duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -54,6 +66,15 @@ func GetDuration(socket string) (time.Duration, error) {
|
|||||||
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDemuxerCacheTime(socket string) (time.Duration, error) {
|
||||||
|
cacheInSeconds, err := GetProperty[float64](socket, "demuxer-cache-time")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Duration(cacheInSeconds * float64(time.Second)), nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetPercentPos(socket string) (float64, error) {
|
func GetPercentPos(socket string) (float64, error) {
|
||||||
return GetProperty[float64](socket, "percent-pos")
|
return GetProperty[float64](socket, "percent-pos")
|
||||||
}
|
}
|
||||||
@ -76,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")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,18 +141,26 @@ 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) (bool, error) {
|
||||||
|
return GetProperty[bool](socket, "loop-file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetLoopPlaylist(socket string) (bool, error) {
|
||||||
|
return GetProperty[bool](socket, "loop-playlist")
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.milar.in/milarin/channel"
|
"git.tordarus.net/tordarus/channel"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ObserveEndOfFile(ctx context.Context, socket string) (<-chan string, error) {
|
func ObserveEndOfFile(ctx context.Context, socket string) (<-chan string, error) {
|
||||||
|
24
props_set.go
24
props_set.go
@ -3,17 +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 {
|
||||||
|
return SetProperty(socket, "volume", volume)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetPlaylistPosition(socket string, index int) error {
|
||||||
|
return SetProperty(socket, "playlist-pos", index)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLoopSong(socket string, loopSong bool) error {
|
||||||
|
return SetProperty(socket, "loop-song", loopSong)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLoopPlaylist(socket string, loopPlaylist bool) error {
|
||||||
|
return SetProperty(socket, "loop-playlist", loopPlaylist)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"git.milar.in/milarin/channel"
|
"git.tordarus.net/tordarus/channel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
|
Reference in New Issue
Block a user