-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.go
79 lines (67 loc) · 1.24 KB
/
actions.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
mpd "github.com/jteeuwen/go-pkg-mpd"
)
func action(args []string, conn *Conn) {
if len(args) == 1 {
switch args[0] {
case "pause":
conn.Lock()
conn.Pause(true)
conn.Unlock()
case "play":
conn.Lock()
conn.Pause(false)
conn.Unlock()
case "toggle", "t":
conn.Lock()
conn.Toggle()
conn.Unlock()
case "status", "stat", "s":
status(conn)
case "next", "n":
conn.Lock()
conn.Next()
conn.Unlock()
case "prev", "previous", "p":
conn.Lock()
conn.Previous()
conn.Unlock()
}
}
}
func status(conn *Conn) {
conn.RLock()
defer conn.RUnlock()
status, _ := conn.Status()
if status.State != mpd.Stopped {
song, err := conn.Current()
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Now Playing: ")
file := song["file"]
title := song["Title"]
artist := song["Artist"]
album := song["Album"]
if title == "" {
fmt.Print(file)
} else {
fmt.Print(title)
if artist != "" {
fmt.Printf(" - %s", artist)
}
if album != "" {
fmt.Printf(" (%s)", album)
}
}
if status.State == mpd.Paused {
fmt.Print(" [Paused]")
}
fmt.Println()
}
} else {
fmt.Println("Nothing playing.")
}
}