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/.config/ncmpcpp/mpdartify

81 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# A simple notify script for now-playing songs on mpd. This script uses
# notify-send and mpc to get the current song information.
# Requirements (* = optional)
# - mpd
# - mpc
# - notify-send (libnotify)
# * ImageMagick (convert)
# Author : Wolfgang Mueller
# You can use, edit and redistribute this script in any way you like.
# (Just make sure not to hurt any kittens)
#
# https://github.com/vehk/mpdnotify
# make sure env var is setup correctly
[[ -z "$XDG_CONFIG_HOME" ]] && \
XDG_CONFIG_HOME="$HOME/.config"
CFG_FILE="$XDG_CONFIG_HOME/ncmpcpp/mpdnotify.conf"
if [[ ! -f "$CFG_FILE" ]]; then
echo " No config file found."
echo " Create $XDG_CONFIG_HOME/ncmpcpp/mpdnotify.conf for this user."
exit 1
else
. "$CFG_FILE"
fi
#--------------------------------------------------------------------
escape() {
echo "$1" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g;'
}
# determine file
file="$(mpc --format %file% current)"
album="$(mpc --format %album% current)"
artist="$(mpc --format %artist% current)"
# check if anything is playing at all
[[ -z $file ]] && exit 1
# Get title info
title="$(mpc current -f "$A_FORMAT")"
# Get song info
song="$(mpc current -f "$T_FORMAT")"
dir="$MUSIC_DIR/$artist/$album"
if [[ -d "$dir" ]] ; then
album_dir="$dir"
else
album_dir="$MUSIC_DIR/${file%/*}"
fi
[[ -z "$album_dir" ]] && exit 1
cover="$(find "$album_dir/" -type d -exec find {} -maxdepth 1 -type f -regex "$IMG_REG" \; )"
src="$(echo -n "$cover" | head -n1)"
text="$(escape "$title $song")"
# check if art is available
# --hint=int:transient:1 is needed, because gnome-shell will keep the notification in its bar.
# using 'hint' they'll be removed automatically (gnome-shell 3.01)
if [[ -n $src ]]; then
if [[ -n $COVER_RESIZE ]]; then
convert "$src" -thumbnail $COVER_RESIZE -gravity center \
-background "$COVER_BACKGROUND" -extent $COVER_RESIZE "$TEMP_PATH" >> "$LOGFILE" 2>&1
cover="$TEMP_PATH"
fi
notify-send -u $URGENCY -t 5000 --hint=int:transient:1 "$text" -i "$src" >> "$LOGFILE" 2>&1
else
notify-send -u $URGENCY -t 5000 --hint=int:transient:1 "$text" >> "$LOGFILE" 2>&1
fi