Home

NCMPCPP with Album Covers (tmux + Ueberzug)

Screenshot of the tmux window with album cover from Ueberzug

Requisites

  • ncmpcpp (which requires mpd)
  • ueberzug (note: this is available in the apt repositories, but not on Github)
  • tmux for creating terminal window layout

Instructions

  1. Download songinfo and put it in ~/.ncmpcpp. This script generates gets the images from the music files. Make sure it is executable by running chmod +x ~/.ncmpcpp/songinfo. Then, add execute_on_song_change="~/.ncmpcpp/songinfo" to ~/.ncmpcpp/config. This makes songinfo run on startup and whenever a new song is begun.
  2. Create the directory ~/.ncmpcpp/cover, and download the following files into this directory: music-tmux.sh, setupCanvas.sh, nextImage.sh, and vis-config. Make them executable with chmod +x ~/.ncmpcpp/cover/setupCanvas.sh ~/.ncmpcpp/cover/nextImage.sh ~/.ncmpcpp/cover/music-tmux.sh
  3. Run ~/.ncmpcpp/cover/music-tmux.sh

Scripts

~/.ncmpcpp/songinfo

#!/bin/bash

music_dir="$HOME/Music"
previewdir="$HOME/.ncmpcpp/cover"
find $previewdir -type f -iname "*jpg" -delete
filename="$(mpc --format "$music_dir"/%file% current)"
previewname="$previewdir/$(openssl rand -hex 6).jpg"

ffmpeg -y -i "$filename" -an -vcodec copy "$previewname" &>/dev/null

if [[ $(pgrep setupCanvas.sh) ]]; then
    sh "$previewdir/nextImage.sh" 
fi

~/.ncmpcpp/cover/music-tmux.sh

#!/bin/sh

previewdir="$HOME/.ncmpcpp/cover" 

if [ -z "${TMUX}" ] ; then 
    tmux new-session -s ncmpcpp-session "$previewdir/music-tmux.sh"
else
    tmux split-window -h "ncmpcpp -c "$previewdir"/vis-config"
    tmux resize-pane -R 44
    tmux split-window -v ""$previewdir"/setupCanvas.sh"
    tmux select-pane -t:.0
    (sleep 0.2s && ~/.ncmpcpp/songinfo) &
    ncmpcpp
fi

~/.ncmpcpp/cover/setupCanvas.sh

#!/bin/sh
set -e

previewdir="$HOME/.ncmpcpp/cover"

if [ ! -e "$previewdir/FIFO_UEBERZUG" ]; then
    mkfifo "$previewdir/FIFO_UEBERZUG"
fi

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
	exit
else
	ueberzug layer -s <$previewdir/FIFO_UEBERZUG -p json &
	exec 3>$previewdir/FIFO_UEBERZUG
    read anything
fi

~/.ncmpcpp/cover/nextImage.sh

#!/bin/sh

previewdir="$HOME/.ncmpcpp/cover"
if [ -n "$previewdir/FIFO_UEBERZUG" ]; then
	printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$previewdir/FIFO_UEBERZUG"
fi

nextImage="$(find $previewdir -type f -iname '*jpg')"

if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
    printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y":"%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' 1 0 49 49 "${nextImage}" > "$previewdir/FIFO_UEBERZUG"
    exit 1
else
    chafa "${nextImage}" 
fi

~/.ncmpcpp/cover/vis-config

statusbar_visibility = no
connected_message_on_startup = no
titles_visibility = no
header_visibility = no
progressbar_look = "   "

visualizer_type = ellipse
visualizer_fps = 30
visualizer_spectrum_dft_size = 5

startup_screen = visualizer

Tags

Categories

If you have questions, you can email me at jeremy.w.cains at gmail.com. View page source here.