The mistake is that it replaces
pacmd list-sink-inputs
with
pactl list sink-inputs
as the latter provides a similar functionality which also works with Pipewire, but has a completely different output, which the script has to parse.
Example outputs from both PA and PW systems to parse
PW:
Sink Input #1158
Driver: PipeWire
Owner Module: n/a
Client: 1157
Sink: 700
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: front-left: 581 / 1% / -123,14 dB, front-right: 581 / 1% / -123,14 dB
balance 0,00
Buffer Latency: 0 usec
Sink Latency: 0 usec
Resample method: PipeWire
Properties:
client.api = "pipewire-pulse"
pulse.server.type = "unix"
application.name = "spotify"
application.process.id = "27389"
application.process.user = "laco"
application.process.host = "DellG3"
application.process.binary = "spotify"
application.language = "hu_HU.UTF-8"
window.x11.display = ":1"
application.process.machine_id = "94739ab9c6c446f2bf361f5351421995"
media.role = "music"
media.name = "Spotify"
node.rate = "1/44100"
node.latency = "8192/44100"
stream.is-live = "true"
node.name = "spotify"
node.want-driver = "true"
node.autoconnect = "true"
media.class = "Stream/Output/Audio"
port.group = "stream.0"
adapt.follower.spa-node = ""
object.register = "false"
factory.id = "7"
clock.quantum-limit = "8192"
node.loop.name = "data-loop.0"
library.name = "audioconvert/libspa-audioconvert"
client.id = "125"
object.id = "104"
object.serial = "1158"
pulse.attr.maxlength = "4194304"
pulse.attr.tlength = "640064"
pulse.attr.prebuf = "0"
pulse.attr.minreq = "7056"
node.driver-id = "91"
module-stream-restore.id = "sink-input-by-media-role:music"
PA:
1 sink input(s) available.
index: 9
driver: <protocol-native.c>
flags: START_CORKED
state: RUNNING
sink: 0 <alsa_output.pci-0000_00_1f.3.analog-stereo>
volume: front-left: 44394 / 68% / -10.15 dB, front-right: 44394 / 68% / -10.15 dB
balance 0.00
muted: no
current latency: 1023.38 ms
requested latency: 980.00 ms
sample spec: float32le 2ch 44100Hz
channel map: front-left,front-right
Sztereó
resample method: copy
module: 11
client: 118 <spotify>
properties:
media.role = "music"
media.name = "Spotify"
application.name = "spotify"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "35"
application.process.id = "42360"
application.process.user = "moncsi"
application.process.host = "moncsi-laptopja"
application.process.binary = "spotify"
application.language = "hu_HU.UTF-8"
window.x11.display = ":0"
application.process.machine_id = "8aee7cb39dc24c17922ea866a7f090e6"
application.process.session_id = "2"
module-stream-restore.id = "sink-input-by-media-role:music"
So a totally different parsing is needed for a PW system.
If you look at the PA output, just parse for “index:”, and any line containing “spotify” after that: the result is the value after “index:”, hence the cut -d: -f2.
It’s simple.
But for PW, we need to parse for node.name, which has to be “spotify”, then what we need really is the object.serial from the same (!!!) node.
This one seems to work reliably (just the relevant snippet from the script):
# Get the client index of Spotify
spotify=$(pactl list sink-inputs | while read line; do
if [[ -n $(echo $line | grep "node.name") ]]; then
name=$(echo $line | awk -F'"' '{print $2}')
if [ "$name" != "spotify" ]; then
name=""
fi
fi
if [ -n "$name" ]; then
if [[ -n $(echo $line | grep "object.serial") ]]; then
index=$(echo $line | awk -F'"' '{print $2}')
echo $index
exit
fi
fi
done)
How does that compare to the GPT’s conversion? (Relevant snippet):
# Get the client index of Spotify using pactl for PipeWire (should work fine)
spotify=$(pactl list sink-inputs | while read line; do
[[ -n $(echo $line | grep "index:") ]] && index=$line
[[ -n $(echo $line | grep Spotify) ]] && echo $index && exit
done | cut -d: -f2)
“Should work fine”, yes should, but doesn’t ![]()
I still tinker with that script, unti it works fine in every aspect I need (still there’s some fiddling to do).