2019-04-07 22:18:49 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euf -o pipefail
|
2018-03-02 04:10:08 +00:00
|
|
|
|
|
|
|
# CONFIG ----------------------------------------------------
|
2019-04-07 22:18:49 +00:00
|
|
|
# This NEEDS to be the same as in mpd.conf
|
|
|
|
music_dir="$HOME/Music/Albums"
|
|
|
|
|
|
|
|
# What should the covers be resized to in pixels
|
2019-05-30 15:00:26 +00:00
|
|
|
cover_resize="150"
|
2019-04-07 22:18:49 +00:00
|
|
|
|
|
|
|
# What is the cover file called?
|
|
|
|
img_reg=".*/(cover|front|folder|art).(jpg|jpeg|png|gif)$"
|
|
|
|
|
|
|
|
# What do we want the notification to look like?
|
2018-03-02 04:10:08 +00:00
|
|
|
artist_color="##a1b56c"
|
|
|
|
song_color="##34e2e2"
|
|
|
|
|
2019-04-07 22:18:49 +00:00
|
|
|
form="<span color='$artist_color'>%artist%</span> - <span color='$song_color'>%title%</span>"
|
2019-05-30 15:00:26 +00:00
|
|
|
# END CONFIG ------------------------------------------------
|
2018-03-02 04:10:08 +00:00
|
|
|
|
|
|
|
# These are some variables we need for things to work
|
|
|
|
song="$(mpc --format %file% current)"
|
2019-04-07 22:18:49 +00:00
|
|
|
songdir="$music_dir/$(dirname "${song}")/"
|
2019-04-22 15:40:54 +00:00
|
|
|
raw_cover="/tmp/current_cover.png"
|
2019-04-29 17:32:59 +00:00
|
|
|
heading="$(mpc current -f "%album%" | sed "s:&:&:g")"
|
2018-03-02 04:10:08 +00:00
|
|
|
message="$(mpc current -f "$form" | sed "s:&:&:g" )"
|
|
|
|
|
2019-04-07 22:18:49 +00:00
|
|
|
# Is there music on?
|
2018-05-26 20:06:45 +00:00
|
|
|
[[ -z $song ]] && exit 1
|
2018-03-02 04:10:08 +00:00
|
|
|
|
2018-05-26 20:06:45 +00:00
|
|
|
# No cover if the folder isn't found
|
2019-04-07 22:18:49 +00:00
|
|
|
[[ -z "$songdir" ]] && exit 1
|
2018-03-02 04:10:08 +00:00
|
|
|
|
|
|
|
# But if it is found, look for only one of the specified files
|
2019-04-07 22:18:49 +00:00
|
|
|
cover="$(find "$songdir" -maxdepth 1 -type f -regextype egrep -regex "$img_reg" 2>/dev/null)"
|
2018-03-02 04:10:08 +00:00
|
|
|
|
2018-05-26 20:06:45 +00:00
|
|
|
# Resize the cover
|
|
|
|
if [[ -n $cover ]]; then
|
2019-04-22 15:40:54 +00:00
|
|
|
ffmpeg -hide_banner -loglevel panic -nostats -y -i "$cover" -vf scale="$cover_resize":-2 "$raw_cover"
|
|
|
|
cover="$raw_cover"
|
2018-03-02 04:10:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Send the notification
|
2019-04-07 22:18:49 +00:00
|
|
|
notify-send -u low -t 8000 -i "$cover" "$heading" "$message"
|
2019-04-22 15:40:54 +00:00
|
|
|
|
|
|
|
# add a rule to make sxiv:albumcover floating
|
2019-04-29 17:32:59 +00:00
|
|
|
#sxiv "$cover" -N albumcover -g 250x250-10-10 -bpq > /dev/null 2>&1 & pid=$!
|
2019-04-22 15:40:54 +00:00
|
|
|
# { sleep 4; kill "$pid"; } &
|