#!/usr/bin/perl # # Dit scriptje laat de NOS teletext zien # # (c) 2001, 2002, 2003 by Bas Zoetekouw # All rights reserved. # # Naar een idee van Wouter Bergmann-Tiest # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice and this list of conditions. # 2. Redistributions in binary form must reproduce the above copyright # notice and this list of conditions in the # documentation and/or other materials provided with the distribution. # # ## 2003-01-06: niew teletekst format ## 2003-01-06: kleurtjes ## 2003-01-06: meer html entities toegevoegd (dank Richard) ## 2003-01-22: VRT support ## 2003-02-07: kleur support aangepast ## 2009-05-11: herschreven, utf8 output en gebruik LWP::Simple; use LWP::Simple; use strict; my $color = 1; if ((scalar @ARGV > 0) && ($ARGV[0] eq "-m")) { $color = 0; shift @ARGV; } my %COLORS = ( "000000" => "\e[30m", #black "black" => "\e[30m", #black "ff0000" => "\e[31m", #red "red" => "\e[31m", #red "00ff00" => "\e[32m", #green "lime" => "\e[32m", #green "0000ff" => "\e[34m", #blue "blue" => "\e[34m", #blue "ffff00" => "\e[33m", #yellow "yellow" => "\e[33m", #yellow "ff00ff" => "\e[35m", #magenta "fuchsia"=> "\e[35m", #magenta "00ffff" => "\e[36m", #cyan "aqua" => "\e[36m", #cyan "ffffff" => "\e[37m", #white "white" => "\e[37m", #white "reset" => "\e[0m"); #reset color my %HTML = ( """ => '"', "­" => "", "<" => '<', "&" => '&', ">" => '>'); sub display(@) { my ($print, $last); foreach my $line (@_) { ($print = 1) if ($line =~ s/^.*
//i);
	($last  = 1) if ($line =~ s/<\/pre>.*$//i);
	next unless $print;

	if ($color) { 
	    foreach (keys %COLORS) {
		$line =~ s/COLOR=$_[^>]*>/>$COLORS{"$_"}/ig;
	    } 
	}
	foreach (keys %HTML) {
	    $line =~ s/$_/$HTML{"$_"}/ig;
	} 
	$line =~ s,<[^>]+>,,g;
	last if $last;

	utf8::encode($line);
	print $line, "\n";
    } 
    print $COLORS{"reset"};
}

my ($pag, @sub) = @ARGV;
$pag    = "100"  if (scalar @ARGV == 0);
push @sub, "1"   if (scalar @ARGV <= 1);  
foreach (@sub) {
    my $sub = sprintf("%02i", $_);
    display split /\n/, get "http://teletekst.nos.nl/tekst/${pag}-${sub}.html";
}