-
Notifications
You must be signed in to change notification settings - Fork 0
/
iotavx.go
61 lines (56 loc) · 1.31 KB
/
iotavx.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
57
58
59
60
61
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"regexp"
"strconv"
)
var re_irdata = regexp.MustCompile("IrAddress:[[:xdigit:]]{4}, IrData:([[:xdigit:]]{2})")
func execute(c int) {
var err error
switch c {
case code["play-pause"]:
fmt.Println("play-pause")
err = exec.Command("playerctl", "play-pause").Run()
case code["next"]:
fmt.Println("next")
err = exec.Command("playerctl", "next").Run()
case code["previous"]:
fmt.Println("previous")
err = exec.Command("playerctl", "previous").Run()
case code["seek-"]:
fmt.Println("seek-")
err = exec.Command("playerctl", "position", "10-").Run()
case code["seek+"]:
fmt.Println("seek+")
err = exec.Command("playerctl", "position", "10+").Run()
case code["stop"]:
fmt.Println("stop")
err = exec.Command("playerctl", "stop").Run()
case code["shuffle"]:
fmt.Println("shuffle")
err = exec.Command("playerctl", "shuffle").Run()
}
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
}
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "opening: %s", err)
os.Exit(1)
}
s := bufio.NewScanner(file)
for s.Scan() {
if sm := re_irdata.FindSubmatch(s.Bytes()); sm != nil && len(sm) == 2 {
c, err := strconv.ParseInt(string(sm[1]), 16, 64)
if err != nil {
continue
}
execute(int(c))
}
}
}