Skip to content

Instantly share code, notes, and snippets.

@hvmonteiro
Last active June 12, 2024 05:35
Show Gist options
  • Save hvmonteiro/78364bb520d6d0b0da1279b110dc181b to your computer and use it in GitHub Desktop.
Save hvmonteiro/78364bb520d6d0b0da1279b110dc181b to your computer and use it in GitHub Desktop.
Script that allows the auto removal of downloaded/completed torrents from transmission BitTorrent daemon in OpenELEC/Kodi.
#!/bin/sh
# Originaly based on script https://community.wd.com/t/guide-auto-removal-of-downloads-from-transmission-2-82/93156
# adapted for OpenELEC Kodi
# port, username, password
SERVER="9091 --auth transmission:transmission"
# use transmission-remote to get torrent list from transmission-remote list
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut -s -d" " -f 1`
echo "$TERM" | grep -q "term"
if [ $? -eq 0 ]; then
transmission-remote $SERVER --list
fi
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
echo Processing : $TORRENTID
# check if torrent download is completed
DL_COMPLETED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "100%"`
# check torrents current state is
STATE_STOPPED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "State: Seeding\|Stopped\|Finished\|Idle"`
echo "$TERM" | grep -q "term" && echo $STATE_STOPPED
# if the torrent is "Stopped", "Finished", or "Idle after downloading 100%"
if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then
# move the files and remove the torrent from Transmission
echo "$TERM" | grep -q "term" && echo "Torrent #$TORRENTID is completed"
echo "$TERM" | grep -q "term" && echo "Removing torrent from list"
transmission-remote $SERVER --torrent $TORRENTID --remove
else
echo "$TERM" | grep -q "term" && echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
done
exit 0
@hvmonteiro
Copy link
Author

hvmonteiro commented Feb 11, 2020

mkdir .bin
cd .bin
wget https://gist.github.com/hvmonteiro/78364bb520d6d0b0da1279b110dc181b/raw/3ba306dc3ea43479129d2d3566e4a18560344cc7/transmission-purge-completed.sh
chmod a+x
  • stop transmission daemon
    systemctl stop service.downloadmanager.transmission.service

  • Search for and edit TransmissionBT settings file
    vi settings.json

change these 2 lines

"script-torrent-done-enabled": true,
"script-torrent-done-filename": “/storage/.bin/transmission-purge-completed.sh”,

where “script-torrent-done-filename” matches the path to the above script (ex: /storage/.bin/transmission-purge-completed.sh)

  • start transmission daemon:
    systemctl start service.downloadmanager.transmission.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment