Big fixes for wf-shadow

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-05-12 18:34:53 -04:00
parent 1906dc4c5d
commit cab1bf18b8
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
1 changed files with 23 additions and 7 deletions

View File

@ -15,7 +15,7 @@
# this program. If not, see <https://www.gnu.org/licenses/>.
#
RUNTIME="${XDG_RUNTIME_DIR:-/run}/wf-shadow/"
RUNTIME="${XDG_RUNTIME_DIR:-/run}/wf-shadow"
MONITOR=1
AUDIO_DEV=""
@ -61,25 +61,41 @@ OPTIONS:
-V DEVICE, --video DEVICE Use DEVICE for video encoding. Passed to wf-recorder -d
-v, --verbose Verbose output
-h, --help Show this menu
VARIABLES:
\$WF_SHADOW_SAVE The directory to save clips in
\$WF_SHADOW_FORMAT The date format to save clips in
EOF
exit $1
}
record() {
local FILE="${WF_SHADOW_SAVE:-"$HOME"/Videos/wf-shadow/"$(date +%Y%m%d_%H:%M:%S)__$2".mp4}"
ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE" ${VERBOSE:-&>/dev/null} &&
notify-send "Clip saved" "$2 second clip saved to $FILE"
local FILE="${WF_SHADOW_SAVE:-"$HOME"/Videos/wf-shadow/}""$(date +${WF_SHADOW_FORMAT:-%Y%m%d_%H:%M:%S})__$2".mp4
if [ $VERBOSE ]; then
ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE" &>/dev/null &&
notify-send "Clip saved" "$2 second clip saved to $FILE" ||
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
else
ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE" &&
notify-send "Clip saved" "$2 second clip saved to $FILE" ||
notify-send "Error saving clip" "Start a new session with --verbose to see ffmpeg output"
fi
}
start() {
local WOFI_STRING="5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n"
while true; do
for i in /tmp/wf-shadow/tmp{00..10}.mp4; do
touch "$i"
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR ${VERBOSE:-&>/dev/null} &
if [ $VERBOSE ]; then
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &
else
wf-recorder ${VIDEO_DEV:+-d "$VIDEO_DEV"} -a $AUDIO_DEV -f "$i" <<< y$'\n'$MONITOR &>/dev/null &
fi
printf "%s" "$!" > "$RUNTIME"/"$MONITOR".pid
fg || exit
case "$(printf "5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 ${VERBOSE:-&>/dev/null} )" in
case "$([ $VERBOSE ] && printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 || printf "$WOFI_STRING" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 &> /dev/null)" in
'5 seconds') record "$i" 5 ;;
'10 seconds') record "$i" 10 ;;
'15 seconds') record "$i" 15 ;;
@ -115,7 +131,7 @@ until [ -z "$1" ]; do
VIDEO_DEV="$2"
shift 2 ;;
'-v' | '--verbose')
VERBOSE=" "
VERBOSE="1"
shift 1 ;;
*) print_help ;;
esac