While creating cue scripts is a lot easier with a word processor than it was writing it out by hand 400 years ago, I wrote this script to make generating cue scripts even easier. It's functionality is currently limited to processing files from the MIT Shakespeare, but it supports creating a cue script that includes multiple parts (as many as the end user specifies) because doubling is one of Shakespeare's original staging conditions, too:
#!/usr/bin/perl # # cueScriptGen # # Generate a cue script from an MIT Shakespeare File # # # Released under the GPL 2.0 and all that jazz. # # This is just a prototype. A more polished version will need further # testing and development. # # Last Revised 12 Dec. 2012 8 PM use strict; use warnings; # The user must give us at least one character name (but may give us # any number of them), followed by a script file. If they don't, # print a simple error and exit. if (@ARGV < 2) { die "usage is \"cueScriptGen character_1 [character_2 &c] file_name\ +"\n"; } # We should edit this to either accept a file name or a URL. # If we force a URL, we can explore transformations based on # alternative methods of formatting. # Whatever the file is, it will be the LAST thing in our # argument list, so pop it off so we have a list of nothing # but characters. my $mit_shakes = pop @ARGV; # Initialize variables. my $cue_line = ""; my $prev_cue_line = ""; my $act = ""; my $scene = ""; my $new_act = "false"; my $new_scene = "false"; my $line = ""; my $title_of_play = ""; # Open a file or quit with a basic warning if you can't. open PLAY, $mit_shakes || die "Could not open file: $!\n"; # Step 0.5: Print basic html header info from the file, and # them some heading info so the reader knows what they're # looking at. until ($line =~ m/<\/head>/) { if ($line =~ m/<title>(.*)<\/title>/) { $title_of_play = $1; } print "$line\n"; $line = <PLAY>; } print "</head>\n<body>\n"; print "<h1>$title_of_play</h1>\n"; print '<h2>Cue Script for '; # This boolean will tell us if we're on the # first item in the list, which should not # be preceeded by a comma and a space when # printing the list of characters. my $i = 0; foreach (@ARGV) { if ($i == 0) { print "$_"; $i = 1; } else { print ", $_"; } } print ". </h2>\n"; # Traverse the file until EOF while (<PLAY>) { $line = $_; # print "</head>\n"; # Step 1: Find a speech block that contains a character that we're l +ooking for. # We need to do this for every character left in our arguument list. + foreach (@ARGV) { my $character = $_; if ($line =~ m/^<a name="speech\d+"><b>$character<\/b>/i) { # Print the act heading if we haven't yet. if ($new_act eq "true") { print "$act\n"; $new_act = "false"; } # Print the scene headin if we haven't yet. if ($new_scene eq "true") { print "$scene\n"; $new_scene = "false"; } # Step 2: We've found a line of text that matches a block of tex +t for the # character we're looking for, so first we need to print their c +ue line. # See step 1.5 (below) for details. If the cue line is less than + three # words long, print the line that came before it, too. $cue_line =~ m/^<a name="\d+\.\d+\.\d+">(.*)</; my @cue_words = split /\s/, $1; my $cue_words = @cue_words; if ($cue_words < 2) { print "<b>Cue:</b> $prev_cue_line\n$cue_line\n\n"; } else { #print "<b>Cue:</b> $cue_line\n\n"; } # Step 3: Print the entire speech block for the character; you k +now you're # at the end of the block when you reach the closing blockquote while ($line !~ m/<\/blockquote>/) { print "$line\n"; # We still need to keep track of the cue line, just in case the cu +e script # is for an actor who plays two roles with back to back lines. $prev_cue_line = $cue_line; $cue_line = $line; # Read the next line of the file. $line = <PLAY>; } # Step 4: Print the closing blockquote. print "</blockquote>\n"; } # Step 1.5: We need to keep track of each line of text as we go, s +o if the # line was not a speech heading, see if it's a line of text. If it + is, keep it elsif ($line =~ m/^<a name="\d\.\d+\.\d+"/) { $prev_cue_line = $cue_line; $cue_line = $line; } # Step 1.6: We should also print act headings. elsif ($line =~ m/.*<h3>ACT \w+.*/) { $act = $line; $new_act = "true"; } # Step 1.7: We should also print scene headings. elsif ($line =~ m/.*<h3>SCENE \w+.*/) { $scene = $line; $new_scene = "true"; } } } # Last piece of cleanup, close off our HTML elements print "\n</body>\n</html>\n";
Please feel free to comment and make suggestions for improvements.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Making Cue Scripts with Perl
by jwkrahn (Abbot) on Dec 17, 2012 at 21:19 UTC | |
Re: Making Cue Scripts with Perl
by GrandFather (Saint) on Dec 17, 2012 at 22:14 UTC | |
Re: Making Cue Scripts with Perl
by girarde (Hermit) on Dec 20, 2012 at 23:07 UTC |