Skip to content

Meaningful Filenames in MythTV

By default, MythTV creates odd filenames for the MPEGs it records. Garry Parker in his Ubuntu MythTV installation guide mentions a script called “mythlink” to create meaningful filenames (well, symbolic links) for your videos. Sadly, it’s b0rked in the current version of MythTV. I’ve hacked it about a bit, and come up with one that works, at least on my install. All praise to Dale Gass who wrote the original; I’ve just butchered his code a little.

This is set up to work with the raw MythTV video files in /var/lib/mythtv/recordings and to create links in /varlib/mythtv/links. If your install is different, you’ll need to change the lines:
my $mythpath= "/var/lib/mythtv/recordings";
my $altpath= "/var/lib/mythtv/links";

…to suit. Note also that MythTV files are stored in a weird format (”NUV”), you won’t necessarily be able to play them without converting them first.

#!/bin/sh

# mythlink.sh - Symlinks mythtv files to more readable versions
# by Dale Gass
# Butchered 13 Jul 2007 to work with MythTV 0.20 on Ubuntu 7.04 

# if [ ! -d /home/mythtv/tv ]; then mkdir /home/mythtv/tv; fi
# rm -f /home/mythtv/tv/*

echo "Done RM"
mysql -uroot  mythconverg -B --exec "select chanid,starttime,endtime,title,subtitle from recorded;" >/tmp/mythlink.$$
perl -w -e '
        my $mythpath= "/var/lib/mythtv/recordings";
        my $altpath= "/var/lib/mythtv/links";
        if (!-d $altpath) {
                mkdir $altpath or die "Failed to make directory: $altpath\n";
        }
        <>;
        while (<>) {
                chomp;
                my ($chanid,$start,$end,$title,$subtitle) = split /\t/;
                $start =~ s/[^0-9]//g;
                $end =~ s/[^0-9]//g;
                $subtitle = “” if(!defined $subtitle);
                my $ofn = “${chanid}_${start}.mpg”;
                do { print “Skipping $mythpath/$ofn\n”; next } unless -e “$mythpath/$ofn”;
                $start =~ /^….(……..)/;
                #my $nfn = “$1_${title}_${subtitle}”;
                my $nfn = “$1_${title}”;
                if ($subtitle) {$nfn=”${nfn}_${subtitle}”}
                $nfn =~ s/ /_/g;
                $nfn =~ s/&/+/g;
                $nfn =~ s/[^+0-9a-zA-Z_-]+/_/g;
                $nfn = “${nfn}.mpg”;
                print “Creating $nfn\n”;
                unlink “$altpath/$nfn” if(-e “$altpath/$nfn”);
                symlink “$mythpath/$ofn”, “$altpath/$nfn” or die “Failed to create symlink $altpath/$nfn: $!”;
        }
‘ /tmp/mythlink.$$
rm /tmp/mythlink.$$

Post a Comment

You must be logged in to post a comment.