mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[scripts/playerctl-simple-menu] sort players which are currently playing something higher
This commit is contained in:
parent
e2d21d085c
commit
7d7a4b106b
1 changed files with 32 additions and 8 deletions
|
@ -31,6 +31,12 @@ PLAYER_ICON_NAME_FIXES = {
|
||||||
"chrome": "google-chrome",
|
"chrome": "google-chrome",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLAYER_PLAYBACK_STATUS_EMOJIS = {
|
||||||
|
Playerctl.PlaybackStatus.PLAYING: "\u25B6",
|
||||||
|
Playerctl.PlaybackStatus.PAUSED: "\u23F8",
|
||||||
|
Playerctl.PlaybackStatus.STOPPED: "\u23F9",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def humanize_duration(duration):
|
def humanize_duration(duration):
|
||||||
minutes, seconds = divmod(math.floor(duration), 60)
|
minutes, seconds = divmod(math.floor(duration), 60)
|
||||||
|
@ -163,19 +169,37 @@ def iter_actions_for_player(player):
|
||||||
|
|
||||||
root_menu = Gtk.Menu()
|
root_menu = Gtk.Menu()
|
||||||
|
|
||||||
player_names = sorted(
|
player_names = Playerctl.list_players()
|
||||||
Playerctl.list_players(),
|
|
||||||
key=lambda player_name: (
|
if len(player_names) > 0:
|
||||||
|
players = []
|
||||||
|
for player_name in player_names:
|
||||||
|
player = Playerctl.Player.new_from_name(player_name)
|
||||||
|
players.append(
|
||||||
|
{
|
||||||
|
"player": player,
|
||||||
|
"player_name": player_name,
|
||||||
|
"sorting_key": (
|
||||||
|
player.props.playback_status != Playerctl.PlaybackStatus.PLAYING,
|
||||||
-PLAYER_NAME_PRIORITIES.get(player_name.name, 0),
|
-PLAYER_NAME_PRIORITIES.get(player_name.name, 0),
|
||||||
player_name.instance,
|
player_name.instance,
|
||||||
),
|
),
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
players = sorted(
|
||||||
|
players, key=lambda player_and_meta: player_and_meta["sorting_key"]
|
||||||
|
)
|
||||||
|
|
||||||
if len(player_names) > 0:
|
for player_and_meta in players:
|
||||||
for player_name in player_names:
|
player_name = player_and_meta["player_name"]
|
||||||
player = Playerctl.Player.new_from_name(player_name)
|
player = player_and_meta["player"]
|
||||||
|
|
||||||
player_menu_item = Gtk.ImageMenuItem.new_with_label(player_name.instance)
|
player_menu_item = Gtk.ImageMenuItem.new_with_label(
|
||||||
|
"{} [{}]".format(
|
||||||
|
player_name.instance,
|
||||||
|
PLAYER_PLAYBACK_STATUS_EMOJIS[player.props.playback_status],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
player_icon_name = PLAYER_ICON_NAME_FIXES.get(
|
player_icon_name = PLAYER_ICON_NAME_FIXES.get(
|
||||||
player_name.name, player_name.name
|
player_name.name, player_name.name
|
||||||
|
|
Loading…
Reference in a new issue