dot/.local/bin/i3scripts/contrib/playerctl

51 lines
912 B
Plaintext
Raw Normal View History

2021-12-20 21:49:21 +00:00
#!/usr/bin/env bash
################################
# Shows info from media players.
#
# TODO: make output format configurable
#
# Dependencies:
# - playerctl
#
# @return {String}: Current media info
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
# Exit if no player found
players=$(playerctl -l)
if [[ ! $players ]]; then exit 0; fi
artist=$(playerctl metadata artist)
title=$(playerctl metadata title)
album=$(playerctl metadata album)
state=$(playerctl status)
if [[ "$title" ]]; then
# Make icon mapping
declare -A icons
icons["Playing"]=""
icons["Paused"]=""
icons["Stopped"]=""
# Determine which icon to use
icon=${icons[$state]}
full="$title"
if [[ "$artist" ]]; then full="$artist - $full"; fi
short="$full $icon"
if [[ "$album" ]]; then full="$full [$album]"; fi
full="$full $icon"
fi
echo $full
echo $short
exit $status