Skip to content

Commit f48f84d

Browse files
committed
New: add qbit_manage API trigger script
Script sends POST requests to qbit_manage Web API to trigger commands for specific torrent hashes. Designed to be called by qBittorrent with the %I variable to run commands on torrent completion. Uses qbit_manage v4.5+ Web API endpoint /api/run-command
1 parent 88b4bb5 commit f48f84d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

qbm-api-trigger.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)