#!/bin/sh # music module for status/stellar # values ICON="$1" BUTTON="$(cat /tmp/speedwm-button)" # load status config if [ -e "$HOME/.config/speedwm-de/status/config" ]; then . $HOME/.config/speedwm-de/status/config if [ "$1" = "" ]; then ICON="$ITEM9_ICON" fi if [ "$ITEM9_BACKEND" = "auto" ]; then command -v mocp > /dev/null && ITEM9_BACKEND=mocp command -v cmus > /dev/null && ITEM9_BACKEND=cmus else if [ "$ITEM9_BACKEND" = "cmus" ]; then command -v cmus > /dev/null || ITEM9_BACKEND=mocp elif [ "$ITEM9_BACKEND" = "mocp" ]; then command -v mocp > /dev/null || ITEM9_BACKEND=cmus fi fi fi # for cmus CMUS() { MUSIC_FILENAME="$(basename "$(cmus-remote -C status | grep file)")" MUSIC_FILENAME_CUT="$(basename "$(cmus-remote -C status | grep file)"| sed 's|\(.*\)[.].*|\1|')" MUSIC_FILEDIR="$(dirname "$(cmus-remote -C status | grep file | sed 's/file //g')")" MUSIC_ARTIST="$(cmus-remote -C status | grep "tag artist" | sed "s/tag artist //g")" MUSIC_SONG="$(cmus-remote -C status | grep "tag title" | sed "s/tag title //g")" MUSIC_ALBUM="$(cmus-remote -C status | grep "tag album" | head -n 1 | sed "s/tag album //g")" MUSIC_GENRE="$(cmus-remote -C status | grep "tag genre" | sed "s/tag genre //g")" MUSIC_TIMEELAPSED="$(cmus-remote -Q | grep position | sed "s/position //g" | awk '{printf "%02d:%02d:%02d",$0/3600,$0%3600/60,$0%60}' | sed "s/00://")" MUSIC_TIMETOTAL="$(cmus-remote -Q | grep duration | sed "s/duration //g" | awk '{printf "%02d:%02d:%02d",$0/3600,$0%3600/60,$0%60}' | sed "s/00://")" MUSIC_REPEAT="$(cmus-remote -C status | grep 'repeat ' | sed "s/true/Yes/; s/false/No/; s/set repeat //")" MUSIC_SHUFFLE="$(cmus-remote -C status | grep 'shuffle' | sed "s/on/Yes/; s/off/No/; s/set shuffle //")" } # for mocp MOCP() { MUSIC_FILENAME="$(basename "$(mocp -Q %file)")" MUSIC_FILENAME_CUT="$(basename "$(mocp -Q %file)" | sed 's|\(.*\)[.].*|\1|')" MUSIC_FILEDIR="$(dirname "$(mocp -Q %file)")" MUSIC_ARTIST="$(mocp -Q %artist)" MUSIC_SONG="$(mocp -Q %song)" MUSIC_ALBUM="$(mocp -Q %album)" MUSIC_TIMEELAPSED="$(mocp -Q %ct)" MUSIC_TIMETOTAL="$(mocp -Q %tt)" # todo: genre } # set variables with content case "$ITEM9_BACKEND" in "cmus") CMUS ;; "mocp") MOCP ;; esac # terminal case "$TERMINAL" in "") TERMINAL=st esac # button case "$BUTTON" in "3") $TERMINAL -e $ITEM9_BACKEND ; exit ;; esac # no spacing if there's no icon if [ "$ICON" != "" ]; then ICONSPACING=" " # one character spacing fi # send the notification SEND_NOTIF() { if [ "$ITEM9_BACKEND" = "cmus" ]; then FULL_MUSIC="$(printf "${ICON}${ICONSPACING}Artist: $MUSIC_ARTIST\nTitle: $MUSIC_SONG\nAlbum: $MUSIC_ALBUM\nGenre: $MUSIC_GENRE\nTime elapsed: $MUSIC_TIMEELAPSED\nTotal time: $MUSIC_TIMETOTAL\nFile: $MUSIC_FILENAME\nDirectory: $MUSIC_FILEDIR\nPath: $MUSIC_FILEDIR/$MUSIC_FILENAME\nRepeat: $MUSIC_REPEAT\nShuffle: $MUSIC_SHUFFLE")" else FULL_MUSIC="$(printf "${ICON}${ICONSPACING}Artist: $MUSIC_ARTIST\nTitle: $MUSIC_SONG\nAlbum: $MUSIC_ALBUM\nTime elapsed: $MUSIC_TIMEELAPSED\nTotal time: $MUSIC_TIMETOTAL\nFile: $MUSIC_FILENAME\nDirectory: $MUSIC_FILEDIR\nPath: $MUSIC_FILEDIR/$MUSIC_FILENAME")" fi notify-send "$FULL_MUSIC" echo "Notification sent successfully!" echo "INFO: $FULL_MUSIC" exit 0 } command -v notify-send > /dev/null && SEND_NOTIF echo "FATAL: libnotify not installed, can't send notification." exit 1