2019-04-07 22:18:49 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euf -o pipefail
|
2018-03-02 04:10:08 +00:00
|
|
|
|
2019-04-07 22:18:49 +00:00
|
|
|
# Hacked together by deadguy from various bits and pieces from manpages,
|
|
|
|
# stackexchange, github, r/unixporn, and the awesome help from people in
|
|
|
|
# #bash, #zsh, and #archlinux-newbie on freenode.
|
|
|
|
|
|
|
|
# Steal it, use it, mod it, share it, love it.
|
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-04-14 15:53:12 +00:00
|
|
|
cover_resize="250"
|
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"
|
|
|
|
album_color="##ad7fa8"
|
|
|
|
song_color="##34e2e2"
|
|
|
|
|
2019-04-07 22:18:49 +00:00
|
|
|
title="<span color='$album_color' weight='bold'>%album%</span>"
|
|
|
|
form="<span color='$artist_color'>%artist%</span> - <span color='$song_color'>%title%</span>"
|
|
|
|
|
2018-03-02 04:10:08 +00:00
|
|
|
# END CONFIG ----------------------------------------------------
|
|
|
|
|
|
|
|
# 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}")/"
|
2018-03-02 04:10:08 +00:00
|
|
|
temp_path="/tmp/current_cover.png"
|
2018-08-15 14:40:52 +00:00
|
|
|
heading="$(mpc current -f "$title" | 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
|
2018-03-02 04:10:08 +00:00
|
|
|
ffmpeg -hide_banner -loglevel panic -nostats -y -i "$cover" -vf scale="$cover_resize":-2 "$temp_path"
|
|
|
|
cover="$temp_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Send the notification
|
2019-04-07 22:18:49 +00:00
|
|
|
notify-send -u low -t 8000 -i "$cover" "$heading" "$message"
|