Skip to content

Commit

Permalink
script & components: V1.2
Browse files Browse the repository at this point in the history
* add checks for `start_notif` and `end_notif` to  every notification related
* fix some display issues with nest.rip on `-u` making say the upload errored but it didn't
* slightly introduce error handling
* add `start_notif` and `end_notif` options to initial setup
  • Loading branch information
verysillycat committed Dec 7, 2024
1 parent c76869c commit d2c9f0e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 24 deletions.
8 changes: 5 additions & 3 deletions components/functions/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ create_default_config() {
local failsave=${11}
local save=${12}
local encoder=${13}

local startnotif=${14}
local endnotif=${15}

mkdir -p "$CONFIG_DIR"

local auth_variable=""
Expand All @@ -37,8 +39,8 @@ encoder=$encoder
save=$save
failsave=$failsave
colorworkaround=false
startnotif=true
endnotif=true
startnotif=$startnotif
endnotif=$endnotif
wlscreenrec=$wlscreenrec
codec=$codec
Expand Down
24 changes: 16 additions & 8 deletions components/functions/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ upload_video() {
file_path=$(realpath "$file")
echo -n "file://$file_path" | xclip -selection clipboard -t text/uri-list
fi
notify-send "Video copied to clipboard" -a "VNREZ Recorder"
[[ "$endnotif" == true ]] && notify-send "Video copied to clipboard" -a "VNREZ Recorder"
exit 0
fi

Expand All @@ -58,7 +58,15 @@ upload_video() {
exit 1
fi

success=$(jq -r ".success" <$response_video)
if [[ "$service" == "e-z" ]]; then
success=$(jq -r ".success" <$response_video)
elif [[ "$service" == "nest" ]]; then
success=$(jq -r ".success" <$response_video)
if [[ "$http_code" -eq 200 && "$success" == "null" ]]; then
success="true"
fi
fi

if [[ "$success" != "true" ]] || [[ "$success" == "null" ]]; then
error=$(jq -r ".error" <$response_video)
if [[ "$error" == "null" ]]; then
Expand Down Expand Up @@ -95,12 +103,12 @@ upload_video() {
fi
if [[ "$is_gif" == "--gif" || "$file" == *.gif ]]; then
if [[ "$XDG_SESSION_TYPE" != "wayland" || ("$XDG_CURRENT_DESKTOP" != "GNOME" && "$XDG_CURRENT_DESKTOP" != "KDE") ]]; then
notify-send "GIF URL copied to clipboard" -a "VNREZ Recorder" -i link
[[ "$endnotif" == true ]] && notify-send "GIF URL copied to clipboard" -a "VNREZ Recorder" -i link
fi
[[ "$is_gif" == "--gif" && "$upload_mode" != true ]] && rm "$gif_pending_file"
else
if [[ "$XDG_SESSION_TYPE" != "wayland" || ("$XDG_CURRENT_DESKTOP" != "GNOME" && "$XDG_CURRENT_DESKTOP" != "KDE") ]]; then
notify-send "Video URL copied to clipboard" -a "VNREZ Recorder" -i link
[[ "$endnotif" == true ]] && notify-send "Video URL copied to clipboard" -a "VNREZ Recorder" -i link
fi
fi
if [[ "$save" == false && "$upload_mode" != true ]]; then
Expand Down Expand Up @@ -138,9 +146,9 @@ upload_kooha() {
let file_count=file_count+1
echo -n "file://$(realpath "$file_path")" | wl-copy -t text/uri-list
if [[ $(echo $new_files | wc -w) -gt 1 ]]; then
notify-send "#$file_count Recording uploaded" "$file_count of $(echo $new_files | wc -w) URLs have been copied." -a "VNREZ Recorder"
[[ "$endnotif" == true ]] && notify-send "#$file_count Recording uploaded" "$file_count of $(echo $new_files | wc -w) URLs have been copied." -a "VNREZ Recorder"
else
notify-send "Recording copied to clipboard" -a "VNREZ Recorder"
[[ "$endnotif" == true ]] && notify-send "Recording copied to clipboard" -a "VNREZ Recorder"
fi
done
exit 0
Expand All @@ -160,9 +168,9 @@ upload_kooha() {
fi

if [[ $(echo $new_files | wc -w) -gt 1 ]]; then
notify-send -i link "#$file_count Recording uploaded" "$file_count of $(echo $new_files | wc -w) URLs have been copied." -a "VNREZ Recorder"
[[ "$endnotif" == true ]] && notify-send -i link "#$file_count Recording uploaded" "$file_count of $(echo $new_files | wc -w) URLs have been copied." -a "VNREZ Recorder"
else
notify-send "Recording copied to clipboard" -a "VNREZ Recorder"
[[ "$endnotif" == true ]] && notify-send "Recording copied to clipboard" -a "VNREZ Recorder"
fi
else
echo "Error: Encoded file not found: $file_path"
Expand Down
21 changes: 21 additions & 0 deletions components/functions/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ if [ "$service" = "e-z" ]; then
elif [ "$service" = "nest" ]; then
url=$nest
fi

valid_args=(
"--help"
"-h"
"config"
"reinstall"
"upload"
"-u"
"auto"
"shot"
"record"
"--gui"
"--full"
"--screen"
"--sound"
"--fullscreen-sound"
"--fullscreen"
"--no-sound"
"--gif"
"--abort"
)
12 changes: 12 additions & 0 deletions components/shot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ if [[ "$1" != "auto" && ! -f "$CONFIG_FILE" ]]; then
check_variables
fi

if [[ "$1" == "auto" ]]; then
arg="$2"
else
arg="$1"
fi

if [[ "$arg" != "--screen" && "$arg" != "shot" && "$arg" != "--full" && "$arg" != "--gui" ]]; then
notify-send "Invalid argument: $arg" -a "VNREZ Recorder"
echo "Argument: \"$arg\" is not valid."
exit 1
fi

if [[ "$1" == "auto" && ! -f "$CONFIG_FILE" ]]; then
service="none"
shift
Expand Down
52 changes: 39 additions & 13 deletions vnrez.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
fi


if [[ -n "$1" && ! " ${valid_args[@]} " =~ " $1 " ]]; then
notify-send "Invalid argument: $1" -a "VNREZ Recorder"
echo "Argument: \"$1\" is not valid."
echo "Use '--help' or '-h' to see the list of valid arguments."
exit 1
fi

if [[ "$1" == "--help" || "$1" == "-h" || "$2" == "--help" || "$2" == "-h" ]]; then
help
fi

check_root
check_dependencies

if [[ "$1" != "upload" && "$1" != "-u" && "$1" != "auto" && "$1" != "shot" && "$1" != "record" && "$1" != "config" && "$1" != "reinstall" ]] || [[ "$1" == "auto" && -z "$2" ]]; then
handle_resize
trap handle_resize SIGWINCH
fi

initial_setup() {
echo -e "Initializing.."
services=("e-z" "nest" "none")
Expand Down Expand Up @@ -170,6 +173,7 @@ initial_setup() {
tput sc

while true; do
trap handle_resize SIGWINCH
tput rc
tput civis
tput el
Expand Down Expand Up @@ -231,10 +235,10 @@ initial_setup() {
read -r save_recordings
if [[ "$save_recordings" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
save=true
echo -e "\e[33mEnter the directory to save files (default is ~/Videos):\e[0m"
echo -e "\e[33mEnter the directory to save files (You need to set it on Kooha too) (default is ~/Videos/Kooha) :\e[0m"
echo -n "✦ ) "
read -r kooha_dir
kooha_dir=${kooha_dir:-"$HOME/Videos"}
kooha_dir=${kooha_dir:-"$HOME/Videos/Kooha"}
while [[ ! -d "$kooha_dir" || "$kooha_dir" == "/" || "$kooha_dir" != "$HOME"* ]]; do
echo -e "\e[31mInvalid directory! Please enter a valid directory path:\e[0m"
echo -n "✦ ) "
Expand Down Expand Up @@ -344,7 +348,30 @@ initial_setup() {
fi
fi
fi
create_default_config "$service" "$auth_token" "$fps" "$crf" "$preset" "$pixelformat" "$extpixelformat" "$wlscreenrec" "$codec" "$directory" "$failsave" "$save"

if [[ "$XDG_SESSION_TYPE" == "wayland" || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mDo you want to start notifications? (Y/N):\e[0m"
echo -n "✦ ) "
read -r startnotif
if [[ -z "$startnotif" || "$startnotif" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
startnotif=true
else
startnotif=false
fi
fi

if [[ "$XDG_SESSION_TYPE" == "wayland" || "$XDG_SESSION_TYPE" == "x11" ]]; then
echo -e "\e[33mDo you want to end notifications? (Y/N):\e[0m"
echo -n "✦ ) "
read -r endnotif
if [[ -z "$endnotif" || "$endnotif" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
endnotif=true
else
endnotif=false
fi
fi

create_default_config "$service" "$auth_token" "$fps" "$crf" "$preset" "$pixelformat" "$extpixelformat" "$wlscreenrec" "$codec" "$directory" "$failsave" "$save" "$encoder" "$startnotif" "$endnotif"
}

check_dependencies
Expand Down Expand Up @@ -387,7 +414,7 @@ if [[ -f "$CONFIG_FILE" ]]; then
update_config
fi

if [[ -z "$1" ]]; then
if [[ -z "$1" || ( "$1" == "auto" && -z "$2" ) ]]; then
options=("record" "shot" "upload" "ǀ" "")
selected=0
tput clear
Expand Down Expand Up @@ -464,17 +491,16 @@ if [[ -z "$1" ]]; then
error_message="ERROR: Service is none."
hpad=$(((cols - ${#error_message}) / 2))
printf "%${hpad}s\033[1;5;31mERROR:\033[0m Service is none.\n"
text="Would you like to add a service? (Y/N): "
hpad=$(((cols - ${#text}) / 2))
printf "%${hpad}s%s" "" "$text"
printf "%${hpad}s%s" "" "Would you like to add a service? (Y/N): "
read -r add_service
if [[ "$add_service" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
prompt_service=true
initial_setup
exec "$0" "$@"
fi
else
tput cnorm
else
tput cnorm
if [[ "$XDG_SESSION_TYPE" == "wayland" && ("$XDG_CURRENT_DESKTOP" == "GNOME" || "$XDG_CURRENT_DESKTOP" == "KDE" || "$XDG_CURRENT_DESKTOP" == "COSMIC") ]]; then
default_save_dir="$(eval echo $kooha_dir)"
else
Expand Down

0 comments on commit d2c9f0e

Please sign in to comment.