Instantly share code, notes, and snippets.

@vlevit /mnuc
Last active May 12, 2018

Embed
What would you like to do?
Script intended to be executed from ncmpcpp (execute_on_song_change preference) running from urxvt to set album cover as background image
#!/bin/bash
# Script intended to be executed from ncmpcpp (execute_on_song_change
# preference) running from urxvt to set album cover as background image
# Copyright (c) 2013 Vyacheslav Levit
# Licensed under The MIT License: http://opensource.org/licenses/MIT
MUSIC_DIR=$HOME/Music
DARKEN=50 # 0 - original image colors, 100 - absolutely black background
TMP=/tmp
COVER=/tmp/cover.jpg
IM_ARGS=(-limit memory 32mb -limit map 64mb)
function reset_background
{
# is there any better way?
printf "\e]20;;100x100+1000+1000\a"
}
{
album="$(mpc --format %album% current)"
file="$(mpc --format %file% current)"
album_dir="${file%/*}"
[[ -z "$album_dir" ]] && exit 1
album_dir="$MUSIC_DIR/$album_dir"
covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)" \; )"
src="$(echo -n "$covers" | head -n1)"
darkenimg="$TMP/darken.jpg"
rm -f "$COVER" "$darkenimg"
if [[ -n "$src" ]] ; then
light="$((100 - $DARKEN))"
convert "${IM_ARGS[@]}" "$src" -fill "gray${light}" +level ${light}%,${light}% \
+matte "$darkenimg"
composite "${IM_ARGS[@]}" "$darkenimg" -compose Multiply "$src" "$COVER"
if [[ -f "$COVER" ]] ; then
bgcolor=$(convert "${IM_ARGS[@]}" "$COVER" -scale 1x1 -format \
'%[fx:int(255*r+.5)] %[fx:int(255*g+.5)] %[fx:int(255*b+.5)]' info:-)
for c in $bgcolor ; do
bghex=$bghex/$(printf %02x $c)
done
bghex=${bghex:1}
printf "\e]11;rgb:${bghex}\a"
printf "\e]708;rgb:${bghex}\a"
printf "\e]20;${COVER};100x100+50+50:op=keep-aspect\a"
else
reset_background
fi
else
reset_background
fi
} &
@alesandar

This comment has been minimized.

Copy link

alesandar commented Sep 29, 2015

The following error comes up when I try to run the script within URxvt:
composite: magick/effect.c:4440: UnsharpMaskImageChannel: Assertion image != (const Image *) ((void *)0)' failed.
/usr/local/bin/coverart.sh: line 55: 8898 Aborted (core dumped) composite "${IM_ARGS[@]}" "$darkenimg" -compose Multiply "$src" "$COVER"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment