Skip to content

Instantly share code, notes, and snippets.

@alext
Last active August 29, 2015 14:11
Show Gist options
  • Save alext/73a1e279fc133956d08f to your computer and use it in GitHub Desktop.
Save alext/73a1e279fc133956d08f to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
if( scalar @ARGV < 1) {
die "Usage $0 config_file\n";
}
my $channels_map_file = "$ENV{'HOME'}/.xmltv/supplement/tv_grab_uk_atlas/tv_grab_uk_atlas.map.channels.conf";
my %channels = ();
unless(open CHANNELS, "< $channels_map_file") {
print STDERR "Failed to open channels map - $channels_map_file : $!\n";
print STDERR "\nRun the grabber at least once before running this script to download the map files.\n";
exit 1;
}
foreach my $line (<CHANNELS>) {
chomp $line;
next if $line =~ /^\s*$/;
next if $line =~ /^\s*#/;
my ($id, $xmlid, $comment) = ($line =~ /^map==([^=]+)==(\S+)\s*(?:#\s*(.*)\s*)?$/ );
unless($id) {
print STDERR "Warn: Failed to match channels line '$line'\n";
next;
}
$channels{$id} = [$xmlid, $comment];
}
close CHANNELS;
open CONFIG, "< $ARGV[0]" or die "Failed to open config $ARGV[0]: $!";
foreach my $line (<CONFIG>) {
unless($line =~ /^channel[=!](\S+)/) {
print $line;
next;
}
my ($lead, $id) = ($line =~ /^(channel[=!])(\S+)/);
print "$lead$id # $channels{$id}[0] # $channels{$id}[1]\n"
}
close CONFIG;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment