1#!/usr/bin/perl 2 3use strict; 4 5if(scalar(@ARGV) != 3) { 6 print("Usage: convert.pl <vdradmin-am config> <timers in> <timers out>\n"); 7 print("\t<vdradmin-am config> VDRAdmin-AM's vdradmind.conf\n"); 8 print("\t<timers in> Source timers.conf\n"); 9 print("\t<timers out> Destination timers.conf\n"); 10 exit 1; 11} 12 13my %CONFIG; 14my $CONFFILE = @ARGV[0]; 15my $timers_in = @ARGV[1]; 16my $timers_out = @ARGV[2]; 17 18ReadConfig(); 19 20print("Converting $timers_in to $timers_out\n"); 21my $in = open(FH_IN, "<$timers_in") if(-e "$timers_in"); 22my $out = open(FH_OUT, ">$timers_out"); 23if($in and $out) { 24 while(<FH_IN>) { 25 chomp; 26 s/#.*//; 27 s/^\s+//; 28 s/\s+$//; 29 next unless length; 30 my ($status, $channel, $day, $start, $stop, $priority, $lifetime, $file, $aux) = split(":", $_); 31 my $autotimer = 1 if($status & 0x8000); 32 my $active = $status & 0x7FFF; 33 my $event_id = $status >> 16; 34 if($autotimer) { 35 $autotimer = 2 if($event_id); 36 $aux .= "|" if($aux); 37 $aux .= "<vdradmin-am><epgid>$event_id</epg_id><autotimer>$autotimer</autotimer><bstart>$CONFIG{TM_MARGIN_BEGIN}</bstart><bstop>$CONFIG{TM_MARGIN_END}</bstop></vdradmin-am>"; 38 } 39 print(FH_OUT "$active:$channel:$day:$start:$stop:$priority:$lifetime:$file:$aux\n"); 40 } 41 close(FH_IN); 42 close(FH_OUT); 43 print("\nNOTE:\n"); 44 print("Please check the new timers.conf for errors before replacing the old timers.conf!\n"); 45} else { 46 print("Failed to open files!\n"); 47 exit 1; 48} 49 50sub ReadConfig { 51 if(-e $CONFFILE) { 52 open(CONF, $CONFFILE); 53 while(<CONF>) { 54 chomp; 55 my($key, $value) = split(/ \= /, $_, 2); 56 $CONFIG{$key} = $value; 57 } 58 close(CONF); 59 } else { 60 print "$CONFFILE doesn't exist. Exiting\n"; 61 exit(1); 62 } 63 return(0); 64} 65