dwm-speedie/modules/module_dfmpeg
2023-09-13 15:24:02 +02:00

64 lines
1.9 KiB
Bash
Executable file

#!/bin/sh
# dfmpeg module for status/stellar
command -v dwm-dfmpeg > /dev/null || exit
[ -e "/tmp/module_dfmpeg_hidden" ] && exit
# load config
module_config
[ -e "$HOME/.config/dwm/statusrc" ] && . $HOME/.config/dwm/statusrc
# click
CLICK() {
# values
DFMPEG_STOP_CMD="dwm-dfmpeg -s" # command to run to stop recording
ICON="$ITEM7_ICON"
DFMPEG_ENCODING="Not encoding" # placeholder, we can override this later
[ -e "/tmp/outputfilename" ] && DFMPEG_REC_PATH="$(cat /tmp/outputfilename)"
[ -e "/tmp/dwm-button" ] && BUTTON="$(cat /tmp/dwm-button)"
[ -z "$TERMINAL" ] && TERMINAL=st
pgrep -x ffmpeg > /dev/null || return
case "$BUTTON" in
"3") dwm-dfmpeg ; exit ;;
"2") $DFMPEG_STOP_CMD ; exit ;;
esac
# check a few things
[ -e "/tmp/isaudio" ] && DFMPEG_AUDIO="Recording audio" || DFMPEG_AUDIO="Not recording audio"
[ -e "/tmp/isencoding" ] && DFMPEG_ENCODING="Encoding"
[ -e "/tmp/encoding-codec" ] && DFMPEG_ENCODING="Encoding with $(cat /tmp/encoding-codec)"
[ -n "$ICON" ] && ICONSPACING=" " # one character spacing
# send the notification
SEND_NOTIF() {
FULL_RECSTATUS="$(printf "${ICON}${ICONSPACING}Recording video $DFMPEG_REC_PATH\n${DFMPEG_AUDIO}, ${DFMPEG_ENCODING}\nMiddle click to stop recording.")"
notify-send "$FULL_RECSTATUS"
# some output
echo "Notification sent successfully!"
echo "INFO: $FULL_RECSTATUS"
return
}
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
return
}
# information itself
PRINT() {
# check if we're recording with dfmpeg or not
[ "$ENABLE_ITEM7" = "true" ] && [ -e "/tmp/dfmpeg-recording" ] && echo "$ITEM7_SEPARATOR $ITEM7_ICON $ITEM7_RECORDING_TEXT"
}
# argument 1
case "$1" in
"") CLICK ;;
"--print-file") PRINT > /tmp/module_dfmpeg ;;
"--print") PRINT ;;
"--click") CLICK ;;
esac