mpris-status: Don't fail when no media players are present

This commit is contained in:
Adam Goldsmith 2023-04-25 18:16:07 -04:00
parent 382884f420
commit a8887a7f9e
1 changed files with 13 additions and 10 deletions

View File

@ -89,13 +89,16 @@ def status_icon(player: Player) -> str:
players = [Player(dbus_interface_info={"dbus_uri": uri}) for uri in get_players_uri()]
players.sort(key=status_key)
active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri)
print(
"<txt>"
+ (f"[{ len(players) }] " if len(players) > 1 else "")
+ format_player(players[0], short=True)
+ "</txt>"
)
print(f"<txtclick>playerctl --player={ active_player_id } play-pause</txtclick>")
print(f"<icon>{ status_icon(players[0]) }</icon>")
print("<tool>" + "\n".join(format_player(player) for player in players) + "</tool>")
if len(players) > 0:
active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri)
print(
"<txt>"
+ (f"[{ len(players) }] " if len(players) > 1 else "")
+ format_player(players[0], short=True)
+ "</txt>"
)
print(f"<txtclick>playerctl --player={ active_player_id } play-pause</txtclick>")
print(f"<icon>{ status_icon(players[0]) }</icon>")
print("<tool>" + "\n".join(format_player(player) for player in players) + "</tool>")
else:
print("<txt>No media players</txt>")