dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/bin/cover

51 lines
2.1 KiB
Plaintext
Raw Normal View History

2018-03-02 04:10:08 +00:00
#!/bin/bash
# Hacked together from various bits and pieces from github, r/unixporn, and the awesome help from people in #bash, #zsh, and #archlinux-newbie on freenode.
# This script assumes your music library is organized like so:
# $music_dir/artist/album
# Steal it, use it, mod it, share it.
# CONFIG ----------------------------------------------------
music_dir="$HOME/Music/Albums" # This needs to be the same as in mpd.conf
cover_resize="100" # What should the covers be resized to
img_reg=".*/(cover|front|folder|art).(jpg|jpeg|png|gif)$" # What is the cover file called?
artist_color="##a1b56c"
album_color="##ad7fa8"
song_color="##34e2e2"
# What do we want the notification to look like?
form="\n<b>Artist:</b>\t<span color='$artist_color'>%artist%</span>\n<b>Track:</b>\t<span color='$song_color'>%title%</span>\n<b>Album:</b>\t<span color='$album_color'>%album%</span>"
# END CONFIG ----------------------------------------------------
# These are some variables we need for things to work
song="$(mpc --format %file% current)"
album="$(mpc --format %album% current)"
artist="$(mpc --format %artist% current)"
albart="$(mpc --format %albumartist% current)"
dir="$music_dir/$artist/$album/"
temp_path="/tmp/current_cover.png"
message="$(mpc current -f "$form" | sed "s:&:&amp;:g" )"
[[ -z $song ]] && exit 1 # Is there music on
if [[ -d "$dir" ]] ; then # Where to look for album covers
album_dir="$dir"
elif [[ -z "$album_dir" ]] ; then
album_dir="$music_dir/$album/"
else
album_dir="$music_dir/$albart/$album/"
fi
[[ -z "$album_dir" ]] && exit 1 # No cover if the folder isn't found
# But if it is found, look for only one of the specified files
cover="$(find "$album_dir" -maxdepth 1 -type f -regextype egrep -regex "$img_reg" 2>/dev/null)"
if [[ -n $cover ]]; then # Resize the cover
ffmpeg -hide_banner -loglevel panic -nostats -y -i "$cover" -vf scale="$cover_resize":-2 "$temp_path"
cover="$temp_path"
fi
# Send the notification
dunstify -a MPD -r 1337 -u low -t 8000 -i "$cover" " ♫ Now Playing ♫ " "$message"