[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mythtv-users
Subject:    [mythtv-users] ignyte replacement script that fetches from Google
From:       Jason Keirstead <jason () keirstead ! org>
Date:       2008-06-02 2:28:56
Message-ID: 48435AE8.4060804 () keirstead ! org
[Download RAW message or body]

The "ignyte" mythmovies grabber that ships with the mythmovies plugin 
does not support non-US addresses, so I decided rather than not using 
the plugin altogether, to write my own grabber that instead fetches the 
data from Google Movies.

It is tested and working fine for me using my Canadian postal code. 
hopefully others may find it useful. Some people in the US even may 
prefer to use it instead of the ignyte script, because one thing I did 
differently is I put the 'star rating' from Google's movie reviews into 
the 'Rating' box instead of the MPAA rating, which I did not find useful.

Only takes one argument, zip / postal code. It is *VERY* hacky, and will 
probably break at the slightest page format change, but it does the trick.

---------

#!/usr/bin/perl -w
#

my $zip = $ARGV[0];

@theatres = ();
@movies = ();
@showtimes = ();
@ratings = ();
@runningTimes = ();

my $page = "";

open( F, "wget --quiet -O - 
'http://www.google.ca/movies?hl=en&near=$zip&sort=1'|" );

while(<F>)
{
        $page .= $_;
}
close(F);

while( $page =~ /tid=\w+"><b>([^<]+)<\/b><\/a><br>([^\s<]+)/g )
{
        push @theatres, "$1:$2";
}


while( $page =~ /mid=\w+"><b>([^<]+)<\/b>/g )
{
        push @movies, $1;
}

while( $page =~ /alt="(Rated [^"]+)"/g )
{
        push @ratings, $1;
}

while( $page =~ /\<br\>\<font size=-1\>([^\s<]+)/g )
{
        push @runningTimes, $1;
}

while( $page =~ /<br>([^<]+)<\/font>/g )
{
        push @showtimes, $1;
}

my %theatreMap = ();
for( my $i = 0; $i < scalar(@theatres); ++$i )
{
        my $theatre = $theatres[$i];
        my $movie = $movies[$i];
        my $showtime = $showtimes[$i];
        my $runningTime = $runningTimes[$i];
        my $rating = $ratings[$i];
        my $movieRef = undef;

        if( $theatreMap{ $theatre } )
        {
                $movieRef = $theatreMap{ $theatre };
        }
        else
        {
                %empty = ();
                $movieRef = \%empty;
                $theatreMap{ $theatre } = $movieRef;
        }

        my @movieInfo = ( $showtime, $runningTime, $rating );
        $movieRef->{ $movie } = \@movieInfo;
}

print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<MovieTimes>\n";

for my $theatre ( keys %theatreMap )
{
        my ( $name, $address ) = split /:/, $theatre;
        $address =~ s/&nbsp;/ /g;

        print 
"<Theatre>\n\t<Name>$name</Name>\n\t<Address>$address</Address>\n\t<Movies>\n";

        my $movieRef = $theatreMap{ $theatre };

        for my $movie( keys %{ $movieRef } )
        {
                print "\t\t<Movie>\n\t\t\t<Name>$movie</Name>\n";

                my @movieInfo = @{ $movieRef->{ $movie } };
                my ( $showtime, $runningTime, $rating )  = @movieInfo;
                $showtime =~ s/&nbsp;/ |/g;
                $showtime =~ s/(\d+:\d+)/$1pm/g;

                print "\t\t\t<ShowTimes>$showtime</ShowTimes>\n";

                if( $runningTime )
                {
                        $runningTime =~ s/&nbsp;/ /g;
                        print 
"\t\t\t<RunningTime>$runningTime</RunningTime>\n";
                }


                if( $rating )
                {
                        print "\t\t\t<Rating>$rating</Rating>\n";
                }

                print "\t\t</Movie>\n";
        }

        print "\t</Movies>\n</Theatre>\n";
}

print "</MovieTimes>"
_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic