Skip to content

Commit

Permalink
mpd/sh: Comments changes
Browse files Browse the repository at this point in the history
Only preserve the important comments, and improve some of them.

Signed-off-by: Harry Kurn <[email protected]>
  • Loading branch information
owl4ce committed Jun 8, 2022
1 parent ac6212a commit d80ab3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
13 changes: 3 additions & 10 deletions .config/mpd/scripts/mpd-notifier.sh
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

Expand All @@ -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 \
Expand All @@ -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
} &
Expand Down
14 changes: 3 additions & 11 deletions .config/mpd/scripts/notify.album-art.sh
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

Expand All @@ -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" \
Expand Down Expand Up @@ -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}}"
Expand Down

0 comments on commit d80ab3a

Please sign in to comment.