My Humax Forum » Freeview SD » PVR 9150T, 9200T, 9300T

Renaming TS files on PC

(16 posts)
  1. User has not uploaded an avatar

    simple

    junior member
    Joined: Jul '11
    Posts: 7

    offline

    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";
    }
    }

    | Mon 25 Jul 2011 1:47:00 #11 |
  2. User has not uploaded an avatar

    simple

    junior member
    Joined: Jul '11
    Posts: 7

    offline

    And this code to get the date off films only and add them to tile in brackets.


    #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 ':'
    $desc =~ /(\d{4})/;
    print "Episode name: $1\n";

    #if episode name exists, rename all files with episode name appended
    if($1)
    {
    @fname=split(/\./,$file);
    print "renaming $file $title $1\n";
    rename ("$fname[0].epg","$title ($1).epg");
    rename ("$fname[0].elu","$title ($1).elu");
    rename ("$fname[0].hre","$title ($1).hre");
    rename ("$fname[0].ts","$title ($1).ts");
    }
    else
    {
    print "no episode name\n";
    }
    }

    | Mon 25 Jul 2011 5:43:27 #12 |
  3. myhumax

    myhumax

    senior admin
    Joined: Feb '11
    Posts: 453

    offline

    Nice to see you getting to grips with Perl and making improvements... Yes, there's no accounting for dodgy characters and not much error checking in the quick and dirty script.

    simple - 7 hours ago  » 


    $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;

    You can replace all the code above by placing the characters in square brackets, like so:

    $title =~ s/[\.:+,\[\]?]/-/g;
    $desc =~ s/[\.:+,\[\]?]/-/g;

    Or safer to only allow normal characters (the ^ at the start means not matching):

    $title =~ s/[^A-Za-z0-9]/_/g;
    $desc =~ s/[^A-Za-z0-9]/_/g;

    I prefer replacing these with an underscore '_'. You can also read in an argument to switch between movie and series renaming like so:

    $type = $ARGV[0];
    if($type eq 'movie') { #do movie name processing here };
    if($type eq 'series') { #do series name processing here };

    Then you can call up the program in the cmd using:

    humax.pl movie

    Or

    humax.pl series

    | Mon 25 Jul 2011 9:27:27 #13 |
  4. User has not uploaded an avatar

    johnkent

    new member
    Joined: Jun '17
    Posts: 3

    offline

    is this posting still open for adding onto?

    | Sat 29 Sep 2018 10:49:21 #14 |
  5. Trev

    Trev

    special member
    Joined: Apr '18
    Posts: 530

    offline

    As you just did, I guess the answer would be "Yes".

    | Sat 29 Sep 2018 13:40:58 #15 |
  6. User has not uploaded an avatar

    johnkent

    new member
    Joined: Jun '17
    Posts: 3

    offline

    well i'm recoding this atm, to allowing renaming and creating of a basic nfo file. in perl script be 1st time i used perl. found issues within this script and issues with titles going into the desc so should be fun trying to work out the kinks.

    | Sat 29 Sep 2018 21:50:41 #16 |

RSS feed for this topic

Reply

You must log in to post.