Fix scan chan.pl

From MythTV Official Wiki
Jump to: navigation, search

Author Bob
Description Perl script to reformat channel numbers from linux-dvb scan program
Supports


fix_scan_chan.pl

This script will take the output from the linux-dvb scan program and reformat for easier reading by the user.

Command line usage

perl fix_scan_chan.pl < scan.log > scan.conf

The Code

Script.png fix_scan_chan.pl

#!/usr/bin/perl

# Version 1.0 - Aug 7, 2009

use strict;

my(@cols, $freqid);

# ChannelName:Frequency:Modulation:VID:AID:PID
while(<STDIN>) {
  chomp $_;
  @cols = split /:/, $_;
  $freqid = sprintf "%03d", freq2freqid($cols[1]);
  $cols[0] = 'C' . $freqid . '-' . $cols[5];
  print join(':', @cols) . "\n";
}
exit;

sub freqid2freq($) {
  my $id = shift;
  my @freqs = ( undef,
                undef,
                57000000,
                63000000,
                69000000,
                79000000,
                85000000,
                177000000,
                183000000,
                189000000,
                195000000,
                201000000,
                207000000,
                213000000,
                123012500,
                129012500,
                135012500,
                141000000,
                147000000,
                153000000,
                159000000,
                165000000,
                171000000,
                219000000,
                225000000,
                231012500,
                237012500,
                243012500,
                249012500,
                255012500,
                261012500,
                267012500,
                273012500,
                279012500,
                285012500,
                291012500,
                297012500,
                303012500,
                309012500,
                315012500,
                321012500,
                327012500,
                333025000,
                339012500,
                345012500,
                351012500,
                357012500,
                363012500,
                369012500,
                375012500,
                381012500,
                387012500,
                393012500,
                399012500,
                405000000,
                411000000,
                417000000,
                423000000,
                429000000,
                435000000,
                441000000,
                447000000,
                453000000,
                459000000,
                465000000,
                471000000,
                477000000,
                483000000,
                489000000,
                495000000,
                501000000,
                507000000,
                513000000,
                519000000,
                525000000,
                531000000,
                537000000,
                543000000,
                549000000,
                555000000,
                561000000,
                567000000,
                573000000,
                579000000,
                585000000,
                591000000,
                597000000,
                603000000,
                609000000,
                615000000,
                621000000,
                627000000,
                633000000,
                639000000,
                645000000,
                93000000,
                99000000,
                105000000,
                111025000,
                117025000,
                651000000,
                657000000,
                663000000,
                669000000,
                675000000,
                681000000,
                687000000,
                693000000,
                699000000,
                705000000,
                711000000,
                717000000,
                723000000,
                729000000,
                735000000,
                741000000,
                747000000,
                753000000,
                759000000,
                765000000,
                771000000,
                777000000,
                783000000,
                789000000,
                795000000,
                801000000 );
  return(undef) if($id > scalar(@freqs) - 1);
  return($freqs[$id]);
}

sub freq2freqid($) {
  my($freq, $i, $h, $f);
  $freq = shift;
  for($f = 0, $i = 2; $i < 127; $i++) {
    $h = freqid2freq($i);
    if($h == $freq) {
      $f = 1;
      last;
    }
  }
  if(!$f) {
    return(undef);
  }
  return($i);
}