my $channel_name;
my $in;
while (<>) {
# Completely remove unsupported extensions.
s|\s+.*\n||;
s|\s+.*\n||;
s|\s+.*\n||;
s|\s+.*\n||;
s|\s+.*\n||;
# Remove empty tags and empty lines.
s|\n||;
s|\n||;
s|^\n$||;
# Ensure a single line before the tv tag.
s|^(.*)|) {
$channel_name = $1;
}
s|\s+.*\n||;
if (m|(.*)|) {
s|(.*)|$1 $channel_name|;
undef $channel_name;
}
if (m|^(\s+)| and defined $channel_name) {
my $space = $1;
s|^|$space$space$channel_name\n|;
}
# Modify the program times to include the current timezone.
if (m|(\s+)|) {
$in = $1;
my $start = $2; my $stop = $3; my $channel=$4;
s|||;
}
# Canonicalise the ratings.
s|\s+\n||;
s|\s+\n||;
s|\s+\n||;
s|(\s+)(.*)|$in$in\n$in$in$in$2\n$in$in|;
print;
}