Add support for Spotify running in a Linux namespace
When running blockify without any arguments, I get:
Traceback (most recent call last):
File "/usr/bin/blockify", line 11, in <module>
load_entry_point('blockify==3.6.3', 'console_scripts', 'blockify')()
File "/usr/lib/python3.6/site-packages/blockify/cli.py", line 605, in main
cli.start()
File "/usr/lib/python3.6/site-packages/blockify/cli.py", line 225, in start
self.toggle_mute(2)
File "/usr/lib/python3.6/site-packages/blockify/cli.py", line 376, in toggle_mute
self.mutemethod(mode)
File "/usr/lib/python3.6/site-packages/blockify/cli.py", line 459, in pulsesink_mute
index, playback_state, muted_value = self.extract_pulse_sink_status(pacmd_out)
File "/usr/lib/python3.6/site-packages/blockify/cli.py", line 444, in extract_pulse_sink_status
pid = [k for k in idxd.keys() if k in self.spotify_pids][0]
IndexError: list index out of range
During the run:
idxd.keys() = [2]
self.spotify_pids = [30019, 30006, 29987, 29984]
So obviously, pid is empty and pid[0] is out of bounds, thus the IndexError.
I ran pacmd list-sink-inputs and noticed that application.process.id of Spotify is 2, not the PID of any Spotify-related process.
The problem is that pacmd list-sink-inputs reports the PID from the view of the respective process, Spotify in this case. Since Spotify is put into a separate namespace by flatpak, it reports PID 2, (PID 1 is of the namespace init process, see man 7 pid_namespaces). I don't know whether to consider this a bug in pulseaudio... but certainly, blockify must be PID namespace-aware and use global PIDs instead of namespace-specific ones.
I confirm this issue on my machine.
I confirm as well.