mpris-status: Don't fail when no media players are present
This commit is contained in:
parent
382884f420
commit
a8887a7f9e
@ -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 = [Player(dbus_interface_info={"dbus_uri": uri}) for uri in get_players_uri()]
|
||||||
|
|
||||||
players.sort(key=status_key)
|
players.sort(key=status_key)
|
||||||
active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri)
|
if len(players) > 0:
|
||||||
print(
|
active_player_id = get_player_id_from_uri(players[0]._dbus_interface_info.uri)
|
||||||
|
print(
|
||||||
"<txt>"
|
"<txt>"
|
||||||
+ (f"[{ len(players) }] " if len(players) > 1 else "")
|
+ (f"[{ len(players) }] " if len(players) > 1 else "")
|
||||||
+ format_player(players[0], short=True)
|
+ format_player(players[0], short=True)
|
||||||
+ "</txt>"
|
+ "</txt>"
|
||||||
)
|
)
|
||||||
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>")
|
||||||
|
Loading…
Reference in New Issue
Block a user