Skip to content

Instantly share code, notes, and snippets.

@tuxity
Created January 31, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxity/0f23df40e5d7ace892f66bc860821bb9 to your computer and use it in GitHub Desktop.
Save tuxity/0f23df40e5d7ace892f66bc860821bb9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# socket you need to connect to
SCGI_SOCKET=127.0.0.1:5001
# list of tracker message to take into account
TODELETE=("Tracker: [Failure reason \"Torrent non trouve sur le Tracker\"]")
#function to find the torrent message in the array TODELETE
findMessage() {
index=0
while [ "${TODELETE[$index]}" != "$MESSAGE" ] && [ $index -lt "${#TODELETE[@]}" ]; do
((index++))
done
if [ $index -lt "${#TODELETE[@]}" ]; then
true
else
false
fi
}
#function to erase torrent and delete data
deleteTorrent() {
# get the full file name with directory
BASE_PATH=$(rtxmlrpc d.get_base_path "$torrent")
# delete torrent from rTorrent
rtxmlrpc d.stop "$torrent" &> /dev/null
rtxmlrpc d.close "$torrent" &> /dev/null
rtxmlrpc d.erase "$torrent" &> /dev/null
# delete file or directory from the system
# check if file/directory exists
if [ -e "$BASE_PATH" ]; then
# test if it's a file
if [ -f "$BASE_PATH" ]; then
# delete the file
rm "$BASE_PATH"
else
# delete the directory
rm -r "$BASE_PATH"
fi
fi
}
# check if rTorrent is running
#if test \! -S $SCGI_SOCKET; then
# echo >&2 "rTorrent is not running (no socket $SCGI_SOCKET)"
# exit 1
#fi
# get the list of .torrents running in rTorrent
LIST=($(rtxmlrpc download_list))
for torrent in ${LIST[@]}
do
MESSAGE=$(rtxmlrpc d.get_message $torrent)
if [ -n "$MESSAGE" ]; then
if findMessage; then
deleteTorrent
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment