[mythtv-users] Cleanup recordings not in database

Ian Clark mrrooster at gmail.com
Tue Jun 14 15:45:29 UTC 2011


On 14 June 2011 16:13, Ramon Hofer <ramonhofer at bluewin.ch> wrote:
> Hi all
>
> I've had some problems with my tuner and was playing around.
> Now I have restored a database where there are not all recordings - that
> are on the disk - are in the database.
>

I use this, ymmv, you'll need to either make it accept
username/password or hardcode them into the script like I have (I use
the defaults so I'm unfussed.)

FWIW I remove the echo from the rm line and just run this, however,
that's at your own risk. :)

Also, this isn't particularly efficient, but it works.

<-------------------------------------------------------------------------
mythtv at pvr:~$ cat bin/findorphans.sh
#!/bin/bash

sql="mysql -umythtv -pmythtv -B -N -e"
dir="/home/mythtv/tv/"
tmpfile=`mktemp`
$sql "select basename from mythconverg.recorded" > $tmpfile

find $dir -name "*.mpg" | while read line
do
        file=`echo $line | tr "/" "\n" | tail -1`
        if [ "`grep $file $tmpfile`" == "" ]; then
                echo "$line doesn't exist in the database."
                echo rm $line
        fi
done

rm $tmpfile
<-------------------------------------------------------------------------

Oh, and for completeness, here's the one to do the reverse:

<-------------------------------------------------------------------------
mythtv at pvr:~$ cat bin/findmissingrecordings.sh
#!/bin/bash

sql="mysql -umythtv -pmythtv -B -N -e"
dir="/home/mythtv/tv/0"
dir2="/home/mythtv/tv/1"


$sql "select basename from mythconverg.recorded" | while read line
do
        if [ ! -e "$dir/$line" ] && [ ! -e "$dir2/$line" ]; then
                echo file: `$sql "select title from
mythconverg.recorded where basename='$line'"`
                chanid=`$sql "select chanid from mythconverg.recorded
where basename='$line'"`
                starttime=`$sql "select starttime from
mythconverg.recorded where basename='$line'"`
                echo Chanid: $chanid Starttime: $starttime
                $sql "delete from mythconverg.recorded where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedcredits where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedfile where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedmarkup where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedprogram where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedrating where
chanid='$chanid' and starttime='$starttime'"
                $sql "delete from mythconverg.recordedseek where
chanid='$chanid' and starttime='$starttime'"

        fi

done
<-------------------------------------------------------------------------

NB, I have 2 storage dirs, if you have more you'll need to edit this
apropriatly, do not run this until you do, otherwise it'll delete all
the recordings in the storage dir you've missed.

Hope these are of some use. :)

Cheers,

Ian


More information about the mythtv-users mailing list