Add community scripts for i3blocks
This commit is contained in:
50
.local/bin/i3scripts/contrib/playerctl
Executable file
50
.local/bin/i3scripts/contrib/playerctl
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user