Last active
December 3, 2018 20:17
-
-
Save Jipok/cd939b0bbbb57cf4c674c3012b198150 to your computer and use it in GitHub Desktop.
Show music info(with cover) for mpd. Will show gray cover, when paused
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
expireTime="3200" | |
mpddir="$HOME/Music/" | |
defaultimage="$HOME/music.png" | |
update_cover() { | |
path=$mpddir$(mpc -f %file% current) | |
album=$(mpc -f %file% current) | |
ffmpeg -loglevel quiet -y -i "$path" /tmp/cover | |
if [[ $? -ne 0 ]] ; then | |
covers="$(find "$(dirname "$path")" -type d -exec find {} -maxdepth 1 -type f -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\)" \; )" | |
src="$(echo -n "$covers" | head -n1)" | |
if [[ -f $src ]] ; then | |
/bin/cp "$src" /tmp/cover | |
else | |
cp "$defaultimage" /tmp/cover | |
fi | |
fi | |
} | |
while true; do | |
mpc -q || exit 1 | |
[[ $(mpc idle) = "player" ]] || continue | |
pkill -SIGRTMIN+2 i3blocks | |
update_cover | |
length=$(mpc status | sed '2!D ; s/\[.* //') | |
status=$(mpc status | grep -o '\[.*\]' | tr -d "[]") | |
title=$(mpc status -f "[[<b>%title%</b>]|[%file%]]\n \n[<i>By</i>: %Artist%\n][<i>Fr</i>: %Album%\n]" | head -n -3) | |
category="mpd"; | |
if [[ ${status} = "paused" ]]; then | |
category="mpd-paused" | |
convert "/tmp/cover" -colorspace Gray "/tmp/cover" | |
fi | |
notify-send --expire-time="${expireTime}" -c ${category} -i "/tmp/cover" "MPD" \ | |
"$(echo "${title}\n""<i>Status</i>: ${length}";)" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment