-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only preserve the important comments, and improve some of them. Signed-off-by: Harry Kurn <[email protected]>
- Loading branch information
Showing
2 changed files
with
6 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
#!/usr/bin/env sh | ||
|
||
# The MPD's track notification-sender daemon. | ||
# https://github.com/owl4ce/dotfiles | ||
# Desc: MPD track notification-sender daemon. | ||
# Author: Harry Kurn <[email protected]> | ||
# URL: https://github.com/owl4ce/dotfiles/tree/ng/.config/mpd/scripts/mpd-notifier.sh | ||
|
||
# SPDX-License-Identifier: ISC | ||
|
||
|
@@ -11,7 +12,6 @@ export LANG='POSIX' | |
exec >/dev/null 2>&1 | ||
. "${HOME}/.joyfuld" | ||
|
||
# Ensure `mpd` and `mpc` already installed for safety and performance reasons. | ||
[ -x "$(command -v mpd)" -a -x "$(command -v mpc)" ] || exec dunstify 'Install `mpd` and `mpc`!' \ | ||
-h string:synchronous:install-deps \ | ||
-a joyful_desktop \ | ||
|
@@ -20,25 +20,18 @@ exec >/dev/null 2>&1 | |
# https://gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html#:~:text=expand_aliases | ||
[ -z "$BASH" ] || shopt -s expand_aliases | ||
|
||
# Process as a background task. | ||
{ | ||
# Ensure mpd isn't running before. | ||
! pidof -s mpd -q || mpd --kill || killall -9 mpd -q | ||
|
||
# Execute mpd with niceness, fallback to fails notification. | ||
nice -n 1 mpd || mpd || exec dunstify 'Music Player' 'Failed to execute <u>mpd</u>!' \ | ||
-h string:synchronous:music-player \ | ||
-a joyful_desktop \ | ||
-i "$MUSIC_ICON" \ | ||
-u low | ||
|
||
# Loop condition of the playing track. | ||
while :; do | ||
# Save the last played track. | ||
LAST_PLAYED_TRACK="$(mpc -p "$CHK_MPD_PORT" -f '%file%' current)" | ||
# Stop while loop, resume when event changes. | ||
nice -n 19 mpc -p "$CHK_MPD_PORT" idle || mpc -p "$CHK_MPD_PORT" idle | ||
# Send notification when current and saved tracks differ. | ||
[ "$LAST_PLAYED_TRACK" = "$(mpc -p "$CHK_MPD_PORT" -f '%file%' current)" ] || joyd_mpd_notify_albumart | ||
done | ||
} & | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
#!/usr/bin/env sh | ||
|
||
# The MPD's track album-art notification-sender. | ||
# https://github.com/owl4ce/dotfiles | ||
# Desc: MPD track notification-sender. | ||
# Author: Harry Kurn <[email protected]> | ||
# URL: https://github.com/owl4ce/dotfiles/tree/ng/.config/mpd/scripts/notify.album-art.sh | ||
|
||
# SPDX-License-Identifier: ISC | ||
|
||
|
@@ -11,29 +12,22 @@ export LANG='POSIX' | |
exec >/dev/null 2>&1 | ||
. "${HOME}/.joyfuld" | ||
|
||
# Ensure `mpd`, `mpc`, and `magick` already installed for safety and performance reasons. | ||
[ -x "$(command -v mpd)" -a -x "$(command -v mpc)" -a -x "$(command -v magick)" ] || exit ${?} | ||
|
||
# Process as a background task. | ||
{ | ||
# Get file path, merge with album-name of current track. | ||
FILE="$(mpc -p "$CHK_MPD_PORT" -f '%file% ########## %album%' current)" | ||
|
||
# Ensure the file path is valid. | ||
[ -n "${FILE%/*\ #####\ *}" ] || exit ${?} | ||
|
||
# Update $CHK_MPD_MUSIC_DIR if in the mpd configuration contains tilde. This is bug fix. | ||
[ -n "${CHK_MPD_MUSIC_DIR%%~*}" ] || CHK_MPD_MUSIC_DIR="${HOME}/${CHK_MPD_MUSIC_DIR#~*/}" | ||
|
||
# Get single album-art image. | ||
read -r ALBUM_COVER <<- EOF | ||
$(find "${CHK_MPD_MUSIC_DIR}/${FILE%/*\ #####\ *}/" -maxdepth 1 \ | ||
-type f \ | ||
-iregex \ | ||
".*/.*\(${FILE##*\ #####\ }\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)") | ||
EOF | ||
|
||
# Rescale and convert album-art image into rounded corners. | ||
if [ -f "$ALBUM_COVER" ]; then | ||
|
||
magick "$ALBUM_COVER" \ | ||
|
@@ -63,10 +57,8 @@ exec >/dev/null 2>&1 | |
MPD_NOTIFY_AA_IMG= | ||
fi | ||
|
||
# Get current track artist, merge with title, fallback to file path. | ||
INFO="$(mpc -p "$CHK_MPD_PORT" -f '%artist% ########## [%title%|%file%]' current)" | ||
|
||
# Send notification with album-art image as raw icon. | ||
exec dunstify '' "<span size='small'>${INFO%%\ #####\ *}</span>\n${INFO##*\ #####\ }" \ | ||
-h string:synchronous:ncmpcpp-album-art \ | ||
-I "${MPD_NOTIFY_AA_IMG:-${MUSIC_ICON}}" | ||
|