#!/bin/sh # Shows a notification with info about the currently playing song. scriptName="${0##*/}" [ "$(pgrep "${scriptName}" | wc -l)" -gt "2" ] && pkill "$scriptName" && exit 0 notificationFreq=0.5 #steps=10 iconSize='128' bluetoothInfo='' getCmusInfo() { cmus-remote -Q | grep "^${1} " | cut -d' ' -f "${2}-" } sToTime() { min=$(( $1 / 60 )) s=$(( $1 % 60 )) [ "$s" -lt 10 ] && s="0${s}" echo "${min}:${s}" } getAlbumIcon() { albumIcon="/tmp/$(echo "$playingFile" | base64 -w0).png" ffmpeg -y -i "$playingFile" -an -vf scale="${iconSize}:${iconSize}" "$albumIcon" echo "$albumIcon" } # Song info playingFile="$(getCmusInfo 'file' '2')" title="🎢 $(getCmusInfo 'tag title' '3') 🎢" artist="πŸ§‘β€πŸŽ€ $(getCmusInfo 'tag artist' '3')" album="$(getCmusInfo 'tag album' '3') πŸ’½" duration="$(getCmusInfo 'duration' '2')" albumIcon="$(getAlbumIcon)" # Bluetooth info if systemctl is-active bluetooth --quiet && bluetoothctl info; then device="πŸ“» $(bluetoothctl info | grep 'Name: ' | cut -d' ' -f '2-')" battery="$(bluetoothctl info | grep 'Battery Percentage:' | grep -o '(.*)' | grep -o '[0-9]*')% πŸ”‹" bluetoothInfo="\n${device} - ${battery}" fi playingIcon='' #i=0 #while [ "$i" -lt "$steps" ]; do while true; do currentlyPlayingFile="$(getCmusInfo 'file' '2')" if [ "$currentlyPlayingFile" != "$playingFile" ]; then playingFile="$currentlyPlayingFile" albumIcon="$(getAlbumIcon)" title="🎢 $(getCmusInfo 'tag title' '3') 🎢" artist="πŸ§‘β€πŸŽ€ $(getCmusInfo 'tag artist' '3')" album="$(getCmusInfo 'tag album' '3') πŸ’½" duration="$(getCmusInfo 'duration' '2')" fi [ "$(getCmusInfo 'status' 2)" = 'playing' ] && playingIcon='▢️' [ "$(getCmusInfo 'status' 2)" = 'paused' ] && playingIcon='⏸️' position="$(getCmusInfo 'position' '2')" percentage="$(awk "BEGIN { print int(${position}/${duration}*100) }")" dunstify \ -r "$(dunstifyIDs.sh cmusShow)" \ -t 1000 \ -i "$albumIcon" \ -h "int:value:${percentage}" \ "${title}" \ "${artist} - ${album}\n${playingIcon} $(sToTime "${position}") - $(sToTime "${duration}")${bluetoothInfo}" sleep "$notificationFreq" #i=$((i+1)) done