-
Notifications
You must be signed in to change notification settings - Fork 0
/
seek.go
56 lines (51 loc) · 1.08 KB
/
seek.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package control
import (
"strconv"
"github.com/blang/mpv"
"github.com/robertgzr/xap/mp"
"github.com/urfave/cli"
)
var seekCommand = cli.Command{
Name: "seek",
ArgsUsage: "AMOUNT [MODE]",
Category: "CONTROL",
Usage: "Move playback to a different point in the current file",
SkipFlagParsing: true,
Action: func(ctx *cli.Context) error {
var seekMode = mpv.SeekModeRelative
c, err := mp.Connect(ctx)
if err != nil {
return err
}
arg := ctx.Args().First()
switch arg {
case "-h":
fallthrough
case "--help":
return cli.ShowCommandHelp(ctx, "seek")
case "":
return nil
default:
val, err := strconv.Atoi(arg)
if err != nil {
return err
}
if ctx.NArg() >= 2 {
seekMode = ctx.Args().Get(1)
}
return c.Seek(val, seekMode)
}
},
}
var from0Command = cli.Command{
Name: "from0",
Category: "CONTROL",
Usage: "Restart playback of the current file",
Action: func(ctx *cli.Context) error {
c, err := mp.Connect(ctx)
if err != nil {
return err
}
return c.Seek(0, mpv.SeekModeAbsolute)
},
}