#! /usr/bin/perl -w # mymovies # # Automatically download your vote history from IMDB. # # Copyright (C) 2001 Alan De Smet chaos at highprogrammer.com # http://www.highprogrammer.com/alan/perl/#mymovies # # This software is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program in file entitled "COPYING"; if # not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA. A copy of the # GNU General Public License is available at # http://www.fsf.org/copyleft/gpl.html . # my $URL = 'http://us.imdb.com/mymovies/list?votehistory'; # Only need to set one of COOKIE_FILE or IMDBDATA. COOKIE_FILE is preferred # over IMDBDATA my $COOKIE_FILE = "$ENV{HOME}/.netscape/cookies"; my $IMDBDATA = undef; # Allows you to rename movies, useful if you know a movie by a a # different name than it's "proper name", common for translated # movies. (The default collection translates a random collection of # anime, Jackie Chan, and John Woo movies to their common english # names.) my(%TRANSLATIONS) = ( '\'A\' gai waak' => 'Project A', 'Cite des enfants perdus, La' => 'City of Lost Children, The', 'Dian zhi gong fu gan chian chan' => 'Half a Loaf of Kung Fu', 'Die xue jie tou' => 'Bullet in the Head', 'Do ma daan' => 'Peking Opera Blues', 'Feiying gaiwak' => 'Armor of God II: Operation Condor', 'Feng yu shuang liu xing' => 'Killer Meteors, The', 'Ging chaat goo si juk jaap' => 'Police Story 2', 'Hokuto no Ken' => 'Fist of the North Star', 'Hong faan kui' => 'Rumble in the Bronx', 'Huo shao dao' => 'The Prisoner', 'Jing cha gu shi III: Chao ji jing cha' => 'Supercop (Police Story 3)', 'Jing cha gu shi IV: Jian dan ren wu' => 'Jackie Chan\'s First Strike (Police Story 4)', 'Jui kuen II' => 'Legend of Drunken Master, The', 'Kwai tsan tse' => 'Wheels on Meals', 'Lashou shentan' => 'Hard Boiled', 'Lodoss to senki' => 'Record of Lodoss War', 'Lola rennt' => 'Run, Lola, Run', 'Longxiong hudi' => 'Armor of God', 'Majo no takkyubin' => 'Kiki\'s Delivery Service', 'Qiji' => 'Miracle', 'She hao ba bu' => 'Snake & Crane Arts of Shaolin', 'Shuang long hui' => 'Twin Dragons', 'Tonari no Totoro' => 'My Neighbor Totoro', 'Unendliche Geschichte, Die' => 'NeverEnding Story, The', 'Wo hu zang long' => 'Crouching Tiger, Hidden Dragon', 'Yatgo ho yan' => 'Mr. Nice Guy', 'Yong Chun' => 'Wing Chun', ); ################################################################################ # # NO USER SERVICABLE PARTS BELOW # use strict; use LWP::UserAgent; use HTTP::Cookies; my $VERSION = '1.0.0.0'; my $AGENT_NAME = "mymovies/$VERSION (http://www.highprogrammer.com/alan/perl/#mymovies)"; main(); exit; sub main { my $USER_AGENT = new LWP::UserAgent; $USER_AGENT->agent($AGENT_NAME); my $request = new HTTP::Request GET=>$URL; my $cookie_jar = undef; if(defined $COOKIE_FILE and -e $COOKIE_FILE) { $cookie_jar = HTTP::Cookies::Netscape->new(File=>$COOKIE_FILE); } if(not defined $cookie_jar) { $cookie_jar = HTTP::Cookies->new; my(@rest) = ("/", ".imdb.com", undef, 0, 0, 60*60, 0); $cookie_jar->set_cookie(undef, "IMDBDATA", $IMDBDATA, @rest); $cookie_jar->set_cookie(undef, "IMDBPREFS", "3", @rest); } $cookie_jar->add_cookie_header($request); my $result = $USER_AGENT->request($request); if($result->is_success) { } else { die "$0: Unable to load movie list from IMDB\n"; } my $body = $result->content; $body = strip_entity($body); my $owner = get_owner($body); my($total) = get_total($body); my(%movies) = get_movies($body); my $count = scalar keys %movies; if($count != $total) { die "$0: An error occurred. Expected $total movies, found $count.\n"; } print "${owner}'s Movies ($total total)\n"; print_movies(%movies); } sub get_owner { my($body) = @_; my($owner) = ($body =~ m|([^<>]+)'s Movies|i); # ' Fix syntax coloring return $owner; } sub get_total { my($body) = @_; my($total) = ($body =~ m|