From de2a59ab19c99298fbebcde3e8cc53467fda491c Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 19 Aug 2022 17:37:43 -0500 Subject: [PATCH] Containing spotify listener launch to local configs; get_pid in spotify listener; Only sending spotify hooks to top bars instead of all bars --- polybar/README.md | 2 -- polybar/launch.sh | 2 ++ polybar/spotify/listener.log | 36 ++++++++++++++++++++++++++ polybar/spotify/py_spotify_listener.py | 26 +++++++++++++++---- 4 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 polybar/spotify/listener.log diff --git a/polybar/README.md b/polybar/README.md index 54d0886..b723cfb 100644 --- a/polybar/README.md +++ b/polybar/README.md @@ -1,5 +1,3 @@ Status Bar(s) https://github.com/polybar/polybar - - diff --git a/polybar/launch.sh b/polybar/launch.sh index 8269762..3dae0d1 100755 --- a/polybar/launch.sh +++ b/polybar/launch.sh @@ -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 diff --git a/polybar/spotify/listener.log b/polybar/spotify/listener.log new file mode 100644 index 0000000..1251fbd --- /dev/null +++ b/polybar/spotify/listener.log @@ -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 diff --git a/polybar/spotify/py_spotify_listener.py b/polybar/spotify/py_spotify_listener.py index 60d67d3..9565c9f 100755 --- a/polybar/spotify/py_spotify_listener.py +++ b/polybar/spotify/py_spotify_listener.py @@ -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):