i3blocks-config/scripts/playerctl

44 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-07-20 16:59:11 -04:00
#!/bin/bash
# Based on https://aur.archlinux.org/packages/playerctl/
INSTANCE="${BLOCK_INSTANCE}"
if [[ "${INSTANCE}" != "" ]]; then
ARGUMENTS="--player ${INSTANCE}"
ps -e | grep "${INSTANCE}" &> /dev/null
fi
if [ $? == 1 ]; then
exit 0
fi
ICON_PLAY="➤"
ICON_PAUSE="Ⅱ"
ICON_STOP="≠"
CUR_ICON=""
if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then
$(playerctl ${ARGUMENTS} previous)
elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then
$(playerctl ${ARGUMENTS} play-pause)
elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then
$(playerctl ${ARGUMENTS} next)
fi
PLAYER_STATUS=$(playerctl ${ARGUMENTS} status)
INFO_TITLE=$(playerctl ${ARGUMENTS} metadata title)
INFO_ALBUM=$(playerctl ${ARGUMENTS} metadata album)
INFO_ARTIST=$(playerctl ${ARGUMENTS} metadata artist)
if [[ "${PLAYER_STATUS}" = "Paused" ]]; then
CUR_ICON="${ICON_PAUSE}"
elif [[ "${PLAYER_STATUS}" = "Playing" ]]; then
CUR_ICON="${ICON_PLAY}"
else
CUR_ICON="${ICON_STOP}"
fi
if [[ "${INFO_TITLE}" != "" ]] && [[ "${INFO_ARTIST}" != "" ]]; then
echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}"
echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}"
fi