Skip to content

Commit d8a853a

Browse files
authored
Merge pull request #1 from catchamonkey/more_commands
Added "stop" and "previous" commands, renamed skip to next
2 parents f151eb5 + db039f2 commit d8a853a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

sonos-controller.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ var sonosIP string
1212
var command string
1313

1414
var commands = map[string]func(){
15-
"play": play,
16-
"pause": pause,
17-
"skip": skip,
15+
"play": play,
16+
"pause": pause,
17+
"next": next,
18+
"stop": stop,
19+
"previous": previous,
1820
}
1921

2022
func init() {
2123
flag.StringVar(&sonosIP, "sonos-ip", "0.0.0.0", "The IP Address of the target Sonos device")
22-
flag.StringVar(&command, "command", "play", "The command to execute, play, pause, skip (next)")
24+
flag.StringVar(&command, "command", "play", "The command to execute, must be one of play, pause, next, stop, previous")
2325
}
2426

2527
func main() {
2628
flag.Parse()
2729
if commands[command] != nil {
2830
commands[command]()
31+
} else {
32+
fmt.Println("Invalid command provided, see -help")
2933
}
3034
}
3135

@@ -37,10 +41,18 @@ func play() {
3741
exec("Play")
3842
}
3943

40-
func skip() {
44+
func next() {
4145
exec("Next")
4246
}
4347

48+
func stop() {
49+
exec("Stop")
50+
}
51+
52+
func previous() {
53+
exec("Previous")
54+
}
55+
4456
func exec(cmd string) {
4557
log.Println("Executing", cmd)
4658
body := fmt.Sprintf("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:%v xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:%v></s:Body></s:Envelope>", cmd, cmd)

0 commit comments

Comments
 (0)