From a599e996c72414cd6877610776c3c01f5177ba1e Mon Sep 17 00:00:00 2001 From: undg Date: Tue, 11 Feb 2025 10:18:40 +0000 Subject: [PATCH] add monitor and monitored to source status --- pactl/pactl.go | 17 +++++++++++------ pactl/types.go | 12 +++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pactl/pactl.go b/pactl/pactl.go index 2cf3426..8215746 100644 --- a/pactl/pactl.go +++ b/pactl/pactl.go @@ -137,19 +137,24 @@ func parseSources(output string) Source { descRe, _ := regexp.Compile(`Description: (.+)`) volumeRe, _ := regexp.Compile(`Volume: .+?(\d+)%`) muteRe, _ := regexp.Compile(`Mute: (yes|no)`) + monitorRe, _ := regexp.Compile(`Monitor of Sink: (.+)`) // n/a or name of the Sink id, _ := strconv.Atoi(idRe.FindStringSubmatch(output)[1]) name := nameRe.FindStringSubmatch(output)[1] desc := descRe.FindStringSubmatch(output)[1] volume, _ := strconv.Atoi(volumeRe.FindStringSubmatch(output)[1]) - mute := muteRe.FindStringSubmatch(output)[1] == "yes" + muted := muteRe.FindStringSubmatch(output)[1] == "yes" + monitored := monitorRe.FindStringSubmatch(output)[1] == "n/a" + monitor := monitorRe.FindStringSubmatch(output)[1] return Source{ - ID: id, - Name: name, - Label: desc, - Volume: volume, - Muted: mute, + ID: id, + Name: name, + Label: desc, + Volume: volume, + Muted: muted, + Monitor: monitor, + Monitored: monitored, } } diff --git a/pactl/types.go b/pactl/types.go index 867fa89..b527107 100644 --- a/pactl/types.go +++ b/pactl/types.go @@ -18,11 +18,13 @@ type Output struct { } type Source struct { - ID int `json:"id" doc:"The id of the source. Same as name"` - Name string `json:"name" doc:"The name of the source. Same as id"` - Label string `json:"label" doc:"Human-readable label for the source"` - Volume int `json:"volume" doc:"Current volume level of the source"` - Muted bool `json:"muted" doc:"Whether the source is muted"` + ID int `json:"id" doc:"Unique numeric identifier of the source"` + Name string `json:"name" doc:"Unique string identifier of the source"` + Label string `json:"label" doc:"Human-readable label for the source"` + Volume int `json:"volume" doc:"Current volume level of the source"` + Muted bool `json:"muted" doc:"Whether the source is muted"` + Monitor string `json:"monitor" doc:"Name of monitor source capturing this source's output"` + Monitored bool `json:"monitored" doc:"Whether source is being monitored"` } type App struct {