I am sometiems using this code on the odd file. I am no programmer but this is where I have got to so far, it just dumps all the information minus some dodgy charter.
This code could be a whole lot better and I will try and improve it. Just thought I'd share where I've got to with your help.
#look for all epg files in current directory
@epgfiles = glob("*.epg");
foreach $file(@epgfiles)
{
#open epg file and get programme title and description
open(IN,"<$file") or die "Error: cannot open file $file";
$epg=<IN>;
close(IN);
#get title at specific location (1st entry)
$title=substr($epg,22,49);
$title=~ s/(00+$)//g;
#get synopsis at specific location (1st entry)
$desc=substr($epg,74,254);
$desc=~ s/(00+$)//g;
# grab the first word of title in epg
$title =~ /(\w+)/;
print "EPG title: $1\n";
#if filename matches first word of title then we have the correct synopsis
if($file=~ /$1/)
{
# do nothing
print "matched first entry in epg\n";
}
#else look at the 2nd EPG entry
else
{
# check for next epg entry
print "getting second epg entry\n";
$title=substr($epg,354,49);
$title=~ s/(00+$)//g;
$desc=substr($epg,406,254);
$desc=~ s/(00+$)//g;
# print ">$title<\n>$desc<\n";
}
# search for episode name between '.' and ':'
print "desc is: $desc\n";
$title =~ s/\.\.\.//g;
$title =~ s/\:/-/g;
$title =~ s/\,/-/g;
$title =~ s/\;/\-/g;
$title =~ s/\?/\-/g;
$desc =~ s/\.\.\.//g;
$desc =~ s/\./,/g;
$desc =~ s/\?/\-/g;
$desc =~ s/\/+/of/g;
$desc =~ s/\[//g;
$desc =~ s/\]//g;
$desc =~ s/\:/-/g;
$desc =~ s/\,/-/g;
$desc =~ s/\;/\-/g;
print "desc2 is: $desc\n";
print "title is: $title\n";
$Ndesc=substr($desc,0,44);
#$desc =~ /\s+([\w+\s*]+):.*/;
print "short name is: $Ndesc";
#if episode name exists, rename all files with episode name appended
if($desc)
{
@fname=split(/\./,$file);
print " ok-- $fname[0]";
print " renaming $file $title - $Ndesc";
rename ("$fname[0].epg","$title - $Ndesc.epg");
rename ("$fname[0].elu","$title - $Ndesc.elu");
rename ("$fname[0].hre","$title - $Ndesc.hre");
rename ("$fname[0].ts","$title - $Ndesc.ts");
}
else
{
print "no episode name\n";
}
}