From d2c9f0ef998bbf245b01be56aabc633b1dd33b72 Mon Sep 17 00:00:00 2001 From: Cortex <126973723+verysillycat@users.noreply.github.com> Date: Sat, 7 Dec 2024 15:36:02 -0600 Subject: [PATCH] script & components: V1.2 * 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 --- components/functions/config.sh | 8 +++-- components/functions/core.sh | 24 +++++++++----- components/functions/variables.sh | 21 +++++++++++++ components/shot.sh | 12 +++++++ vnrez.sh | 52 +++++++++++++++++++++++-------- 5 files changed, 93 insertions(+), 24 deletions(-) diff --git a/components/functions/config.sh b/components/functions/config.sh index 8b19767..62eaaf4 100755 --- a/components/functions/config.sh +++ b/components/functions/config.sh @@ -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="" @@ -37,8 +39,8 @@ encoder=$encoder save=$save failsave=$failsave colorworkaround=false -startnotif=true -endnotif=true +startnotif=$startnotif +endnotif=$endnotif wlscreenrec=$wlscreenrec codec=$codec diff --git a/components/functions/core.sh b/components/functions/core.sh index 451fc96..47fb4d6 100755 --- a/components/functions/core.sh +++ b/components/functions/core.sh @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" diff --git a/components/functions/variables.sh b/components/functions/variables.sh index fc4bb49..d3c2c97 100755 --- a/components/functions/variables.sh +++ b/components/functions/variables.sh @@ -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" +) diff --git a/components/shot.sh b/components/shot.sh index 22bca48..bd848ef 100755 --- a/components/shot.sh +++ b/components/shot.sh @@ -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 diff --git a/vnrez.sh b/vnrez.sh index b2e8d84..b717156 100755 --- a/vnrez.sh +++ b/vnrez.sh @@ -11,6 +11,14 @@ 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 @@ -18,11 +26,6 @@ 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") @@ -170,6 +173,7 @@ initial_setup() { tput sc while true; do + trap handle_resize SIGWINCH tput rc tput civis tput el @@ -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 "✦ ) " @@ -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 @@ -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 @@ -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