Skip to content

Commit

Permalink
update(xseed.sh): usenet season pack support
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkarry authored and bakerboy448 committed Jul 22, 2024
1 parent 086470c commit 2d8c38d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All scripts are **Created By: [Bakerboy448](https://github.com/bakerboy448/) unl

- **Script:** `xseed.sh`
- **Description:** Triggers a cross-seed search post-import or post-upgrade in Starr applications.
- **Creator:** [Bakerboy448](https://github.com/bakerboy448/) with assitance from [zakkarry](https://github.com/zakkarry)
- **Setup:**
1. Copy `.env.sample` to `.env`.
2. Populate required values under "# Xseed" header.
Expand Down
57 changes: 38 additions & 19 deletions xseed.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
### UPDATED FOR SEASON PACK FROM USENET SUPPORT IN
### CROSS SEED v6 ONLY!! v5 IS NOT SUPPORTED FOR USENET
### SEASON PACKS AND WILL ALWAYS FAIL TO FIND MATCHES

### TO ENABLE THIS FEATURE YOU _MUST_ SWITCH TO THE
### ON IMPORT COMPLETE EVENT TYPE IN YOUR SONARR SETTINGS

# Load environment variables from .env file if it exists
if [ -f ".env" ]; then
Expand Down Expand Up @@ -42,13 +48,22 @@ detect_application() {
elif [ -n "$sonarr_eventtype" ]; then
app="sonarr"
# shellcheck disable=SC2154 # These are set by Starr on call
sonarrReleaseType="$sonarr_release_releasetype"
# shellcheck disable=SC2154 # These are set by Starr on call
clientID="$sonarr_download_client"
# shellcheck disable=SC2154 # These are set by Starr on call
downloadID="$sonarr_download_id"
# shellcheck disable=SC2154 # These are set by Starr on call
filePath="$sonarr_episodefile_path"
# shellcheck disable=SC2154 # These are set by Starr on call
folderPath="$sonarr_episodefile_sourcefolder"
if [ -n "$sonarrReleaseType" ] && [ "$sonarrReleaseType" == "SeasonPack" ]; then
# shellcheck disable=SC2154 # These are set by Starr on call
folderPath="$sonarr_destinationpath"
else
[ -z "$sonarr_release_releasetype" ] && {
# shellcheck disable=SC2154 # These are set by Starr on call
folderPath="$sonarr_episodefile_sourcefolder"
}
# shellcheck disable=SC2154 # These are set by Starr on call
filePath="$sonarr_episodefile_paths"
fi
# shellcheck disable=SC2154 # These are set by Starr on call
eventType="$sonarr_eventtype"
elif [ -n "$lidarr_eventtype" ]; then
Expand Down Expand Up @@ -96,43 +111,47 @@ validate_process() {
echo "Test event detected. Exiting."
exit 0
}
[ -z "$filePath" ] && [ -z "$downloadID" ] && {
[ -z "$filePath" ] && [ -z "$folderPath" ] && [ -z "$downloadID" ] && {
echo "Essential parameters missing. Exiting."
exit 1
}

if [ -z "$downloadID" ] || [ -z "$filePath" ]; then
if [ -z "$downloadID" ] && [[ -z "$filePath" || -z "$folderPath" ]]; then
echo "Download ID is missing. Checking if file path works for data/path based cross-seeding."
if [ -z "$filePath" ]; then
echo "File path is missing. Exiting."
if [[ -z "$filePath" && -z "$folderPath" ]]; then
echo "File and Folder paths are missing. Exiting."
exit 1
fi
fi

[ -z "$filePath" ] && [ -z "$downloadID" ] && {
echo "Essential parameters missing. Exiting."
exit 1
}
}

send_data_search() {
if [ -n "$sonarrReleaseType" ] && [ "$sonarrReleaseType" == "SeasonPack" ]; then
xseed_resp=$(cross_seed_request "webhook" "path=$folderPath")
else
xseed_resp=$(cross_seed_request "webhook" "path=$filePath")
fi
}
# Main logic for handling operations
handle_operations() {
detect_application
validate_process

case "$clientID" in
"$TORRENT_CLIENT_NAME")
echo "Processing torrent client operations..."
[ -n "$downloadID" ] && { xseed_resp=$(cross_seed_request "webhook" "infoHash=$downloadID"); }
[ "$xseed_resp" != "204" ] && sleep 15 && xseed_resp=$(cross_seed_request "webhook" "path=$filePath")
if [ "$xseed_resp" != "204" ]; then
sleep 15
send_data_search
fi
;;
"$USENET_CLIENT_NAME")
[[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]] && {
echo "Skipping season pack search."
if [ -z "$sonarrReleaseType" ] && [[ "$folderPath" =~ S[0-9]{1,2}(?!\.E[0-9]{1,2}) ]]; then {
echo "Skipping season pack search. Please switch to On Import Complete for Usenet Season Pack Support!"
exit 0
}
fi
echo "Processing Usenet client operations..."
xseed_resp=$(cross_seed_request "webhook" "path=$filePath")
send_data_search
;;
*)
echo "Unrecognized client $clientID. Exiting."
Expand Down

0 comments on commit 2d8c38d

Please sign in to comment.