Created
October 18, 2019 17:21
-
-
Save eelfroth/9e0c7dfc7466a9a835e2e56d525cc265 to your computer and use it in GitHub Desktop.
simple cmus cover art
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/sh | |
# | |
# cmus-status-display | |
# | |
# Usage: | |
# in cmus command ":set status_display_program=cmus-status-display" | |
# | |
# This scripts is executed by cmus when status changes: | |
# cmus-status-display key1 val1 key2 val2 ... | |
# | |
# All keys contain only chars a-z. Values are UTF-8 strings. | |
# | |
# Keys: status file url artist album discnumber tracknumber title date | |
# - status (stopped, playing, paused) is always given | |
# - file or url is given only if track is 'loaded' in cmus | |
# - other keys/values are given only if they are available | |
# | |
set_bg() { | |
## gnome | |
gsettings set org.gnome.desktop.background picture-uri "file://$1" | |
gsettings set org.gnome.desktop.background picture-options "scaled" | |
## other WMs | |
#feh --bg-max "$1" | |
} | |
while test $# -ge 2 | |
do | |
eval _$1='$2' | |
shift | |
shift | |
done | |
if test "$_status" != "playing"; then | |
set_bg "$DEFAULT_BACKGROUND" | |
elif test -n "$_file"; then | |
## look for cover art in folder | |
cd "$(dirname "$_file")" | |
images=$(find . -maxdepth 1 -name 'cover.*' -o -name '*.png' -o -name '*.jpg' -o -name '*.jpeg') | |
if test -z "$images"; then | |
## extract cover from file | |
ffmpeg -i "$_file" cover.jpg | |
images="cover.jpg" | |
fi | |
cover=$(echo "$images" | head -n 1) | |
cover=$(readlink -f "$cover") | |
echo "$cover" | |
## set desktop background | |
set_bg "$cover" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment