#!/usr/bin/perl -w use strict; use HTML::Entities; use File::Basename; my $outfile; my $transcript; my $url; sub line { my $enc = encode_entities($_); # un-fix things that were valid entities to begin with $enc =~ s/&([a-zA-Z]*);/&$1;/g; return '
' . $enc . "
\n"; } print "Content-type: text/plain\n\n"; open READ, '<', 'ohnorobot.txt' or die "Could not open input file: $@"; my $newpanel = 0; while () { # couldn't get chomp to work with DOS line endings s/\r\n//; if (/URL: \[\[\[([^\]]*)\]\]\]/) { $url = $1; my ($name,$path,$suffix) = fileparse($url, ".php"); $outfile = $name . '.ts'; $transcript = '
' . "\n"; $newpanel = 1; } elsif (/\]\]\]$/) { # found end-of-transcript s/TRANSCRIPTION: \[\[\[//; s/\]\]\]//; $transcript .= line($_) . '
'; print "Writing $url => $outfile\n"; open TS, '>', $outfile or die "Could not open $outfile: $@"; print TS $transcript; close TS; } else { s/TRANSCRIPTION: \[\[\[//; if (/./) { $transcript .= line($_); $newpanel = 0; } else { $transcript .= '
' . "\n" unless $newpanel; $newpanel = 1; } } }