Project

General

Profile

Cleanup recordings folder

Added by Fred Fred almost 4 years ago

Dear all, this is not entirely related to tvheadend rather comskip with tvheadend and folder management.
If this is inappropriate just delete the post and notify me and I'll look for support elsewhere.

I record a tv channel every day for two hours. ComSkip cleans out most commercials and that's that. The recording profile is set to retain recordings (Recorded file(s) retention period:) for three (3) days and then remove them, this works fine.
The recording file itself is removed but the folder created is still there and the logs from comskip and some other files are retained, so after a while I have a bunch of folders with files but the recordings itself are removed. Like I say, tvhedend does exactly what it should and everything works, just leaves lot of artifacts... anyone have a solution for this?

My own idea that I want to test here is this - would this work or is there a better way.
The recorded filename is always .ts, so some-genereated-name.ts
Create a script (cleanup-recorings-folder.sh) that looks in every folder under /media/recordings/ for folders where the is no file named *.ts in that folder and removes the folder.
Update the recordings post-processor command to do comskip first and then the clean script.
/usr/bin/comskip --ini=/config/comskip/comskip.ini "%f" & /cfgfiles/tvheadend/cleanup-recorings-folder.sh
Would this work?

I'm not much of a shell scripter so if anyone have something like this or can point me in the right direction I'd be grateful.

My environment is OpenMediaVault 5 and running this docker image: https://hub.docker.com/r/linuxserver/tvheadend


Replies (1)

RE: Cleanup recordings folder - Added by Hiro Protagonist almost 4 years ago

Here's a script I use to check for directories that no longer contain video files:

#!/bin/bash

usage()
{
 echo "Find directories that don't contain video files" 
 echo "$0 /path/to/search" 
}

if [ -d "$1" ]; then
  SAVEIFS=$IFS
  IFS=$(echo -en "\n\b")

  for DIR in $(find $1 -type d)
  do
    ls "$DIR" | grep -q -e '\.mp4$' -e '\.mkv$' -e '\.avi$' -e '\.ts$' -e '\.m4v$' -e '\.flv$'
    if [ $? -ne 0 ]; then
      SUBS=$(find $DIR -type d | tail -n +2 | head -n 1)
      if [ -z $SUBS ]; then
        echo "$DIR" 
      fi
    fi
  done
  IFS=$SAVEIFS
else
  usage
fi

You can modify the file types supported by adding or removing -e '\.xyz$' expression in the "grep" line, but as it contains an expression for .ts
it will work for you as-is.

If you want it to do anything other than just print the directories it finds, you can replace the echo "$DIR" with whatever action you want.

Save the file as findempty.sh [or whatever name you prefer], make it executable and run with the path of your recordings folder.

chmod +x findempty.sh
./findempty.sh /media/recordings/

    (1-1/1)