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