51 lines
		
	
	
		
			912 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			912 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/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
 |