Forums » Tutorial and setups »
Auto delete recorded files: solution
Added by Thomas Roth over 9 years ago
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="[email protected]" 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 ""
Replies (3)
RE: Auto delete recorded files: solution - Added by Hiro Protagonist over 9 years ago
Thanks very much - I was just looking for something like this.
I've made a few modifications:
1) I don't echo out all the files as I have hundreds...
2) I took out -maxdepth 1 from find, as I have my recordings in directories
3) Sometimes [I'm not sure why] TVH will record a program in more than 1 file, so you'll see:
PROG-NAME.YYYY-MM-DD.HH-MM-3.xyz logged as the filename, but it will actually have created files
with -2.xyz, -1.xyz and .xyz as well as the logged one. I had to do a bit of work to account for that.
4) I've also found some log files with no filename entry - no sure what this means, but currently I just
ignore them.
5) After deleting a file, I attempt to delete the directory so as to clean up empty dirs. You'll
want to remove this if you don't put your progs in separate dirs.
pvrclean.sh (2.43 KB) pvrclean.sh | PVR Cleanup script |
RE: Auto delete recorded files: solution - Added by redpeat . about 9 years ago
Thanks for coming up with this. It's been working for me, until this past night. I recorded a program on 10/8/2015 and had Hiro's modified script execute at 11PM last night as usual.
Here's the content of my recordings folder:
hts@tvheadend:~$ ls -lh /mnt/dvr/recordings/
drwxr-xr-x 1 hts video 3 Oct 8 15:59 Odd-Squad
hts@tvheadend:~$ ls -lh /mnt/dvr/recordings/Odd-Squad/
-rwxr-xr-x 1 hts video 2.6G Oct 8 16:30 Odd-Squad.S01E33.2015-10-08.16-00.mkv
However I didn't receive the usual notification that the script ran. So I checked it this morning and tried executing it manually. This is what I saw in the output, repeated over and over:
./dvr_cleanup.sh: line 54: let: 08: value too great for base (error token is "08")
Searching this general error online, a few sites mention the improper handling of numbers starting with 0 (zero) being handled as an octal or base 8.
Have you encountered errors of this sort? Any recommendations for how to modify Hiro's script to handle this error?
Thanks!
RE: Auto delete recorded files: solution - Added by Prof Yaffle about 9 years ago
You may wish to look at master...