Skip to content

Commit

Permalink
Add multiple client support
Browse files Browse the repository at this point in the history
  • Loading branch information
adapowers committed Nov 15, 2024
1 parent 2f89ba0 commit ca00d8a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
6 changes: 4 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
# 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"
## API Key for Cross Seed, if applicable
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
Expand Down
62 changes: 46 additions & 16 deletions xseed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -175,30 +206,29 @@ 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
if [ "$xseed_resp" != "204" ]; then
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
Expand Down

0 comments on commit ca00d8a

Please sign in to comment.