Using the configuration file shown in my Transmission-Daemon setup post, Transmission will download files into the “downloading” folder until the download hits 100%. At that point, the downloaded files will be moved to the “seeding” folder. The torrent will remain active, seeding to other users, until it hits the seeding ratio, or until you pause or remove the torrent.
Left alone, these completed torrents will not be removed from the server, and will accumulate as you download more torrents over time. There is no automated way to remove these torrents. Also, there is no automated way to move files to a new folder after seeding is complete, only after downloading is complete.
My ultimate goals are to complete seeding up until my seeding ratio is hit, to move torrents out of the seeding folder once seeding is complete, and to use the TVNamer Python script to automatically move any TV episodes I have downloaded to my media server’s TV folder.
Because I want to use TVNamer to move and rename most of my downloads automatically, but I want them to be seeded up to the ratio I set, I cannot use TVNamer on my “seeding” folder. If I did so, there’s a big chance that files would be removed from my “seeding” folder before seeding was complete. To solve that, I decided to move all completed torrent downloads to another folder, “complete”, and set TVNamer to run on that folder. To move completed torrents, I created a Transmission queue management script, which performs the following actions every 15 minutes:
- Check for completed downloads that have either been paused manually or have seeded until the seeding ratio.
- Move the downloaded files to another folder (“complete”).
- Remove the torrent from the Transmission server.
Removing Completed Torrents Using a Script
Here is the script, which is based on my previous version. Compared to my last script, this one’s largest difference is the elimination of the netrc argument in the transmission-remote calls. I noticed that I did not need to send credentials to the Transmission daemon, presumably because my user account has all the privileges it needs to run transmission-remote.
A commenter on my previous post of this script informed me that Transmission 2.x uses “Finished” instead of “Stopped” to indicate completed torrents. I incorporated that change into the script, so that it will work with the old or the new verbiage.
Be sure to change the value of the MOVEDIR to the path you wish to move the downloads to. If you set it to “%1”, you can specify the path as a command-line argument.
Script file: /home/mjdescy/bin/removecompletedtorrents
#!/bin/sh
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
MOVEDIR=/home/mjdescy/media # the folder to move completed downloads to
# …or set MOVEDIR using the first command-line argument
# MOVEDIR=%1# 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 –list | sed -e ’1d;$d;s/^ *//’ | cut –only-delimited –delimiter= ” ” –fields=1`# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
echo “* * * * * Operations on torrent ID $TORRENTID starting. * * * * *”# check if torrent download is completed
DL_COMPLETED=`transmission-remote –torrent $TORRENTID –info | grep “Percent Done: 100%”`# check torrent’s current state is “Stopped”, “Finished”, or “Idle”
STATE_STOPPED=`transmission-remote –torrent $TORRENTID –info | grep “State: Stopped\|Finished\|Idle”`# 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 “Torrent #$TORRENTID is completed.”
echo “Moving downloaded file(s) to $MOVEDIR.”
transmission-remote –torrent $TORRENTID –move $MOVEDIR
echo “Removing torrent from list.”
transmission-remote –torrent $TORRENTID –remove
else
echo “Torrent #$TORRENTID is not completed. Ignoring.”
fiecho “* * * * * Operations on torrent ID $TORRENTID completed. * * * * *”
done
After creating the script file, be sure to make it executable.
$ sudo chmod u+x /home/mjdescy/bin/removecompletedtorrents
Scheduling the Script
Schedule execution of the script using cron.
$ crontab -e
I run the script every 10 minutes, with a 1-minute offset from the top of the hour. I redirect output to /dev/null so cron will not send me emails regarding the script’s output.
1,11,21,31,41,51 * * * * /home/mjdescy/bin/removecompletedtorrents > /dev/null 2>&1