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

View File

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