mpvfs

9P file server for controlling mpv playback

git clone https://git.8pit.net/mpvfs.git

 1package playlistfs
 2
 3import (
 4	"fmt"
 5	"strconv"
 6)
 7
 8type Control struct {
 9	Name string
10	Arg  *int
11}
12
13func CtlCmd(buf []byte) (*Control, error) {
14	var cmd Control
15
16	fields, err := parseFields(buf, 1, 2)
17	if err != nil {
18		return nil, err
19	}
20
21	for _, field := range fields {
22		for i := 0; i < len(field); i++ {
23			data := field[i]
24			switch i {
25			case 0:
26				cmd.Name = data
27			case 1:
28				arg, err := strconv.Atoi(data)
29				if err != nil {
30					return nil, err
31				}
32				cmd.Arg = &arg
33			}
34		}
35	}
36
37	return &cmd, nil
38}
39
40func (c *Control) String() string {
41	return fmt.Sprintf("%s %d", c.Name, *c.Arg)
42}