Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: Resort channels.conf




Christian Pesch made a tiny script to "resort" VDR-channels.conf.

Daniel Schneider asked for a version which takes 
the original channel.comf as "sort reference"
so i assume that there is still no other script?


I modified the script to accept a file in channel.conf-format.
That has the big advantage that channel rename conflicts
can be solved "automagically". (currently by using SID).
If it detects "renames" it generates a "sed" command script
to automagically convert the names in the "sort reference".


There are 2 problems still to solve:

 -Informations about channels which are not in the "new" 
  channels.conf will be lost (without a warning!)

 -Grouping infos will be lost (without a warning!).

 -Better rename solution.
 

Rainer



(Please: Don't take it as a "reference implementation" ;-)
It's only a -very- quick hack with a lot of work to done.
If here is a perl hacker: pls. don't hesitate to sent a better 
version!)

------------------------------------------------------------------
channelssort.pl


#!/usr/bin/perl
# Version 0.02
# Aranges a new VDR channel.conf file to the channel order
# given by a reference  channel.conf file
#
# channels with signal IDs not existing in new channel.conf
# are silently omitted!
#
# changed channel names generated a "sed" command file
# to easily patch the reference channel.conf
#
# History:
# 030808 rz accept norma channels.conf as input
#           try to detect renames
# 020605 cp initial version
#
####################################################################
if ($#ARGV < 2) {
  Usage();
  exit;
}

$src   = $ARGV[0];
$order = $ARGV[1];
$dest  = $ARGV[2];

##########################################################################

$quiet=1;

# read in ordering file
open(ORDER, $order) || die "Cannot open $order: $!\n";
while ($line = <ORDER>) {

  # may be too simple to remove the new line character
  chop($line);
  push(@sorted, $line);
}
close(ORDER);

#readin original file
open(SRC, $src) || die "Cannot open $src: $!\n";
while($line = <SRC>) {
  $channel = ChannelName($line);
  $channels{$channel} = $line;
  ($Name,$Frequency,$Parameters,$Source, $Srate,$VPIFD,$APID,$TPID,$CA,$SID,$NID,$TID,$RID,@rem)= split(/:/,$line);
  $sids{$SID}=$Name;
  push(@unsorted, $line);
}
close(SRC);




# write ordered channels in given order

open(DEST, ">$dest") || die "Cannot open $dest: $!\n";

print DEST ":My channels\n";

for ($i=0; $i <= $#sorted; $i++) {
  $line = $sorted[$i];
  ($Name,$Frequency,$Parameters,$Source, $Srate,$VPIFD,$APID,$TPID,$CA,$SID,$NID,$TID,$RID,@rem)= split(/:/,$line);
  # if very old (1.0.4) channels.conf  $Source="S19.2E";
  if(!$channels{$Name}) 
  {
    # Dump all channels not found
    if (!$quiet) {
        print "$Name=$sids{$SID}:$Frequency:$Parameters:$Source:$Srate:$VPIFD:$APID:$TPID:$CA:$SID:$NID:$TID:$RID\n";
    }
    if($sids{$SID}){
      push(@subst,"/^$Name:/$sids{$SID}:/");
    }
  }
  else
  {
    print DEST $channels{$Name};
    delete $channels{$Name};
  }
}

printf STDERR"Wrote %s sorted channels.\n", $#sorted;

# write all other channels in original order

print DEST ":All channels\n";

$count = 0;
for ($i=0; $i <= $#unsorted; $i++) {
  $line = $unsorted[$i];
  $channel = ChannelName($line);

  # ignore channels already written
  if($channels{$channel}) {
    print DEST $line;

    if(length($channel) != 0) {
      $count++;
    }
  }
}
close(DEST);

printf STDERR "Wrote %s other channels.\n", $count;



# process channel names changed:
if ($#subst >0)
{
  print STDERR "\nFound $#subst name changes to be done:\n";

  # write sed-file if any names have changed
  for ($i=0; $i+1 <= $#subst; $i++) {
    print "1,\$s$subst[$i]\n";
  }

  print STDERR "\nTo convert those names do redirect output to a command file: \n";
  print STDERR "\n    $0 $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] > $ARGV[1].sed\n";
  print STDERR "\nEdit channels.conf.sed if required and do:\n";

  print STDERR "\n    sed -f $ARGV[1].sed < $ARGV[1] > $ARGV[1].new\n";
  print STDERR   "    $0 $ARGV[0] $ARGV[1].new $ARGV[2] $ARGV[3]\n";

}


##########################################################################

sub ChannelName {
  local($name) = @_;

  @split = split(":", $name);
  $name = $split[0];
  return $name;
}

sub Usage {
  print "Usage: $0 <source file> <sort order file> <destination file>\n";
  print "Sorts the VDR channels from the <source file> according to the\n";
  print "sort order given in the <sort order file> and writes them to\n";
  print "the <destination file>. All channels not mentioned in the sort\n";
  print "order file are appended.\n";
  print "The oder file is usually an older channel.conf\n";
  print "A warning is issued ";
  print "if the order file refers a name which is not in source file\n";
  print "Sample:\n";
  print "$0 channels.conf channels.conf.my channels.conf.resorted\n";
}




-- 
Info:
To unsubscribe send a mail to ecartis@linuxtv.org with "unsubscribe vdr" as subject.



Home | Main Index | Thread Index