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

55 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -euf -o pipefail
2018-03-02 04:10:08 +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 ----------------------------------------------------
# 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"
# 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"
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)"
songdir="$music_dir/$(dirname "${song}")/"
2018-03-02 04:10:08 +00:00
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" )"
# 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
[[ -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
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
notify-send -u low -t 8000 -i "$cover" "$heading" "$message"