Make the recorder script more readable

This commit is contained in:
Alexander Oakman 2024-08-24 20:19:43 +03:00
parent d59a58120b
commit bca213279f

View file

@ -1,18 +1,17 @@
#!/bin/bash #!/bin/bash
countdown() { countdown() {
notify "Recording in 3 seconds" -t 1000 for count in {3..1}; do
sleep 1 notify "Recording in $count seconds" -t 1000
notify "Recording in 2 seconds" -t 1000
sleep 1
notify "Recording in 1 seconds" -t 1000
sleep 1 sleep 1
done
} }
notify() { notify() {
line=$1 notify-send \
shift "$1" \
notify-send "${line}" -i /usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg "$@" -i "/usr/share/icons/Yaru/scalable/devices/camera-video-symbolic.svg" \
"${@:2}"
} }
kill_waybar() { kill_waybar() {
@ -41,17 +40,25 @@ main() {
timestamp=$(date +'recording_%Y%m%d-%H%M%S') timestamp=$(date +'recording_%Y%m%d-%H%M%S')
notify "Select a region to record" -t 1000 notify "Select a region to record" -t 1000
area=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp) area=$(swaymsg -t get_tree | \
jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | \
slurp)
countdown countdown
(sleep 0.5 && kill_waybar) & (sleep 0.5 && kill_waybar) &
if [ "$1" == "-a" ]; then if [[ "$1" == "-a" ]]; then
file="$target_path/$timestamp.mp4" file="$target_path/$timestamp.mp4"
wf-recorder --audio -g "$area" --file="$file" wf-recorder --audio -g "$area" --file="$file"
else else
file="$target_path/$timestamp.webm" file="$target_path/$timestamp.webm"
wf-recorder -g "$area" -c libvpx --codec-param="qmin=0" --codec-param="qmax=25" --codec-param="crf=4" --codec-param="b:v=1M" --file="$file" wf-recorder \
-g "$area" -c libvpx \
--codec-param="qmin=0" \
--codec-param="qmax=25" \
--codec-param="crf=4" \
--codec-param="b:v=1M" \
--file="$file"
fi fi
kill_waybar && notify "Finished recording ${file}" kill_waybar && notify "Finished recording ${file}"