-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
148 lines (121 loc) · 3.27 KB
/
status.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package mmpd
import (
"fmt"
"reflect"
"strconv"
"github.com/fhs/gompd/v2/mpd"
)
// Status represents the current player status.
type Status struct {
// the name of the current partition (see Partition commands)
Partition string
// 0-100 (deprecated: -1 if the volume cannot be determined)
Volume int
// 0 or 1
Repeat bool
// 0 or 1
Random bool
// 0, 1, or oneshot
Single OffOnOneshot
// 0, 1 or oneshot 13
Consume OffOnOneshot
// 31-bit unsigned integer, the playlist version number
Playlist uint32
// integer, the length of the playlist
PlaylistLength int
// play, stop, or pause
State PlayerState
// playlist song number of the current song stopped on or playing
Song int
// playlist songid of the current song stopped on or playing
SongId int
// playlist song number of the next song to be played
NextSong int
// playlist songid of the next song to be played
NextSongId int
// total time elapsed (of current playing/paused song) in seconds (deprecated, use elapsed instead)
Time int
// Total time elapsed within the current song in seconds, but with higher resolution.
Elapsed float32
// Duration of the current song in seconds.
Duration int
// instantaneous bitrate in kbps
Bitrate int
// crossfade in seconds (see Cross-Fading)
CrossFade int
// mixramp threshold in dB
MixRampDB int
// mixrampdelay in seconds
MixRampDelay int
// The format emitted by the decoder plugin during playback, format: samplerate:bits:channels. See Global Audio Format for a detailed explanation.
Audio string
// Job id
UpdatingDB string
// if there is an error, returns message here
Error string
}
func (s *Status) Equals(other *Status) bool {
return reflect.DeepEqual(s, other)
}
func ParseStatusAttrs(attrs mpd.Attrs) *Status {
status := &Status{}
for k, v := range attrs {
switch k {
case "partition":
status.Partition = v
case "volume":
status.Volume, _ = strconv.Atoi(v)
case "repeat":
status.Repeat = v == "1"
case "random":
status.Random = v == "1"
case "single":
status.Single = ParseOffOnOneshot(v)
case "consume":
status.Consume = ParseOffOnOneshot(v)
case "playlist":
if i, err := strconv.ParseUint(v, 10, 32); err == nil {
status.Playlist = uint32(i)
}
case "playlistlength":
if i, err := strconv.ParseInt(v, 10, 32); err == nil {
status.PlaylistLength = int(i)
}
case "state":
status.State = PlayerState(v)
case "song":
status.Song, _ = strconv.Atoi(v)
case "songid":
status.SongId, _ = strconv.Atoi(v)
case "nextsong":
status.NextSong, _ = strconv.Atoi(v)
case "nextsongid":
status.NextSongId, _ = strconv.Atoi(v)
case "time":
status.Time, _ = strconv.Atoi(v)
case "elapsed":
if f, err := strconv.ParseFloat(v, 32); err == nil {
status.Elapsed = float32(f)
}
case "duration":
status.Duration, _ = strconv.Atoi(v)
case "bitrate":
status.Bitrate, _ = strconv.Atoi(v)
case "xfade":
status.CrossFade, _ = strconv.Atoi(v)
case "mixrampdb":
status.MixRampDB, _ = strconv.Atoi(v)
case "mixrampdelay":
status.MixRampDelay, _ = strconv.Atoi(v)
case "audio":
status.Audio = v
case "updating_db":
status.UpdatingDB = v
case "error":
status.Error = v
default:
fmt.Printf("Unknown status attribute '%s' => '%s'\n", k, v)
}
}
return status
}