#!/usr/bin/perl -w # odeon.cgi # Open Source Odeon courtesy of Bwch'r Bant Productions. # A front-end to Odeon Cinemas' film information (www.odeon.co.uk) without # the nasty browser-specific stuff of the original site. # This is a slightly modified v0.1.1 (film names now sentence-case). # No rights reserved. Install it where you like. Change anything. Copy freely. # You'll need the LWP module, which should be installed on most competent hosts. # (Yes, this is a Perl script, for those who haven't twigged yet.) # You can currently download this script from www.geocities.com/opensourceodeon/ # Kudos to Matthew Somerville for the original idea. Matthew has no responsibility # for this script. # You can call it with: # ?cmd=N - now showing # ?cmd=C - coming soon # ?cmd=F&film=filmname - film details # ?cmd=R - list regions # ?cmd=R®ion=regionname - list cinemas in that region # ?cmd=A&cinema=cinemaname - what's on at that cinema # # and you can even supply a stylesheet URL in the css parameter. # =================================== # Main code starts here # =================================== # ----- Initialisation use LWP::Simple; Parse_Form(); $cmd=lc($formdata{'cmd'}); $"=', '; # ----- HTTP header and top of page print "Content-type: text/html\n\n"; if (exists $formdata{'css'}) { print '\n"; $suffix="&css=".$formdata{'css'}; } else { $suffix = ''; } print <Open Source Odeon

Open Source Odeon: Now showing | Coming soon | Find a cinema


EOF # ----- Now let's do the work! if ($cmd eq 'n' or $cmd eq '') { # ----- Now showing @ojs=Get_Odeon_JS('page=films.js&Parameters=TYPE~N'); ProcessVars(@ojs); print "

Now showing

\n"; print "

Current top five

\n"; print ""; print "

New releases

\n"; print ""; print "

All films

\n"; print ""; } elsif ($cmd eq 'c') { # ----- Coming soon @ojs=Get_Odeon_JS('page=films.js&Parameters=TYPE~C'); ProcessVars(@ojs); print "

Coming soon

"; print "

Forthcoming films

\n"; print ""; print "

Future highlights

\n"; print ""; } elsif ($cmd eq 'f') { # ----- Film details $film=$formdata{'film'}; $filmreadable=$film; $filmreadable=~s/_/ /g; $filmreadable=~s/([\w']+)/\u\L$1/g; @ojs=Get_Odeon_JS("page=film_x.js&Parameters=FILM~$film"); ProcessVars(@ojs); print "

$filmreadable ($var{'certificate'})

"; print "

$var{'synopsis'}

"; print "

Running time $var{'runtime'} minutes

"; print "

Director $var{'director'}

"; @stars=ParseCSV($var{'keyCast'}); if (@stars) { print "

Starring: @stars

"; } if ($var{'showing'}==1) { print "

Now showing "; } else { print "

Coming soon "; } print "(released $var{'releaseDate'}) "; @cinemas=ParseCSV($var{'cinema_id'}); if (@cinemas) { print "at:"; ListCinemas(@cinemas); } print "

"; } elsif ($cmd eq 'r') { # ----- Region or cinema listing if (exists $formdata{'region'}) { # List cinemas in a region $region=$formdata{'region'}; $regionreadable=$region; $regionreadable=~s/_/ /g; print "

$regionreadable

\n"; @ojs=Get_Odeon_JS("Page=regionx.js&Parameters=REGION~$region"); ProcessVars(@ojs); ListCinemas(ParseCSV($var{'cinemas'})); } else { # List all regions print "

Select a region

"; } } elsif ($cmd eq 'a') { # ----- What's on at a particular cinema $cinema=$formdata{'cinema'}; $cinemareadable=$cinema; $cinemareadable=~s/_/ /g; $cinemareadable=~s/(\w+)/\u\L$1/g; # What's on print "

$cinemareadable

\n"; print "

What's on

\n"; @ojs=Get_Odeon_JS("page=cinema_xy.js&Parameters=CINEMA~$cinema"); ProcessVars(@ojs); @dates=ParseCSVSingleQuotes($var{'d'}); @films=ParseCSVSingleQuotes($var{'f'}); @perfs=ParseCSVSingleQuotes($var{'p'}); @schedule=unpack('(A6)*',$var{'data'}); $lastdate=999; foreach $perf (@schedule) { ($dateno,$filmno,$perfno)=unpack('(A2)*',$perf); $dateno=hex $dateno; $filmno=hex $filmno; $perfno=hex $perfno; if ($dateno ne $lastdate) { if ($lastdate!=999) { print "\n"; } print "

$dates[$dateno]

\n"; } print "

For information, call $var{'filmlineNumber'}

"; print "

Disability information call $var{'disabilityNumber'}

"; $loveseat=$var{'love_seat'}; $audio=$var{'dda'}; # Cinema information print "

About this cinema

\n"; @ojs2=Get_Odeon_JS("page=cinema_info.js&Parameters=CINEMA~$cinema"); ProcessVars(@ojs2); print "

Address: $var{'address'}

"; for ($i=17; $i<=$#ojs2; $i++) { if ($ojs2[$i]=~/new header\("([^"]*)","([^"]*)"\)/) { print "

$1: $2

\n"; } } if ($loveseat eq 'Y') { print "

Lurve seats available

\n"; } if ($audio eq 'Y') { print "

Audio description technology installed

\n"; } } # ================================= # Subroutines follow # ================================= # ------ Get_Odeon_JS subroutine # takes query string for Display.page, returns document as string sub Get_Odeon_JS { my $qs=$_[0]; return split(/\n/,get ("http://www.odeon.co.uk/pls/Odeon/Display.page?$qs")) or die ("Couldn't get $qs: $!\n"); } # ------ Parse_Form subroutine # this version handles both POST and GET sub Parse_Form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs=split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); if ($ENV{'QUERY_STRING'}) { @getpairs=split(/&/, $ENV{'QUERY_STRING'}); push (@pairs,@getpairs); } } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-f0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-f0-9])/pack("C", hex($1))/eg; if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; } } } # ------------------- # ParseCSV subroutine sub ParseCSV { my $str = @_ ? shift : $_; my @ret; while ($str =~ /\G\s*(?!$)("[^"]*(?:""[^"]*)*"|[^,"]*),?/g) { push @ret, $1; $ret[-1] =~ s/\s+$//; if ($ret[-1] =~ s/^"//) { chop $ret[-1]; $ret[-1] =~ s/""/"/g } } return @ret; } sub ParseCSVSingleQuotes { my $str=substr($_[0],1).",'"; return split(/','/,$str); } # ------------------- # Paramify subroutine sub Paramify { my $str=$_[0]; $str=~s/['.]//g; $str=~s/ /_/g; return $str; } # ---------------------- # WriteRegion subroutine sub WriteRegion { my $region=$_[0]; my $regurl=Paramify($region); print "
  • $region\n"; } # ---------------------- # ListCinemas subroutine sub ListCinemas { print ""; } # -------------------- # ListFilms subroutine sub ListFilms { foreach my $film (@_) { my $filmurl=Paramify($film); $film=~s/([\w']+)/\u\L$1/g; print "
  • $film\n"; } } # ---------------------- # ProcessVars subroutine sub ProcessVars { %var=(); foreach my $line (@_) { foreach my $subline (split(/; var /,$line)) { if ($subline=~/^var /) { $subline=substr($subline,4);} $subline=~s/;$//; if ($subline=~/^([^=\s]*)\s?=\s?(.*)$/) { my $varname=$1; my $value=$2; if ($value=~/^".*"$/) { $value=substr($value,1,-1); } elsif ($value=~/^\[.*\]$/) { $value=substr($value,1,-1); } $value=~s/\\//g; $var{$varname}=$value; } } } }