Webhooks - godver3/cli_debrid GitHub Wiki

Webhooks

Overseerr

  1. In Overseerr go to Settings
  2. Then go to Notifications
  3. Then select Webhook
  4. Enable the agent and add your cli_debrid instance URL and port
  5. Click Test and Save at the bottom of the page

Zurg - Symlinking

This is used specifically for Symlinking when adding items outside of cli_debrid to allow it to pick them up and create Symlinks (i.e. via DMM)

  1. In your Zurg config.yml under "on_library_update" add:
on_library_update: sh ./cli_update.sh "$@"
  1. Create a new cli_update.sh file. This script will verify the folder's presence in your rclone drive, and the presence of at least one file within. The cli_update.sh file will contain:
#!/bin/bash

# Configuration
webhook_url="http://localhost:5000/webhook/rclone"  # Replace with your actual webhook URL
zurg_mount_base="/mnt/zurg/__all__" # Base path for checking files including __all__, replace with your actual mount location
max_attempts=25       # Total attempts (1 initial + 24 retries or 4 minutes)
initial_delay=1      # Seconds before first check
retry_interval=10     # Seconds between retries

# Notify webhook for each item after verification
for arg in "$@"
do
    # Clean the argument
    # First, strip any parent folder(s) from the argument to get the base filename.
    # The '--' ensures that arguments starting with a hyphen are treated as filenames.
    arg_basename=$(basename -- "$arg")
    # Then, apply the original cleaning step to remove any backslashes.
    arg_clean=$(echo "$arg_basename" | sed 's/\\//g')
    # Construct the full path to check
    full_path="$zurg_mount_base/$arg_clean"

    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verifying path: $full_path"

    path_valid=false
    attempt=1

    # Initial delay before the first check
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Initial delay for $initial_delay seconds..."
    /bin/sleep $initial_delay # Using /bin/sleep
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Initial delay finished."


    while [ $attempt -le $max_attempts ]; do
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Attempt $attempt/$max_attempts: Checking for '$full_path'"
        # Check if the path exists and is a directory
        if [ -d "$full_path" ]; then
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory found: $full_path"
            # Check if the directory is not empty
            if [ -n "$(find "$full_path" -mindepth 1 -print -quit 2>/dev/null)" ]; then
                echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory is not empty: $full_path"
                path_valid=true
                break # Exit the verification loop
            else
                echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory is empty: $full_path"
            fi
        else
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Path is not a directory or does not exist: $full_path"
        fi

        # If not the last attempt and path is not yet valid, wait before retrying
        if [ "$path_valid" = false ] && [ $attempt -lt $max_attempts ]; then
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Path not fully verified. Waiting $retry_interval seconds before retry..."
            /bin/sleep $retry_interval # Using /bin/sleep
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Retry delay finished." # Added log after sleep
        fi

        # Increment attempt counter
        attempt=$((attempt + 1))
    done

    # Proceed only if the path was validated (directory exists and is not empty)
    if [ "$path_valid" = true ]; then
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verification successful. Notifying webhook for: $arg_clean"
        /bin/sleep 5 # Final sleep
        # URL-encode the cleaned argument
        encoded_webhook_arg=$(echo -n "$arg_clean" | python3 -c "import sys, urllib.parse as ul; print(ul.quote(sys.stdin.read()))")
        # Call the webhook
        curl -s -X GET "$webhook_url?file=$encoded_webhook_arg"
        echo # Add a newline after curl for better log readability
    else
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verification failed for '$full_path' after $max_attempts attempts. Skipping webhook."
    fi
done

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Updates completed!"
  1. Ensure your Zurg instance can access both the config.yml and cli_update.sh file

Zurg - Plex Update

This is used to update Plex directly from Zurg as media items become available locally

  1. In your Zurg config.yml under "on_library_update" add:
on_library_update: sh ./cli_update.sh "$@"
  1. Create a new cli_update.sh file. This script will verify the folder's presence in your rclone drive, and the presence of at least one file within. The cli_update.sh file will contain:
#!/bin/bash

# Configuration
zurg_mount_base="/mnt/zurg/__all__" # Base path for checking files including __all__, replace with your actual mount location
max_attempts=25       # Total attempts (1 initial + 24 retries or 4 minutes)
initial_delay=1      # Seconds before first check
retry_interval=10     # Seconds between retries

# Plex Configuration - REPLACE THESE WITH YOUR ACTUAL PLEX DETAILS
plex_url="YOUR_PLEX_URL" # e.g., http://localhost or http://192.168.1.100
plex_port="32400"        # Default Plex port is 32400
plex_token="YOUR_PLEX_TOKEN" # Your Plex access token

# Process each argument
for arg in "$@"
do
    # Clean the argument
    arg_basename=$(basename -- "$arg")
    arg_clean=$(echo "$arg_basename" | sed 's/\\//g')
    # Construct the full path that Plex will scan
    full_path_to_scan="$zurg_mount_base/$arg_clean"

    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verifying path: $full_path_to_scan"

    path_valid=false
    attempt=1

    # Initial delay before the first check
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Initial delay for $initial_delay seconds..."
    /bin/sleep $initial_delay
    echo "[$(date '+%Y-%m-%d %H:%M:%S')] Initial delay finished."

    while [ $attempt -le $max_attempts ]; do
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Attempt $attempt/$max_attempts: Checking for '$full_path_to_scan'"
        if [ -d "$full_path_to_scan" ]; then
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory found: $full_path_to_scan"
            if [ -n "$(find "$full_path_to_scan" -mindepth 1 -print -quit 2>/dev/null)" ]; then
                echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory is not empty: $full_path_to_scan"
                path_valid=true
                break
            else
                echo "[$(date '+%Y-%m-%d %H:%M:%S')] Directory is empty: $full_path_to_scan"
            fi
        else
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Path is not a directory or does not exist: $full_path_to_scan"
        fi

        if [ "$path_valid" = false ] && [ $attempt -lt $max_attempts ]; then
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Path not fully verified. Waiting $retry_interval seconds before retry..."
            /bin/sleep $retry_interval
            echo "[$(date '+%Y-%m-%d %H:%M:%S')] Retry delay finished."
        fi
        attempt=$((attempt + 1))
    done

    if [ "$path_valid" = true ]; then
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verification successful for $full_path_to_scan. Triggering Plex scan."
        /bin/sleep 5 # Optional: Final sleep before calling Plex

        # URL-encode the full path to be scanned by Plex
        # Ensure python3 is in your venv at /root/myenv as per custom instructions
        encoded_plex_path=$(echo -n "$full_path_to_scan" | /root/myenv/bin/python3 -c "import sys, urllib.parse as ul; print(ul.quote(sys.stdin.read()))")
        
        # Construct the Plex API URL
        plex_api_url="$plex_url:$plex_port/library/sections/all/refresh?path=$encoded_plex_path&X-Plex-Token=$plex_token"
        
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Calling Plex API: $plex_url:$plex_port/library/sections/all/refresh?path=...&X-Plex-Token=TOKEN_HIDDEN" # Log URL without sensitive parts
        # Call the Plex API
        curl -s -X GET "$plex_api_url"
        echo # Add a newline after curl for better log readability
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Plex scan initiated for: $full_path_to_scan"
    else
        echo "[$(date '+%Y-%m-%d %H:%M:%S')] Verification failed for '$full_path_to_scan' after $max_attempts attempts. Skipping Plex scan."
    fi
done

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Plex update process completed!"
  1. Ensure your Zurg instance can access both the config.yml and cli_update.sh file