MythTV Roku Streaming Dir Remove Expired

This is just a quick and dirty script to delete MythTV recordings that had been previously transcoded and moved to the stream directory, but have since been autoexpired out of MythTV. This is an issue because trying to pull data outta the MythTV recording database about a recording that has been deleted causes an error because the entry isn’t there anymore. All it does is loop through each file in the stream directory and if it doesn’t exist in /var/lib/mythtv/recordings/ it gets deleted.

Contents of:
/usr/local/bin/mythexpire.pl

[perl]
#!/usr/bin/perl -w
use Fcntl; #The Module
#Checks the myth recording directory for .mp4 files that don’t have a corresponding .mpg. If found, it deletes them and generates a new feed

#Change below to your myth recordings directory
$directory = "/var/lib/mythtv/recordings";
$streamdirectory = "/var/www/stream";
$s = "";
$deletedfile = "";

foreach $f (<$streamdirectory/*>) {
$f =~ s/^/var/www/stream///;
if ( $f =~ /.mp4$/ ){
$s = $directory . "/". $f;
$s =~ s/.mp4$//;
if (!( -e $s )){
$deletedfile = $streamdirectory . "/" . $f;
$deletedfile =~ s/.mp4$//;
print $deletedfile . "n";
`rm -f $deletedfile.*`;
$deleted = "true";
}
}
}
[/perl]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: