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/tapa

57 lines
2.0 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?
title="<span color='$artist_color' weight='bold'>%artist%</span>"
form="<span color='$song_color'>%title%</span> - <span color='$album_color'>%album%</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)"
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"
heading="$(mpc current -f "$title" | sed "s:&:&amp;:g")"
2018-03-02 04:10:08 +00:00
message="$(mpc current -f "$form" | sed "s:&:&amp;:g" )"
2018-05-26 20:06:45 +00:00
# Is there music on
[[ -z $song ]] && exit 1
2018-03-02 04:10:08 +00:00
2018-05-26 20:06:45 +00:00
# Where to look for album covers
if [[ -d "$dir" ]] ; then
2018-03-02 04:10:08 +00:00
album_dir="$dir"
elif [[ -z "$album_dir" ]] ; then
album_dir="$music_dir/$album/"
else
album_dir="$music_dir/$albart/$album/"
fi
2018-05-26 20:06:45 +00:00
# No cover if the folder isn't found
[[ -z "$album_dir" ]] && exit 1
2018-03-02 04:10:08 +00:00
# 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)"
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
dunstify -a MPD -r 1337 -u low -t 8000 -i "$cover" "$heading" "$message"