From ca00d8a0c51490fe42fa4857df90215da1d62fe3 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 15 Nov 2024 14:54:42 -0500 Subject: [PATCH 01/16] Add multiple client support --- .env.sample | 6 ++++-- xseed.sh | 62 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.env.sample b/.env.sample index a6d33f8..4164138 100644 --- a/.env.sample +++ b/.env.sample @@ -3,8 +3,9 @@ # Rename this file to .env and fill in the values accordingly. # Xseed ## Download Client Names -TORRENT_CLIENT_NAME="" # Example: "Qbit" -USENET_CLIENT_NAME="" # Example: "SABnzbd" +### For multiple clients, use format: client1,client2,client3 +TORRENT_CLIENTS="" # Examples: "Qbit", "Qbit,Deluge" +USENET_CLIENTS="" # Examples: "SABnzbd", "SABnzbd,SABnzbd Anime" ## Cross Seed API configuration XSEED_HOST="" # Example: "crossseed" XSEED_PORT="" # Example: "2468" @@ -12,6 +13,7 @@ XSEED_PORT="" # Example: "2468" XSEED_APIKEY="" # Example: "your-api-key" ## Path to store the script's database of prior searches LOG_FILE="" # Example: "/config/xseed_db.log" +LOGID_FILE="" # Example: "/config/xseed-id.log" # ZFS Destory VERBOSE=0 MAX_FREQ=2 diff --git a/xseed.sh b/xseed.sh index f740237..c7e38bc 100755 --- a/xseed.sh +++ b/xseed.sh @@ -8,7 +8,7 @@ # Load environment variables from .env file if it exists # in the same directory as this bash script -VERSION='3.1.0' +VERSION='3.2.0' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_PATH="$SCRIPT_DIR/.env" @@ -43,22 +43,53 @@ else fi # Use environment variables with descriptive default values -TORRENT_CLIENT_NAME=${TORRENT_CLIENT_NAME:-Qbit} -USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd} +# For multiple clients, use format: client1,client2,client3 +TORRENT_CLIENTS=${TORRENT_CLIENTS:-"Qbit"} +USENET_CLIENTS=${USENET_CLIENTS:-"SABnzbd"} XSEED_HOST=${XSEED_HOST:-crossseed} XSEED_PORT=${XSEED_PORT:-8080} LOG_FILE=${LOG_FILE:-/config/xseed.log} LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log} XSEED_APIKEY=${XSEED_APIKEY:-} + +# Convert comma-separated strings to arrays +IFS=',' read -r -a TORRENT_CLIENT_ARRAY <<< "$TORRENT_CLIENTS" +IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" + log_message "DEBUG" "Using '.env' file for config?: $EVAR" -log_message "INFO" "Using Configuration:" -log_message "INFO" "TORRENT_CLIENT_NAME=$TORRENT_CLIENT_NAME" -log_message "INFO" "USENET_CLIENT_NAME=$USENET_CLIENT_NAME" +log_message "INFO" "Using configuration:" +log_message "INFO" "TORRENT_CLIENTS=$TORRENT_CLIENTS" +log_message "INFO" "USENET_CLIENTS=$USENET_CLIENTS" log_message "INFO" "XSEED_HOST=$XSEED_HOST" log_message "INFO" "XSEED_PORT=$XSEED_PORT" log_message "INFO" "LOG_FILE=$LOG_FILE" log_message "INFO" "LOGID_FILE=$LOGID_FILE" +# Function to check if a client is in the allowed list +is_valid_client() { + local client="$1" + local client_type="$2" + local valid=false + + if [ "$client_type" == "torrent" ]; then + for allowed_client in "${TORRENT_CLIENT_ARRAY[@]}"; do + if [ "$client" == "$allowed_client" ]; then + valid=true + break + fi + done + elif [ "$client_type" == "usenet" ]; then + for allowed_client in "${USENET_CLIENT_ARRAY[@]}"; do + if [ "$client" == "$allowed_client" ]; then + valid=true + break + fi + done + fi + + echo "$valid" +} + # Function to send a request to Cross Seed API cross_seed_request() { local endpoint="$1" @@ -175,9 +206,10 @@ send_data_search() { handle_operations() { detect_application validate_process - case "$clientID" in - "$TORRENT_CLIENT_NAME") - log_message "INFO" "Processing torrent client operations..." + + # Check if client is a torrent client + if [ "$(is_valid_client "$clientID" "torrent")" == "true" ]; then + log_message "INFO" "Processing torrent client operations for $clientID..." if [ -n "$downloadID" ]; then xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID") fi @@ -185,20 +217,18 @@ handle_operations() { sleep 15 send_data_search fi - ;; - "$USENET_CLIENT_NAME") + # Check if client is a usenet client + elif [ "$(is_valid_client "$clientID" "usenet")" == "true" ]; then if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then log_message "WARN" "Depreciated Action. Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!" exit 0 fi - log_message "INFO" "Processing Usenet client operations..." + log_message "INFO" "Processing Usenet client operations for $clientID..." send_data_search - ;; - *) + else log_message "ERROR" "Unrecognized client $clientID. Exiting." exit 2 - ;; - esac + fi log_message "INFO" "Cross-seed API response: $xseed_resp" if [ "$xseed_resp" == "204" ]; then From 0cad9da2d7bdc79bca17f43f80e346bf6060c389 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 15 Nov 2024 15:10:23 -0500 Subject: [PATCH 02/16] Add space tolerance and IFS restore --- xseed.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xseed.sh b/xseed.sh index c7e38bc..b226418 100755 --- a/xseed.sh +++ b/xseed.sh @@ -52,10 +52,22 @@ LOG_FILE=${LOG_FILE:-/config/xseed.log} LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log} XSEED_APIKEY=${XSEED_APIKEY:-} +# Save original IFS +OLD_IFS="$IFS" + # Convert comma-separated strings to arrays IFS=',' read -r -a TORRENT_CLIENT_ARRAY <<< "$TORRENT_CLIENTS" IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" +# Restore original IFS +IFS="$OLD_IFS" + +# Trim whitespace from array elements +TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/#[[:space:]]/}") +TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/%[[:space:]]/}") +USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/#[[:space:]]/}") +USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/%[[:space:]]/}") + log_message "DEBUG" "Using '.env' file for config?: $EVAR" log_message "INFO" "Using configuration:" log_message "INFO" "TORRENT_CLIENTS=$TORRENT_CLIENTS" From 8c934b41ad0c9a33cf072f760ed8f0084f993cf6 Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:29:59 -0500 Subject: [PATCH 03/16] Update xseed.sh Co-authored-by: zakary --- xseed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xseed.sh b/xseed.sh index b226418..0f54211 100755 --- a/xseed.sh +++ b/xseed.sh @@ -43,9 +43,11 @@ else fi # Use environment variables with descriptive default values -# For multiple clients, use format: client1,client2,client3 -TORRENT_CLIENTS=${TORRENT_CLIENTS:-"Qbit"} -USENET_CLIENTS=${USENET_CLIENTS:-"SABnzbd"} +# format for up to as many clients as you need +# Multiple clients: (${TORRENT_CLIENTS:-"Qbit","Qbit2"}) +# Single Client: (${TORRENT_CLIENTS:-"Qbit"}) +TORRENT_CLIENTS=(${TORRENT_CLIENTS:-"Qbit"}) +USENET_CLIENTS=(${USENET_CLIENTS:-"SABnzbd"}) XSEED_HOST=${XSEED_HOST:-crossseed} XSEED_PORT=${XSEED_PORT:-8080} LOG_FILE=${LOG_FILE:-/config/xseed.log} From af8078685e669f1ab4a66f01e2eb9541e8248aee Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:30:05 -0500 Subject: [PATCH 04/16] Update xseed.sh Co-authored-by: zakary --- xseed.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xseed.sh b/xseed.sh index 0f54211..f9b1bfd 100755 --- a/xseed.sh +++ b/xseed.sh @@ -64,11 +64,6 @@ IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" # Restore original IFS IFS="$OLD_IFS" -# Trim whitespace from array elements -TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/#[[:space:]]/}") -TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/%[[:space:]]/}") -USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/#[[:space:]]/}") -USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/%[[:space:]]/}") log_message "DEBUG" "Using '.env' file for config?: $EVAR" log_message "INFO" "Using configuration:" From aff59e01c60fcfb1a25cfa62e1d159b28d2cc48b Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:30:45 -0500 Subject: [PATCH 05/16] Update xseed.sh Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> --- xseed.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xseed.sh b/xseed.sh index f9b1bfd..d152df6 100755 --- a/xseed.sh +++ b/xseed.sh @@ -8,7 +8,7 @@ # Load environment variables from .env file if it exists # in the same directory as this bash script -VERSION='3.2.0' +VERSION='4.0.0' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_PATH="$SCRIPT_DIR/.env" From 02b22e7aab6dd4ace0091dbf07da670fbf4ca341 Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:30:55 -0500 Subject: [PATCH 06/16] Update xseed.sh Co-authored-by: zakary --- xseed.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xseed.sh b/xseed.sh index d152df6..3409c5c 100755 --- a/xseed.sh +++ b/xseed.sh @@ -96,7 +96,10 @@ is_valid_client() { done fi - echo "$valid" + if [[ "$valid" == "true" ]]; then + return 0 + fi + return 1 } # Function to send a request to Cross Seed API From 2c2fbdc4ad803aa2e7c0e9ff733f47b6d5c259a6 Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:31:01 -0500 Subject: [PATCH 07/16] Update xseed.sh Co-authored-by: zakary --- xseed.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xseed.sh b/xseed.sh index 3409c5c..d88d08c 100755 --- a/xseed.sh +++ b/xseed.sh @@ -220,7 +220,7 @@ handle_operations() { validate_process # Check if client is a torrent client - if [ "$(is_valid_client "$clientID" "torrent")" == "true" ]; then + if is_valid_client "$clientID" "torrent"; then log_message "INFO" "Processing torrent client operations for $clientID..." if [ -n "$downloadID" ]; then xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID") From d170e284c5660c191a1644fdc7b2902cc02edef4 Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:31:07 -0500 Subject: [PATCH 08/16] Update xseed.sh Co-authored-by: zakary --- xseed.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xseed.sh b/xseed.sh index d88d08c..e4a69b6 100755 --- a/xseed.sh +++ b/xseed.sh @@ -230,7 +230,7 @@ handle_operations() { send_data_search fi # Check if client is a usenet client - elif [ "$(is_valid_client "$clientID" "usenet")" == "true" ]; then + elif is_valid_client "$clientID" "usenet"; then if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then log_message "WARN" "Depreciated Action. Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!" exit 0 From 832fb962c15e600c9c5fd3e7c0a57e87518cf037 Mon Sep 17 00:00:00 2001 From: Ada Date: Sat, 16 Nov 2024 00:32:58 -0500 Subject: [PATCH 09/16] Update xseed.sh --- xseed.sh | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/xseed.sh b/xseed.sh index e4a69b6..1c2f814 100755 --- a/xseed.sh +++ b/xseed.sh @@ -78,27 +78,24 @@ log_message "INFO" "LOGID_FILE=$LOGID_FILE" is_valid_client() { local client="$1" local client_type="$2" - local valid=false - - if [ "$client_type" == "torrent" ]; then - for allowed_client in "${TORRENT_CLIENT_ARRAY[@]}"; do - if [ "$client" == "$allowed_client" ]; then - valid=true - break - fi - done - elif [ "$client_type" == "usenet" ]; then - for allowed_client in "${USENET_CLIENT_ARRAY[@]}"; do - if [ "$client" == "$allowed_client" ]; then - valid=true - break - fi - done - fi - - if [[ "$valid" == "true" ]]; then - return 0 - fi + case $client_type in + "torrent") + for allowed_client in "${TORRENT_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + break + fi + done + ;; + "usenet") + for allowed_client in "${USENET_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + break + fi + done + ;; + esac return 1 } From 17dca3e0b81a991a3ea38c3995f000a1f3b97ee9 Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 15 Nov 2024 14:54:42 -0500 Subject: [PATCH 10/16] intitial multi-client support variables --- .env.sample | 5 +++-- xseed.sh | 62 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/.env.sample b/.env.sample index 8c19793..13c5623 100644 --- a/.env.sample +++ b/.env.sample @@ -3,8 +3,9 @@ # Rename this file to .env and fill in the values accordingly. # Xseed ## Download Client Names -TORRENT_CLIENT_NAME="" # Example: "Qbit" -USENET_CLIENT_NAME="" # Example: "SABnzbd" +### For multiple clients, use format: client1,client2,client3 +TORRENT_CLIENTS="" # Examples: "Qbit", "Qbit,Deluge" +USENET_CLIENTS="" # Examples: "SABnzbd", "SABnzbd,SABnzbd Anime" ## Cross Seed API configuration XSEED_HOST="" # Example: "crossseed" XSEED_PORT="" # Example: "2468" diff --git a/xseed.sh b/xseed.sh index f740237..c7e38bc 100755 --- a/xseed.sh +++ b/xseed.sh @@ -8,7 +8,7 @@ # Load environment variables from .env file if it exists # in the same directory as this bash script -VERSION='3.1.0' +VERSION='3.2.0' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_PATH="$SCRIPT_DIR/.env" @@ -43,22 +43,53 @@ else fi # Use environment variables with descriptive default values -TORRENT_CLIENT_NAME=${TORRENT_CLIENT_NAME:-Qbit} -USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd} +# For multiple clients, use format: client1,client2,client3 +TORRENT_CLIENTS=${TORRENT_CLIENTS:-"Qbit"} +USENET_CLIENTS=${USENET_CLIENTS:-"SABnzbd"} XSEED_HOST=${XSEED_HOST:-crossseed} XSEED_PORT=${XSEED_PORT:-8080} LOG_FILE=${LOG_FILE:-/config/xseed.log} LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log} XSEED_APIKEY=${XSEED_APIKEY:-} + +# Convert comma-separated strings to arrays +IFS=',' read -r -a TORRENT_CLIENT_ARRAY <<< "$TORRENT_CLIENTS" +IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" + log_message "DEBUG" "Using '.env' file for config?: $EVAR" -log_message "INFO" "Using Configuration:" -log_message "INFO" "TORRENT_CLIENT_NAME=$TORRENT_CLIENT_NAME" -log_message "INFO" "USENET_CLIENT_NAME=$USENET_CLIENT_NAME" +log_message "INFO" "Using configuration:" +log_message "INFO" "TORRENT_CLIENTS=$TORRENT_CLIENTS" +log_message "INFO" "USENET_CLIENTS=$USENET_CLIENTS" log_message "INFO" "XSEED_HOST=$XSEED_HOST" log_message "INFO" "XSEED_PORT=$XSEED_PORT" log_message "INFO" "LOG_FILE=$LOG_FILE" log_message "INFO" "LOGID_FILE=$LOGID_FILE" +# Function to check if a client is in the allowed list +is_valid_client() { + local client="$1" + local client_type="$2" + local valid=false + + if [ "$client_type" == "torrent" ]; then + for allowed_client in "${TORRENT_CLIENT_ARRAY[@]}"; do + if [ "$client" == "$allowed_client" ]; then + valid=true + break + fi + done + elif [ "$client_type" == "usenet" ]; then + for allowed_client in "${USENET_CLIENT_ARRAY[@]}"; do + if [ "$client" == "$allowed_client" ]; then + valid=true + break + fi + done + fi + + echo "$valid" +} + # Function to send a request to Cross Seed API cross_seed_request() { local endpoint="$1" @@ -175,9 +206,10 @@ send_data_search() { handle_operations() { detect_application validate_process - case "$clientID" in - "$TORRENT_CLIENT_NAME") - log_message "INFO" "Processing torrent client operations..." + + # Check if client is a torrent client + if [ "$(is_valid_client "$clientID" "torrent")" == "true" ]; then + log_message "INFO" "Processing torrent client operations for $clientID..." if [ -n "$downloadID" ]; then xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID") fi @@ -185,20 +217,18 @@ handle_operations() { sleep 15 send_data_search fi - ;; - "$USENET_CLIENT_NAME") + # Check if client is a usenet client + elif [ "$(is_valid_client "$clientID" "usenet")" == "true" ]; then if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then log_message "WARN" "Depreciated Action. Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!" exit 0 fi - log_message "INFO" "Processing Usenet client operations..." + log_message "INFO" "Processing Usenet client operations for $clientID..." send_data_search - ;; - *) + else log_message "ERROR" "Unrecognized client $clientID. Exiting." exit 2 - ;; - esac + fi log_message "INFO" "Cross-seed API response: $xseed_resp" if [ "$xseed_resp" == "204" ]; then From dd5526f3baa2c6af98f7cd24101bf9546c710b6b Mon Sep 17 00:00:00 2001 From: Ada Date: Fri, 15 Nov 2024 15:10:23 -0500 Subject: [PATCH 11/16] parse and trim for multi-client array conversion --- xseed.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xseed.sh b/xseed.sh index c7e38bc..b226418 100755 --- a/xseed.sh +++ b/xseed.sh @@ -52,10 +52,22 @@ LOG_FILE=${LOG_FILE:-/config/xseed.log} LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log} XSEED_APIKEY=${XSEED_APIKEY:-} +# Save original IFS +OLD_IFS="$IFS" + # Convert comma-separated strings to arrays IFS=',' read -r -a TORRENT_CLIENT_ARRAY <<< "$TORRENT_CLIENTS" IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" +# Restore original IFS +IFS="$OLD_IFS" + +# Trim whitespace from array elements +TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/#[[:space:]]/}") +TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/%[[:space:]]/}") +USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/#[[:space:]]/}") +USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/%[[:space:]]/}") + log_message "DEBUG" "Using '.env' file for config?: $EVAR" log_message "INFO" "Using configuration:" log_message "INFO" "TORRENT_CLIENTS=$TORRENT_CLIENTS" From 15e2d84ec35006be73629706c7a3c48243e89fe6 Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:29:59 -0500 Subject: [PATCH 12/16] switch to array types for configuration variables Co-authored-by: zakary Update xseed.sh Co-authored-by: zakary --- xseed.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/xseed.sh b/xseed.sh index b226418..f9b1bfd 100755 --- a/xseed.sh +++ b/xseed.sh @@ -43,9 +43,11 @@ else fi # Use environment variables with descriptive default values -# For multiple clients, use format: client1,client2,client3 -TORRENT_CLIENTS=${TORRENT_CLIENTS:-"Qbit"} -USENET_CLIENTS=${USENET_CLIENTS:-"SABnzbd"} +# format for up to as many clients as you need +# Multiple clients: (${TORRENT_CLIENTS:-"Qbit","Qbit2"}) +# Single Client: (${TORRENT_CLIENTS:-"Qbit"}) +TORRENT_CLIENTS=(${TORRENT_CLIENTS:-"Qbit"}) +USENET_CLIENTS=(${USENET_CLIENTS:-"SABnzbd"}) XSEED_HOST=${XSEED_HOST:-crossseed} XSEED_PORT=${XSEED_PORT:-8080} LOG_FILE=${LOG_FILE:-/config/xseed.log} @@ -62,11 +64,6 @@ IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" # Restore original IFS IFS="$OLD_IFS" -# Trim whitespace from array elements -TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/#[[:space:]]/}") -TORRENT_CLIENT_ARRAY=("${TORRENT_CLIENT_ARRAY[@]/%[[:space:]]/}") -USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/#[[:space:]]/}") -USENET_CLIENT_ARRAY=("${USENET_CLIENT_ARRAY[@]/%[[:space:]]/}") log_message "DEBUG" "Using '.env' file for config?: $EVAR" log_message "INFO" "Using configuration:" From b63e5164beadf7f01003236405c97dbc8168dcdf Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:30:55 -0500 Subject: [PATCH 13/16] refactor client validation function and logic Update xseed.sh Update xseed.sh Update xseed.sh Co-Authored-By: zakary --- xseed.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/xseed.sh b/xseed.sh index f9b1bfd..cee1d2c 100755 --- a/xseed.sh +++ b/xseed.sh @@ -78,25 +78,25 @@ log_message "INFO" "LOGID_FILE=$LOGID_FILE" is_valid_client() { local client="$1" local client_type="$2" - local valid=false - - if [ "$client_type" == "torrent" ]; then - for allowed_client in "${TORRENT_CLIENT_ARRAY[@]}"; do - if [ "$client" == "$allowed_client" ]; then - valid=true - break - fi - done - elif [ "$client_type" == "usenet" ]; then - for allowed_client in "${USENET_CLIENT_ARRAY[@]}"; do - if [ "$client" == "$allowed_client" ]; then - valid=true - break - fi - done - fi - - echo "$valid" + case $client_type in + "torrent") + for allowed_client in "${TORRENT_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + break + fi + done + ;; + "usenet") + for allowed_client in "${USENET_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + break + fi + done + ;; + esac + return 1 } # Function to send a request to Cross Seed API @@ -217,7 +217,7 @@ handle_operations() { validate_process # Check if client is a torrent client - if [ "$(is_valid_client "$clientID" "torrent")" == "true" ]; then + if is_valid_client "$clientID" "torrent"; then log_message "INFO" "Processing torrent client operations for $clientID..." if [ -n "$downloadID" ]; then xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID") @@ -227,7 +227,7 @@ handle_operations() { send_data_search fi # Check if client is a usenet client - elif [ "$(is_valid_client "$clientID" "usenet")" == "true" ]; then + elif is_valid_client "$clientID" "usenet"; then if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then log_message "WARN" "Depreciated Action. Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!" exit 0 From 960d25a07f8bde15ce2814fd1f56bd4da608b543 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 16 Nov 2024 00:11:09 -0600 Subject: [PATCH 14/16] update .env.sample for multi client format instructions --- .env.sample | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 13c5623..7a2e159 100644 --- a/.env.sample +++ b/.env.sample @@ -3,7 +3,8 @@ # Rename this file to .env and fill in the values accordingly. # Xseed ## Download Client Names -### For multiple clients, use format: client1,client2,client3 +### For multiple clients, use format: "client1,client2,client3" +### Do not include extra spaces around commas! TORRENT_CLIENTS="" # Examples: "Qbit", "Qbit,Deluge" USENET_CLIENTS="" # Examples: "SABnzbd", "SABnzbd,SABnzbd Anime" ## Cross Seed API configuration From f2c8faab84467c56cfb0bb975895ec3658a049c9 Mon Sep 17 00:00:00 2001 From: zakary Date: Sat, 16 Nov 2024 00:28:13 -0600 Subject: [PATCH 15/16] refactor for env var parsing and config initialization --- xseed.sh | 73 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/xseed.sh b/xseed.sh index cee1d2c..395853f 100755 --- a/xseed.sh +++ b/xseed.sh @@ -11,6 +11,7 @@ VERSION='3.2.0' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_PATH="$SCRIPT_DIR/.env" +OLD_IFS="$IFS" # Function to log messages log_message() { @@ -42,33 +43,43 @@ else log_message "DEBUG" ".env file not found in script directory ($ENV_PATH)" fi +### START OF CONFIGURATION SECTION +### START OF CONFIGURATION SECTION + # Use environment variables with descriptive default values -# format for up to as many clients as you need -# Multiple clients: (${TORRENT_CLIENTS:-"Qbit","Qbit2"}) -# Single Client: (${TORRENT_CLIENTS:-"Qbit"}) -TORRENT_CLIENTS=(${TORRENT_CLIENTS:-"Qbit"}) -USENET_CLIENTS=(${USENET_CLIENTS:-"SABnzbd"}) +# If you are not using environmental variables set your client +# in the ELSE section of the following if-else statement + +if [[ -n "$TORRENT_CLIENTS" || -n "$USENET_CLIENTS" ]]; then + # Convert from env to arrays + IFS=',' + read -r -a TORRENT_CLIENTS <<<"$TORRENT_CLIENTS" + read -r -a USENET_CLIENTS <<<"$USENET_CLIENTS" +else + # If you are not using environmental variables set your client here + # format for up to as many clients as you need + # Multiple clients: (${TORRENT_CLIENTS:-"Qbit","Qbit2"}) + # Single Client: (${TORRENT_CLIENTS:-"Qbit"}) + TORRENT_CLIENTS=("Qbit") + USENET_CLIENTS=("SABnzbd") +fi + XSEED_HOST=${XSEED_HOST:-crossseed} XSEED_PORT=${XSEED_PORT:-8080} LOG_FILE=${LOG_FILE:-/config/xseed.log} LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log} XSEED_APIKEY=${XSEED_APIKEY:-} -# Save original IFS -OLD_IFS="$IFS" - -# Convert comma-separated strings to arrays -IFS=',' read -r -a TORRENT_CLIENT_ARRAY <<< "$TORRENT_CLIENTS" -IFS=',' read -r -a USENET_CLIENT_ARRAY <<< "$USENET_CLIENTS" +### END OF CONFIGURATION SECTION +### END OF CONFIGURATION SECTION # Restore original IFS IFS="$OLD_IFS" - log_message "DEBUG" "Using '.env' file for config?: $EVAR" -log_message "INFO" "Using configuration:" -log_message "INFO" "TORRENT_CLIENTS=$TORRENT_CLIENTS" -log_message "INFO" "USENET_CLIENTS=$USENET_CLIENTS" +log_message "INFO" "Using Configuration:" +log_message "INFO" "TORRENT_CLIENTS=$(printf '"%s" ' "${TORRENT_CLIENTS[@]}")" +log_message "INFO" "USENET_CLIENTS=$(printf '"%s" ' "${USENET_CLIENTS[@]}")" log_message "INFO" "XSEED_HOST=$XSEED_HOST" log_message "INFO" "XSEED_PORT=$XSEED_PORT" log_message "INFO" "LOG_FILE=$LOG_FILE" @@ -79,22 +90,20 @@ is_valid_client() { local client="$1" local client_type="$2" case $client_type in - "torrent") - for allowed_client in "${TORRENT_CLIENTS[@]}"; do - if [[ "$client" == "$allowed_client" ]]; then - return 0 - break - fi - done - ;; - "usenet") - for allowed_client in "${USENET_CLIENTS[@]}"; do - if [[ "$client" == "$allowed_client" ]]; then - return 0 - break - fi - done - ;; + "torrent") + for allowed_client in "${TORRENT_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + fi + done + ;; + "usenet") + for allowed_client in "${USENET_CLIENTS[@]}"; do + if [[ "$client" == "$allowed_client" ]]; then + return 0 + fi + done + ;; esac return 1 } @@ -215,7 +224,7 @@ send_data_search() { handle_operations() { detect_application validate_process - + # Check if client is a torrent client if is_valid_client "$clientID" "torrent"; then log_message "INFO" "Processing torrent client operations for $clientID..." From 1c92173b57ba7e8bb6282d8fcad528f090b08d0b Mon Sep 17 00:00:00 2001 From: Ada Powers <31081056+adapowers@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:30:45 -0500 Subject: [PATCH 16/16] bump xseed.sh version to 4.0.0 Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> --- xseed.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xseed.sh b/xseed.sh index 395853f..040668d 100755 --- a/xseed.sh +++ b/xseed.sh @@ -8,7 +8,7 @@ # Load environment variables from .env file if it exists # in the same directory as this bash script -VERSION='3.2.0' +VERSION='4.0.0' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_PATH="$SCRIPT_DIR/.env" OLD_IFS="$IFS"