From 0cb713aa7ff7cc42f0da42da55ac90fb5d531ec3 Mon Sep 17 00:00:00 2001 From: noodle Date: Sun, 2 Jul 2023 00:38:05 +0300 Subject: mpc-notify: use xdg-user-dirs for finding music directory --- mpc-notify | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mpc-notify b/mpc-notify index 4bd80a1..ab6d43e 100755 --- a/mpc-notify +++ b/mpc-notify @@ -2,8 +2,14 @@ # Based on: # https://wiki.archlinux.org/title/Ncmpcpp#With_album_art -# Sends notification for mpd with album cover art. Uses mpc, ffmpeg, -# notify-send, and my other script, notify-replace. +# Sends notification of currently playing MPD music with album cover art. +# Dependencies: +# mpc +# ffmpeg +# notify-send +# and my other script, notify-replace. +# recommended: a home directory setup with xdg-user-dirs (for finding your +# music directory # For notification on song change: # Assign execute_on_song_change to this script in ncmpcpp's config file. # For notification on media keys: @@ -15,11 +21,19 @@ if [ -z "$WAYLAND_DISPLAY" ] && [ -z "$DISPLAY" ]; then fi command="$1" +# set defaults # FEATURE: make width and height configurable through flags preview_width=64 preview_height=64 default_song_icon="media-playback-start" + +# find xdg directories xdg_config_home="${XDG_CONFIG_HOME:-$HOME/.config}" +xdg_user_dirs="${xdg_config_home}/user-dirs.dirs" +[ -f "$xdg_user_dirs" ] && source "$xdg_user_dirs" +xdg_music_dir="${XDG_MUSIC_DIR:-$HOME/Music}" + +# find mpc config directory mpc_config_dir="$xdg_config_home/mpc" [ -d "$mpc_config_dir" ] || mkdir -p "$mpc_config_dir" @@ -92,10 +106,9 @@ song_body="$(mpc --format '[%title%[ \n%artist% - %album%]]|[%file%]' current)" if [ "$use_preview" -eq 1 ]; then preview_dir="$mpc_config_dir/previews" [ -d "$preview_dir" ] || mkdir -p "$preview_dir" - music_dir="$(xdg-user-dir MUSIC)" # get preview filename - song_filename="$(mpc --format "$music_dir"/%file% current)" + song_filename="$(mpc --format "${xdg_music_dir}/%file%" current)" song_album="$(mpc --format %album% current)" if [ -z "$song_album" ]; then # fallback to default for empty album name -- cgit v1.2.3