This script add Categories to Automatically add torrents from per Monitored Folder
👉 This script is in flux, as it may be implemented into qBittorrent in the future.
savecategory
expects the user's watch directories to look similar to something like this:
It's based off Docker guide for setting up hard links between virtual volumes (Docker) and machine volumes.
Save the script below as savecategory
and make it executable via chmod 755 /path/to/savecategory
.
#!/bin/sh
category="$(basename $1)"
torrent_hash="$2"
torrent_name="$3"
host="http://localhost:8112"
username="admin"
password="adminadmin"
echo "running savecategory script"
echo "\tgetting cookie"
cookie=$(curl --silent --fail --show-error \
--header "Referer: $host" \
--cookie-jar - \
--data "username=$username&password=$password" \
--request POST "$host/api/v2/auth/login")
if [ -z "$cookie" ]; then
echo "Login failed, exiting script."
exit 1
fi
echo "\tsetting $torrent_name to category $category"
echo "$cookie" | curl --silent --fail --show-error \
--cookie - \
--header "Content-Type: application/x-www-form-urlencoded" \
--data "hashes=$torrent_hash&category=$category" \
--request POST "$host/api/v2/torrents/setCategory"
echo "completed savecategory script"
exit 0
ℹ️ Make sure to replace the
username
andpassword
with your credentials before using or else this will not work. Another caveat is that if your password contains#
or&
, you'll need to replace with ASCII encoded characters.🔗 gist for potential script changes or comments.
And set Run external program on torrent completion to:
/path/to/savecategory "%D" "%I" "%N"
On completion, the category will change based on the directory name the .torrent
file was placed in the watch directory.
The wiki states...
This is a little misleading, it would be better if written something more like;
At the moment, the text reads as though the cat is set "whenever" the torrent is dropped into the watched folder.