This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/statusbar/sb-music
David JULIEN 7458ed872a feat: properly display album artist
only display title artist for compilations
2021-09-25 13:50:42 +02:00

28 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env sh
######################################################################
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
# @file : sb-music
# @license : GPLv3
# @created : Saturday Feb 13, 2021 18:05:21 CET
#
# @description : music block for dwmblocks
######################################################################
unicode() { sed "s/[]/'/g;s/[“”]/\"/g"; }
format() { sed "s/^volume:n\/a.*//g;/^volume:/d;s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g"; }
mpc="$(mpc --format "%albumartist% - %artist% - %title%")"
title="$(echo "$mpc" | head -n1 | cut -d'-' -f3 | unicode)"
[ "$(echo "$title" | wc -c)" -gt 18 ] && title="$(printf "%.15s..." "$title")"
artist="$(echo "$mpc" | head -n1 | cut -d'-' -f1 | unicode)"
[ "Various Artists " = "$artist" ] &&
artist="$(echo "$mpc" | head -n1 | cut -d'-' -f2 | unicode)"
[ "$(echo "$artist" | wc -c)" -gt 18 ] && artist="$(printf "%.15s..." "$artist")"
status="$(echo "$mpc" | tail -n2 | format)"
pgrep -f sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 &
[ -n "$status" ] && printf " %s %s-%s " "$status" "$artist" "$title"