#!/bin/sh

if [ -z "${1:-}" ]; then
	playerctl --player="$(cat ~/.cache/euandreh/mpris-player.txt)" play-pause
fi

if   [ "$(playerctl --player="$(cat ~/.cache/euandreh/mpris-player.txt)" status)" = 'Paused' ]; then
	cat ~/.cache/euandreh/mpris-player.txt >> ~/.cache/euandreh/mpris-player-xmobar.txt
elif [ "$(playerctl --player="$(cat ~/.cache/euandreh/mpris-player.txt)" status)" = 'Playing' ]; then
	printf '%s: %s\n' \
		"$(cat ~/.cache/euandreh/mpris-player.txt)" \
		"$(playerctl --player="$(cat ~/.cache/euandreh/mpris-player.txt)" metadata xesam:title)" \
		>> ~/.cache/euandreh/mpris-player-xmobar.txt
fi
