Transmission - remove torrent when complete

Hi

I was wondering if any osmc out there in user-land have implemented a script to automatically remove torrent after completion from transmission?

I’ve done Google searches and tried a few of their recommendations, however the 2 I tried didn’t work.

Can anyone make any recommendations based on experience?

Cheers, Geoff.

Transmission 2.84 (14307)

See the first post on that thread. Really good guide.

You can use this script, I made it several months ago.

#!/bin/bash

ELEMENTS=/home/osmc/Downloads/*
DOWN_DIR="/home/osmc/Downloads"
DEST_DIR="/media/2TB_EHDD/ToClassify"
DATE="$(date)"

echo "$DATE"

#Test if /media/2TB_EHDD/ToClassify exists
if [ ! -d "$DEST_DIR" ]; then
    echo "Destination directory does not exist. Check if external drive "2TB_EHDD" is plugged and running"
    echo "Aborting..."
    exit 1
fi

#Test if there are sub-dir in Downloads directory
subdircount=`find $DOWN_DIR -maxdepth 1 -type d | wc -l`

#Test if there are files in Downloads directory
if [ ! "$(ls -A $DOWN_DIR)" ]; then
    echo "$DOWN_DIR is empty and thus contains no file. Nothing to process...."
    echo "Exiting $0"
    exit 1
fi

#Loop over files and folders in Downloads directory
shopt -s nullglob
for f in $ELEMENTS
do
	#if it's a file
        if [ -f "$f" ]; then
	    EXT="${f##*.}"
            filename=$(basename "$f")
	    #if filename does not end with 'part'
	    if [ $EXT != "part" ]; then
	        echo "Processing file '$filename'. Moving "$filename" to $DEST_DIR"
   	        mv -vf "$f" $DEST_DIR
	    else
	        echo "$filename download still in progress... Waiting for completion to move file to $MEDIA"
	    fi
	fi        
	#if it's a directory (works only with a depth of 1)
	if [ -d "$f" ]; then
	    folder=$f
	    countfilewithpart=0
            shopt -s nullglob
	    
	    for file in "$folder"/*
	    do
               #test if it's a file
	       if [ -f "$file" ]; then
                   subext="${file##*.}"
		   subfilename=`basename "$file"`
                   if [ $subext == "part" ]; then
		       echo "$subfilename download still in progress... Waiting for completion..."
                       countfilewithpart=$((countfilewithpart+1))
		   fi 
	       fi	
	    done
            
	    #There is no file which filename ends with 'part'
	    if [ $countfilewithpart == 0 ]; then
	        echo "Processing directory $folder , moving to $DEST_DIR"
		mv -vf "$folder" $DEST_DIR
            fi
	fi
done

exit 0

It assumes you are using transmission, and it appends “.part” at the end of the file it is downloading.
It also moves all the finished downloads to “/media/2TB_EHDD/ToCLassify”.
Let me know if you need any help with it.

And this one simply deletes all the files ending with “.torrent” in ‘/home/osmc/Downloads’:

#!/bin/bash

cd /home/osmc/Downloads

counter=0
shopt -s nullglob
for f in *.torrent
do
	rm -rvf "${f}"
	counter=$((counter+1))
done

if [ $counter == 0 ]; then
	echo "No torrent file to delete"
	exit 1
else
	exit 0
fi

You just have to use crontab then to schedule the execution of the script.

thanks, looks good.

I just want to delete my .torrent files once torrent file and been completed. Looks like this script will actually move the payload as well.

(i’ve configured Transmission to put in-progress torrent in a directory called incomplete, transmission will move to default directory as per the .json file).

Could i use just the ‘delete torrent when done’ portion?

Cheers and thanks for offer of assitance. Geoff.

thanks again, I imagine this is close to what i need? I imagine it woudl delete torrent prior to completion in accordance with the cronjob schedule…

cheers, geoff.

If you have already configured transmission to auto move the files when the downloads are completed, then you just have to use the second script I posted.
Just change the path of the first command to the path where the ‘.torrent’ files are kept (i.e : cd /path/to/torrents_files).
Save the script in a .sh file (i.e : deleteTorrents.sh).

Don’t forget to make it executable : sudo chmod +x /path/to/deleteTorrents.sh

Then schedule the job with cron :

crontab -e

append this line at the end of the file, the script will run every 10 minutes with no output at all.
0,10 * * * * /path/to/deleteTorrents.sh >> /dev/null 2>&1

if you want some output (to see which files have been deleted)
0,10 * * * * /path/to/deleteTorrents.sh >> /path/to/outputFile

Yep, it will definitely do the job.