Add Hyprland stuff

This commit is contained in:
2023-11-27 23:31:36 +01:00
parent 06b642ae28
commit 5017ee7099
9 changed files with 143 additions and 123 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
readonly ENABLED=''
readonly DISABLED=' '
readonly ENABLED=''
readonly DISABLED='\uf1f6' # nf-fa-bell_slash
dbus-monitor path='/org/freedesktop/Notifications',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged' --profile |
while read -r _; do
PAUSED="$(dunstctl is-paused)"

View File

@ -61,16 +61,6 @@ class PlayerManager:
def get_players(self) -> List[Player]:
return self.manager.props.players
def write_output(self, text, player):
logger.debug(f"Writing output: {text}")
output = {"text": text,
"class": "custom-" + player.props.player_name,
"alt": player.props.player_name}
sys.stdout.write(json.dumps(output) + "\n")
sys.stdout.flush()
def clear_output(self):
sys.stdout.write("\n")
sys.stdout.flush()
@ -102,32 +92,29 @@ class PlayerManager:
current_player = self.get_first_playing_player()
if current_player is not None:
self.on_metadata_changed(current_player, current_player.props.metadata)
else:
else:
self.clear_output()
def on_metadata_changed(self, player, metadata, _=None):
logger.debug(f"Metadata changed for player {player.props.player_name}")
player_name = player.props.player_name
artist = player.get_artist()
title = player.get_title()
track_info = ""
if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]:
track_info = "Advertisement"
elif artist is not None and title is not None:
track_info = f"{artist} - {title}"
else:
track_info = title
if track_info:
if player.props.status == "Playing":
track_info = "" + track_info
else:
track_info = "" + track_info
data = {
"player_name": player.props.player_name,
"player_icon": "" if player.props.player_name == "spotify" else "",
"artist": player.get_artist(),
"title": player.get_title(),
"status": player.props.status,
"status_icon": "" if player.props.status == "Paused" else "",
"class": [
player.props.player_name.lower(),
player.props.status.lower()
],
"text": f"{player.get_artist()} - {player.get_title()}",
}
# only print output if no other player is playing
current_playing = self.get_first_playing_player()
if current_playing is None or current_playing.props.player_name == player.props.player_name:
self.write_output(track_info, player)
sys.stdout.write(json.dumps(data) + "\n")
sys.stdout.flush()
else:
logger.debug(f"Other player {current_playing.props.player_name} is playing, skipping")