Hello,
I would like to share with you my solution for auto deleting expired recordings:
All items of a "DVR AutoRec Entry" have a field called "Retention". From my understanding, this is the time in days after the recording is deleted from the TVheadend "finished Recordings" list. The recording is not shown in a frontend (like Kodi) anymore, but the actual file on the harddisk is not deleted. I have not found an official solution for deleting the recorded files after the retention time automatically.
So I have written a small shell script which does the job, at least for my setup. I would like to mention that I am not an expert in programming by any means, so the script probably has some shortcomings. Please use at you own risk. I'm not responsible for any accidentally deleted files. For testing purposes I would recommend to comment out the line "while read line; do rm "$line" ;done < $MyFile4", where the actual deletion happens.
The script is run by a cron job at my setup and sends the list of the deleted files by email.
Please feel free to comment and improve the attached script, since there may be cases of interest not being included at the moment.
Cheers, Thomas
#!/bin/bash
# Settings:
MyEmail="recordings@myemail.com"
MyTVhFolder="/home/hts/.hts/tvheadend/dvr/log"
MyRecordingsFolder="/srv/smb-freigaben/recordings"
# Create temp files:
MyFile1="/tmp/myFile1.txt"
MyFile2="/tmp/myFile2.txt"
MyFile3="/tmp/myFile3.txt"
MyFile4="/tmp/myFile4.txt"
if [ -f $MyFile1 ] ; then rm $MyFile1 ; fi
if [ -f $MyFile2 ] ; then rm $MyFile2 ; fi
if [ -f $MyFile3 ] ; then rm $MyFile3 ; fi
if [ -f $MyFile4 ] ; then rm $MyFile4 ; fi
touch $MyFile1
touch $MyFile2
touch $MyFile3
touch $MyFile4
# List all recordings in recordings folder and write to file1:
echo ""
echo "All recordings in recordings directory:"
find $MyRecordingsFolder -maxdepth 1 -type f | sort | tee -a $MyFile1
# List all recordings in tvheadend, sort and write to file3:
echo ""
echo "All recordings in TVheadend:"
for file in $MyTVhFolder/*
do
cat $file | grep filename | awk -F'"' '{print $4}' >> $MyFile2
done
sort $MyFile2 | tee -a $MyFile3
# Difference of file1 and file3 for subsequent usage:
echo ""
comm -3 $MyFile1 $MyFile3 > $MyFile4
# Actual deletion, if any:
if [ -n "$(cat $MyFile4)" ]; then
echo "Yes, the following files will be deleted:"
echo "$(cat $MyFile4)"
cat $MyFile4 | mail -s "TVheadend: deleted recordings from $(date +"%d.%m.%Y")" $MyEmail
cd $MyRecordingsFolder
while read line; do rm "$line" ;done < $MyFile4
else
echo "No, nothing will be deleted."
fi
# Cleanup:
rm $MyFile1
rm $MyFile2
rm $MyFile3
rm $MyFile4
echo ""