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