Jump to content

Bash script to remove Tdarr video source files


FunkyBuddha

Recommended Posts

Posted

I was able to improve Tdarr's performance by at least 2x. I did three things. First, I used a RAM drive for the cache. Second, I created a separate output folder. Third, I decoupled the delete function from the Tdarr flow to a script. You can run this ad hoc or scheduled.

Methodology:

  • Run the script and parm in the original folder
    • i.e. del_tdarr_orig.sh "/path/to/original_files
  • Create a list of all transcoded files
  • Use list to find and delete matching original video files
  • After the script runs, you can move the content of output folder to the original folder

vid_fmt.txt:

Quote

mp4
avi
mov
flv
wmv
mpeg
ogm
webm
m2ts
swf
mpg
vob
m2v
m4v
mts
ts
mov
qt
yuv
vob
3gp
3gpp
f4v
divx
ogv
asf
rm
rmvb
ram

Bash script:

Quote

del_tdarr_orig() {
    echo start - `date` > /var/log/del_tdarr_orig.log
    outfile=/path/to/tdarr_del_orig
    cat /dev/null > $outfile.txt

    if [[ -z "$1" ]]; then
        echo Missing parm, exiting...
        exit
    else
        echo fldr=$1 >> /var/log/del_tdarr_orig.log
        cd /path/to/tdarr_media/output
        find . -type f \( -iname \*.mkv \) -printf "\"%p\" \n" | sed 's/\.mkv//' > $outfile.tmp
        cd $1
    fi

    IFS=$'\n'       # make newlines the only separator
    for i in $(cat $outfile.tmp)
    do
        local f_nm=$(echo "$i" | xargs)
        for x in $(cat ~/vid_fmt.txt)
        do
            local f_name="$f_nm.$x"
            if [[ -f "$f_name" ]]; then
                rm "$f_name"
                echo "$f_name" >> $outfile.txt
                break
            fi
        done    
    done

    local emsg=$(wc -l $outfile.txt)
    local num_del=$(echo "$emsg" | awk '{ print $1 }')
    echo --- $emsg >> /var/log/del_tdarr_orig.log
    echo end - `date` >> /var/log/del_tdarr_orig.log
}

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...