~hnaguski/aart

9914c5c742b1e90d6d78e3a84827cf0c94a070df — Henry Naguski 1 year, 10 months ago df4660d
simplify first_start and add safe handling of mpd being killed
1 files changed, 13 insertions(+), 8 deletions(-)

M aart
M aart => aart +13 -8
@@ 82,13 82,9 @@ first_start() {
	pgrep mpd >/dev/null || exit 1

	# check status of mpd, if it's stopped then wait for mpd to start playing a
	# song maybe only check for playing, I leave mpd paused quite often
	mpc status | grep -o "playing\|paused" > /dev/null || file=$(mpc -q current --wait -f %file%)

	# get current song's filename relative to mpd's music directory
	file=$(mpc current -f %file%)

	set_art "$file"
	# song and set the art. Maybe only check for playing, I leave mpd paused
	# quite often
	mpc status | grep -o "playing\|paused" > /dev/null || set_art "$(mpc -q	current --wait -f %file%)"

	# open image viewer on the art and store the pid
	sxiv -b art & viewer_pid=$!


@@ 106,6 102,15 @@ trap close_script INT

while true;
do
	set_art "$(mpc -q current --wait -f %file%)"
	old_song="$(mpc current -f %file%)"

	# wait for a player event, if mpd closes then exit
	mpc -q idle player > /dev/null || close_script

	# make sure viewer is still open
	check_pid

	# only change the art if the song changes
	new_song="$(mpc current -f %file%)"
	[ "$old_song" != "$new_song" ] && set_art "$new_song"
done