#!/usr/bin/perl

# converting technosat transponder ini files into a transponder-list for VDR
# Usage: Get transponder inis from http://joshyfun.webzdarma.cz/transponders/index.html
#        Combine the wanted .ini into one: cat *.ini > combined.ini
#        Convert the combined.ini into a transponder-file for VDR: TTini2VDR < combined.ini > channels.conf
#
# 15 Feb 2004: initial version from Stephan Martin <dvb@martin.de>
# 15 Feb 2004: small additions by Frank Scherthan <t.a.r.o.s@gmx.de>, now possible to use mor than one .ini
#              files and setting the start-channel-number

my $sat = '';
my $transponder = 0;
my $count = 0;
my $channelsstart = 4999;

while (<>) {
  if (!$sat) {
     if (/1=(\d+)/) {
         $sat = 'S'.  ($1 < 1800 ? $1/10 . 'E' : 180 - ($1 - 1800) / 10 .'W');
     }
  } elsif (!$transponder) {
   if (/\[DVB\]/) { $transponder = 1 } 
  } else {
    s/(\d+)=(\d+),([V|H]),(\d+),(\d+)\s*$/$channelsstart:$2:$3:$sat:$4:8191:8191:8191:0:8191:8191:$count:0/ && print 
"$_\n";
	$count++;
    $channelsstart++
  }
}

