From 730f20af5249e96d40ba0c83adbaa0204ba9eedd Mon Sep 17 00:00:00 2001 From: inkch Date: Fri, 19 Jan 2024 22:47:59 +0900 Subject: [PATCH] ncmpcpp: add config, bindings and a script --- dot_config/ncmpcpp/bindings | 38 ++++++++++++++++ dot_config/ncmpcpp/config | 2 + dot_config/ncmpcpp/executable_art.sh | 66 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 dot_config/ncmpcpp/bindings create mode 100644 dot_config/ncmpcpp/config create mode 100644 dot_config/ncmpcpp/executable_art.sh diff --git a/dot_config/ncmpcpp/bindings b/dot_config/ncmpcpp/bindings new file mode 100644 index 0000000..9c64589 --- /dev/null +++ b/dot_config/ncmpcpp/bindings @@ -0,0 +1,38 @@ +############################################################## +## My `ncmpcpp` keybindings. This file should be in ## +## ~/.ncmpcpp/bindings or $XDG_CONFIG_HOME/ncmpcpp/bindings ## +## ## +## For more information, see example file ## +## -> /usr/share/doc/ncmpcpp/bindings ## +############################################################## +# +# vim-like bindings +def_key "l" + next_column +def_key "h" + previous_column +def_key "j" + scroll_down +def_key "k" + scroll_up + +def_key "." + seek_forward +def_key "," + seek_backward +def_key ">" + next +def_key "<" + previous + +def_key "ctrl-l" + seek_forward +def_key "ctrl-h" + seek_backward +def_key "ctrl-p" + volume_up +def_key "ctrl-n" + volume_down + +def_key ";" + show_lyrics diff --git a/dot_config/ncmpcpp/config b/dot_config/ncmpcpp/config new file mode 100644 index 0000000..31fc0a4 --- /dev/null +++ b/dot_config/ncmpcpp/config @@ -0,0 +1,2 @@ +ncmpcpp_directory=~/.config/ncmpcpp +lyrics_directory=~/.config/ncmpcpp/lyrics diff --git a/dot_config/ncmpcpp/executable_art.sh b/dot_config/ncmpcpp/executable_art.sh new file mode 100644 index 0000000..0a93586 --- /dev/null +++ b/dot_config/ncmpcpp/executable_art.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env sh + +# Add following line to config: +# execute_on_song_change = "~/.config/ncmpcpp/art.sh" + + +#-------------------------------# +# Generate current song cover # +# ffmpeg version # +#-------------------------------# + +# Path to music directory +MUSIC_DIR="$HOME/.local/share/mpd/music" +# Path to output cover +COVER="/tmp/cover.png" +COVER_NOTIFICATION="/tmp/cover_notification.png" +# Size of cover +COVER_SIZE=297 +# Size in pixel of borders to crop out +CROP_BORDER=20 +# Radius or rounded borders +BORDER_RADIUS=10 + +ffmpeg_cover() { + ffmpeg -loglevel 0 -y -i "$1" -vf "crop=min(in_w-$CROP_BORDER\,in_h-$CROP_BORDER):out_w,scale=-2:$COVER_SIZE" "$COVER" +} + +rounded_cover() { + convert -quiet "$COVER" \ + \( +clone -alpha extract \ + -draw "fill black polygon 0,0 0,$BORDER_RADIUS $BORDER_RADIUS,0 fill white circle $BORDER_RADIUS,$BORDER_RADIUS $BORDER_RADIUS,0" \ + \( +clone -flip \) -compose Multiply -composite \ + \( +clone -flop \) -compose Multiply -composite \ + \) -alpha off -compose CopyOpacity -composite "$COVER" +} + +#fallback_find_cover() { +# album=$(dirname "$file") +# album_cover="$(find "$album" -type d -exec find {} -maxdepth 1 -type f -iregex ".*\(covers?\|folders?\|artworks?\|fronts?\|scans?\).*[.]\(jpe?g\|png\|gif\|bmp\)" \;)" +# [ -z "$album_cover" ] && album_cover="$(find "$album" -type d -exec find {} -maxdepth 1 -type f -iregex ".*[.]\(jpe?g\|png\|gif\|bmp\)" \;)" +# [ -z "$album_cover" ] && album_cover="$(find "${album%/*}" -type d -exec find {} -maxdepth 1 -type f -iregex ".*\(covers?\|folders?\|artworks?\|fronts?\|scans?\|booklets?\).*[.]\(jpe?g\|png\|gif\|bmp\)" \;)" +# album_cover="$(echo "$album_cover" | grep -iv '\(back\|cd\)\.' | head -n1)" +#} + +mpris_album_art() { + playerctl metadata mpris:artUrl | sed 's#file://##' + # mpris_player_control -t | grep 'artUrl' | cut -f 3 -d '|' | sed 's#file://##' +} + +notification() { + convert "$COVER" -resize 144x144 "$COVER_NOTIFICATION" + # notify-send -i "$COVER_NOTIFICATION" "$(playerctl metadata --format '{{title}} {{album}}')" +} + +main() { + file="$MUSIC_DIR/$(mpc --format %file% current)" + + # [ -n "$file" ] && ffmpeg_cover "$file" && rounded_cover || + # fallback_find_cover && ffmpeg_cover "$album_cover" && rounded_cover + # [ ! -x "$(which playerctl)" ] && echo "Install playerctl and mpDris2 for this script to work." + + ffmpeg_cover "$file" && rounded_cover + notification +} + +main