Mailing List archive

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

[vdr] Resort channels.conf



Hi,

I've found it annoying to resort the channels.conf
after each update of vdr - and I didn't wanted to
miss updates from the channels.conf

So I wrote a small perl script to resort the channels.conf
according to an order given in a separate file.

Do

1> ./sort-channels.pl channels.conf channels.order channels.sorted
Wrote 4 sorted channels.
Wrote 175 other channels.

Maybe it's usefull for somebody.

-- 
Christian 


--- sort-channels.pl ---

#!/usr/bin/perl

if ($#ARGV != 2) {
  Usage();
  exit;
}

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

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

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

open(SRC, $src) || die "Cannot open $src: $!\n";
while($line = <SRC>) {
  $channel = ChannelName($line);
  $channels{$channel} = $line;
  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++) {
  $channel = $sorted[$i];
  print DEST $channels{$channel};
  delete $channels{$channel};
}

printf "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 "Wrote %s other channels.\n", $count;

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

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

--- channels.order ---

ARD
ZDF
RTL
Sat.1
Pro-7




-- No attachments (even text) are allowed --
-- Type: application/x-pkcs7-signature
-- File: smime.p7s
-- Desc: S/MIME Cryptographic Signature





Home | Main Index | Thread Index