-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.go
65 lines (50 loc) · 1.24 KB
/
functions.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
62
63
64
65
package main
import (
"fmt"
"os/exec"
"strings"
)
func pause(player string) {
cmd := exec.Command("playerctl", fmt.Sprintf("--player=%s", player), "pause")
cmd.Run()
}
func play(player string) {
cmd := exec.Command("playerctl", fmt.Sprintf("--player=%s", player), "play")
cmd.Run()
}
func toggleOrStart(player string) {
s := status(player)
cmds := make(map[string]string)
cmds["YoutubeMusic"] = "youtube-music"
if s != "Playing" && s != "Paused" {
toExec := player
if val, exists := cmds[player]; exists {
toExec = val
}
cmd := exec.Command(toExec)
cmd.Start()
return
}
cmd := exec.Command("playerctl", fmt.Sprintf("--player=%s", player), "play-pause")
cmd.Start()
}
func status(player string) string {
cmd := exec.Command("playerctl", fmt.Sprintf("--player=%s", player), "status")
out, err := cmd.Output()
if err != nil {
return "Inactive"
}
return strings.TrimSpace(string(out))
}
func metadata(player, data, format string) string {
params := []string{fmt.Sprintf("--player=%s", player), "metadata", data}
if format != "" {
params = append(params, "-f", format)
}
cmd := exec.Command("playerctl", params...)
out, err := cmd.CombinedOutput()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}