|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# run_qbit_manage_commands.sh |
| 4 | +# |
| 5 | +# Sends a POST request to qBit Manage with a given torrent hash to trigger |
| 6 | +# actions like "tag_update" and "share_limits". |
| 7 | +# |
| 8 | +# USAGE: |
| 9 | +# ./run_qbit_manage_commands.sh <torrent_hash> |
| 10 | +# |
| 11 | +# EXAMPLE: |
| 12 | +# ./run_qbit_manage_commands.sh 123ABC456DEF789XYZ |
| 13 | +# |
| 14 | +# NOTES: |
| 15 | +# - Make sure this script is executable: chmod +x run_qbit_manage_commands.sh |
| 16 | +# - The torrent hash is typically passed in automatically by qBittorrent via the "%I" variable. |
| 17 | +# - All output is logged to run_qbit_manage_commands.log in the same directory as the script, |
| 18 | +# and also printed to stdout. |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +API_URL="http://127.0.0.1:4269/api/run-command" |
| 23 | +COMMANDS='["tag_update", "share_limits", "rem_unregistered", "recheck"]' |
| 24 | + |
| 25 | +if [[ $# -lt 1 || -z "$1" ]]; then |
| 26 | + echo "Usage: $0 <torrent_hash>" >&2 |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +TORRENT_HASH="$1" |
| 31 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 32 | +LOG_FILE="${SCRIPT_DIR}/run_qbit_manage_commands.log" |
| 33 | + |
| 34 | +JSON="{\"commands\":${COMMANDS},\"hashes\":[\"${TORRENT_HASH}\"]}" |
| 35 | + |
| 36 | +{ |
| 37 | + echo "Sending API call for hash: ${TORRENT_HASH}" |
| 38 | + echo "Payload: ${JSON}" |
| 39 | +} | tee -a "${LOG_FILE}" |
| 40 | + |
| 41 | +if curl -fsSL -X POST \ |
| 42 | + -H "Content-Type: application/json" \ |
| 43 | + -d "${JSON}" \ |
| 44 | + "${API_URL}" | tee -a "${LOG_FILE}"; then |
| 45 | + echo "Success" | tee -a "${LOG_FILE}" |
| 46 | +else |
| 47 | + echo "Error: qBit Manage API call failed for hash ${TORRENT_HASH}" | tee -a "${LOG_FILE}" |
| 48 | +fi |
0 commit comments