Containing spotify listener launch to local configs; get_pid in spotify listener; Only sending spotify hooks to top bars instead of all bars

This commit is contained in:
Noah L. Schrick 2022-08-19 17:37:43 -05:00
parent ebe8fb1657
commit de2a59ab19
4 changed files with 59 additions and 7 deletions

View File

@ -1,5 +1,3 @@
Status Bar(s)
https://github.com/polybar/polybar

View File

@ -4,6 +4,7 @@
# Terminate already running bar instances
killall -q polybar
#killall -q py_spotify_listener.py
# Wait until the processes have been shut down
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
@ -12,6 +13,7 @@ for m in $(polybar --list-monitors | cut -d":" -f1); do
MONITOR=$m polybar top -c ~/.config/polybar/config-top.ini > ~/.config/polybar/top.log &
MONITOR=$m polybar bottom -c ~/.config/polybar/config-bottom.ini > ~/.config/polybar/bottom.log &
done
/usr/bin/env python3 ~/.config/polybar/spotify/py_spotify_listener.py > ~/.config/polybar/spotify/listener.log &
exit 0

View File

@ -0,0 +1,36 @@
Successfully wrote action '#playpause.hook.1' to PID 924
Successfully wrote action '#playpause.hook.1' to PID 926
Successfully wrote action '#playpause.hook.1' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#playpause.hook.2' to PID 924
Successfully wrote action '#playpause.hook.2' to PID 926
Successfully wrote action '#playpause.hook.2' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#playpause.hook.1' to PID 924
Successfully wrote action '#playpause.hook.1' to PID 926
Successfully wrote action '#playpause.hook.1' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#playpause.hook.2' to PID 924
Successfully wrote action '#playpause.hook.2' to PID 926
Successfully wrote action '#playpause.hook.2' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928
Successfully wrote action '#playpause.hook.1' to PID 924
Successfully wrote action '#playpause.hook.1' to PID 926
Successfully wrote action '#playpause.hook.1' to PID 928
Successfully wrote action '#spotify.hook.1' to PID 924
Successfully wrote action '#spotify.hook.1' to PID 926
Successfully wrote action '#spotify.hook.1' to PID 928

View File

@ -5,6 +5,7 @@
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from os import system
from os import popen
from gi.repository import GLib
import dbus
@ -39,6 +40,12 @@ class Test(dbus.service.Object):
raise Exception('FAIL!')
def get_top_pid():
pids = popen("pgrep -f 'polybar top'").read().split('\n')
while('') in pids:
pids.remove('')
return pids
def catchall_handler(*args, **kwargs):
"""Catch all handler.
Catch and print information about all singals.
@ -58,21 +65,30 @@ def event_handler(*args, **kwargs):
"""arg[1] contains metadata"""
"""arg[1][1] contains PlaybackStatus"""
data = unwrap(args)
pids = get_top_pid()
print("Top Bar PIDs:", pids)
#if 'spotify' in data[1]['Metadata']['mpris:trackid']:
if 'PlaybackStatus' in data[1]:
if data[1]['PlaybackStatus'] == "Playing":
print("Music is playing")
""" Send IPC hook 2 to all bars for module playpause """
#system("polybar-msg hook playpause 2")
system("polybar-msg action '#playpause.hook.1'")
""" Send IPC hook 2 to top bars for module playpause """
for pid in pids:
#system("polybar-msg hook playpause 2")
cmd = "polybar-msg -p " + pid + " action '#playpause.hook.1'"
system(cmd)
if data[1]['PlaybackStatus'] == "Paused":
print("Music is paused.")
""" Send IPC hook 3 to all bars module playpause """
#system("polybar-msg hook playpause 3")
system("polybar-msg action '#playpause.hook.2'")
for pid in pids:
cmd = "polybar-msg -p " + pid + " action '#playpause.hook.2'"
system(cmd)
""" Send IPC hook 2 to all bars for module spotify """
#system("polybar-msg hook spotify 2")
system("polybar-msg action '#spotify.hook.1'")
for pid in pids:
cmd = "polybar-msg -p " + pid + " action '#spotify.hook.1'"
#system("polybar-msg action '#spotify.hook.1'")
system(cmd)
def unwrap(val):
if isinstance(val, dbus.ByteArray):