Skip to content

Commit

Permalink
(feat) xseed.sh: add LOGID_FILE to track downloaded ids (#24)
Browse files Browse the repository at this point in the history
* (feat) xseed.sh: add LOGID_FILE to track downloaded ids

Move from log file to db

* tweak logging; actually use db file

* Update xseed.sh
  • Loading branch information
bakerboy448 authored Aug 18, 2024
1 parent 326d731 commit bcd0db4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 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='2.1.1'
VERSION='2.2.1'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_PATH="$SCRIPT_DIR/.env"

Expand Down Expand Up @@ -48,6 +48,7 @@ USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd}
XSEED_HOST=${XSEED_HOST:-crossseed}
XSEED_PORT=${XSEED_PORT:-8080}
LOG_FILE=${LOG_FILE:-/config/xseed.log}
LOGID_FILE=${LOG_FILE:-/config/xseed-id.log}
XSEED_APIKEY=${XSEED_APIKEY:-}
log_message "DEBUG" "Using '.env' file for config?: $EVAR"
log_message "INFO" "Using Configuration:"
Expand All @@ -56,6 +57,7 @@ log_message "INFO" "USENET_CLIENT_NAME=$USENET_CLIENT_NAME"
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 send a request to Cross Seed API
cross_seed_request() {
Expand Down Expand Up @@ -123,15 +125,16 @@ detect_application() {
# Validate the process
validate_process() {
[ ! -f "$LOG_FILE" ] && touch "$LOG_FILE"
[ ! -f "$LOGID_FILE" ] && touch "$LOGID_FILE"
unique_id="${downloadID}-${clientID}"

if [ -z "$unique_id" ]; then
log_message "ERROR" "Unique ID is missing. Exiting."
exit 1
fi

if grep -qF "$unique_id" "$LOG_FILE"; then
log_message "INFO" "Download ID $unique_id already processed. Exiting."
if grep -qF "$unique_id" "$LOGID_FILE"; then
log_message "INFO" "Download ID [$unique_id] already processed and logged in [$LOGID_FILE]. Exiting."
exit 0
fi

Expand Down Expand Up @@ -199,7 +202,7 @@ handle_operations() {

log_message "INFO" "Cross-seed API response: $xseed_resp"
if [ "$xseed_resp" == "204" ]; then
echo "$unique_id" >>"$LOG_FILE"
echo "$unique_id" >>"$LOGID_FILE"
log_message "INFO" "Process completed successfully."
else
if [ "$xseed_resp" == "000" ]; then
Expand Down

0 comments on commit bcd0db4

Please sign in to comment.