Skip to content

Commit c95f917

Browse files
adapowerszakkarrybakerboy448
authored
(feat) xseed.sh: Add multiple download client support (#27)
* Add multiple client support * Add space tolerance and IFS restore * Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * Update xseed.sh Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> * Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * Update xseed.sh * intitial multi-client support variables * parse and trim for multi-client array conversion * switch to array types for configuration variables Co-authored-by: zakary <zak@ary.dev> Update xseed.sh Co-authored-by: zakary <zak@ary.dev> * refactor client validation function and logic Update xseed.sh Update xseed.sh Update xseed.sh Co-Authored-By: zakary <zak@ary.dev> * update .env.sample for multi client format instructions * refactor for env var parsing and config initialization * bump xseed.sh version to 4.0.0 Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> --------- Co-authored-by: zakary <zak@ary.dev> Co-authored-by: bakerboy448 <55419169+bakerboy448@users.noreply.github.com>
1 parent 9bc08b7 commit c95f917

2 files changed

Lines changed: 65 additions & 17 deletions

File tree

.env.sample

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Rename this file to .env and fill in the values accordingly.
44
# Xseed
55
## Download Client Names
6-
TORRENT_CLIENT_NAME="" # Example: "Qbit"
7-
USENET_CLIENT_NAME="" # Example: "SABnzbd"
6+
### For multiple clients, use format: "client1,client2,client3"
7+
### Do not include extra spaces around commas!
8+
TORRENT_CLIENTS="" # Examples: "Qbit", "Qbit,Deluge"
9+
USENET_CLIENTS="" # Examples: "SABnzbd", "SABnzbd,SABnzbd Anime"
810
## Cross Seed API configuration
911
XSEED_HOST="" # Example: "crossseed"
1012
XSEED_PORT="" # Example: "2468"

xseed.sh

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
# Load environment variables from .env file if it exists
1010
# in the same directory as this bash script
11-
VERSION='3.1.0'
11+
VERSION='4.0.0'
1212
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
ENV_PATH="$SCRIPT_DIR/.env"
14+
OLD_IFS="$IFS"
1415

1516
# Function to log messages
1617
log_message() {
@@ -42,23 +43,70 @@ else
4243
log_message "DEBUG" ".env file not found in script directory ($ENV_PATH)"
4344
fi
4445

46+
### START OF CONFIGURATION SECTION
47+
### START OF CONFIGURATION SECTION
48+
4549
# Use environment variables with descriptive default values
46-
TORRENT_CLIENT_NAME=${TORRENT_CLIENT_NAME:-Qbit}
47-
USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd}
50+
# If you are not using environmental variables set your client
51+
# in the ELSE section of the following if-else statement
52+
53+
if [[ -n "$TORRENT_CLIENTS" || -n "$USENET_CLIENTS" ]]; then
54+
# Convert from env to arrays
55+
IFS=','
56+
read -r -a TORRENT_CLIENTS <<<"$TORRENT_CLIENTS"
57+
read -r -a USENET_CLIENTS <<<"$USENET_CLIENTS"
58+
else
59+
# If you are not using environmental variables set your client here
60+
# format for up to as many clients as you need
61+
# Multiple clients: (${TORRENT_CLIENTS:-"Qbit","Qbit2"})
62+
# Single Client: (${TORRENT_CLIENTS:-"Qbit"})
63+
TORRENT_CLIENTS=("Qbit")
64+
USENET_CLIENTS=("SABnzbd")
65+
fi
66+
4867
XSEED_HOST=${XSEED_HOST:-crossseed}
4968
XSEED_PORT=${XSEED_PORT:-8080}
5069
LOG_FILE=${LOG_FILE:-/config/xseed.log}
5170
LOGID_FILE=${LOGID_FILE:-/config/xseed-id.log}
5271
XSEED_APIKEY=${XSEED_APIKEY:-}
72+
73+
### END OF CONFIGURATION SECTION
74+
75+
# Restore original IFS
76+
IFS="$OLD_IFS"
77+
5378
log_message "DEBUG" "Using '.env' file for config?: $EVAR"
5479
log_message "INFO" "Using Configuration:"
55-
log_message "INFO" "TORRENT_CLIENT_NAME=$TORRENT_CLIENT_NAME"
56-
log_message "INFO" "USENET_CLIENT_NAME=$USENET_CLIENT_NAME"
80+
log_message "INFO" "TORRENT_CLIENTS=$(printf '"%s" ' "${TORRENT_CLIENTS[@]}")"
81+
log_message "INFO" "USENET_CLIENTS=$(printf '"%s" ' "${USENET_CLIENTS[@]}")"
5782
log_message "INFO" "XSEED_HOST=$XSEED_HOST"
5883
log_message "INFO" "XSEED_PORT=$XSEED_PORT"
5984
log_message "INFO" "LOG_FILE=$LOG_FILE"
6085
log_message "INFO" "LOGID_FILE=$LOGID_FILE"
6186

87+
# Function to check if a client is in the allowed list
88+
is_valid_client() {
89+
local client="$1"
90+
local client_type="$2"
91+
case $client_type in
92+
"torrent")
93+
for allowed_client in "${TORRENT_CLIENTS[@]}"; do
94+
if [[ "$client" == "$allowed_client" ]]; then
95+
return 0
96+
fi
97+
done
98+
;;
99+
"usenet")
100+
for allowed_client in "${USENET_CLIENTS[@]}"; do
101+
if [[ "$client" == "$allowed_client" ]]; then
102+
return 0
103+
fi
104+
done
105+
;;
106+
esac
107+
return 1
108+
}
109+
62110
# Function to send a request to Cross Seed API
63111
cross_seed_request() {
64112
local endpoint="$1"
@@ -175,30 +223,28 @@ send_data_search() {
175223
handle_operations() {
176224
detect_application
177225
validate_process
178-
case "$clientID" in
179-
"$TORRENT_CLIENT_NAME")
180-
log_message "INFO" "Processing torrent client operations..."
226+
# Check if client is a torrent client
227+
if is_valid_client "$clientID" "torrent"; then
228+
log_message "INFO" "Processing torrent client operations for $clientID..."
181229
if [ -n "$downloadID" ]; then
182230
xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID")
183231
fi
184232
if [ "$xseed_resp" != "204" ]; then
185233
sleep 15
186234
send_data_search
187235
fi
188-
;;
189-
"$USENET_CLIENT_NAME")
236+
# Check if client is a usenet client
237+
elif is_valid_client "$clientID" "usenet"; then
190238
if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then
191239
log_message "WARN" "Depreciated Action. Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!"
192240
exit 0
193241
fi
194-
log_message "INFO" "Processing Usenet client operations..."
242+
log_message "INFO" "Processing Usenet client operations for $clientID..."
195243
send_data_search
196-
;;
197-
*)
244+
else
198245
log_message "ERROR" "Unrecognized client $clientID. Exiting."
199246
exit 2
200-
;;
201-
esac
247+
fi
202248

203249
log_message "INFO" "Cross-seed API response: $xseed_resp"
204250
if [ "$xseed_resp" == "204" ]; then

0 commit comments

Comments
 (0)