CONTINUED... (these are not required, just added for completeness to show what I did)
Here's some sample database entries from the start of my database. Obviously they won't actually play as you don't have the disk and the cover entries don't exist (regrab em with getimdb script if you like) but they act as an example. NOTE I also modified the imdb.pl script to use actors and other stuff in place of countries, so one of the fields is larger. so backup db first as mentioned
Code:
DROP TABLE IF EXISTS `videometadata`;
CREATE TABLE `videometadata` (
`intid` int(10) unsigned NOT NULL auto_increment,
`title` varchar(128) NOT NULL default '',
`director` varchar(128) NOT NULL default '',
`plot` text,
`rating` varchar(255) NOT NULL default '',
`inetref` varchar(32) NOT NULL default '',
`year` int(10) unsigned NOT NULL default '0',
`userrating` float NOT NULL default '0',
`length` int(10) unsigned NOT NULL default '0',
`showlevel` int(10) unsigned NOT NULL default '0',
`filename` text NOT NULL,
`coverfile` text NOT NULL,
`childid` int(11) NOT NULL default '-1',
`browse` tinyint(1) NOT NULL default '1',
`playcommand` varchar(255) default NULL,
`category` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`intid`),
KEY `director` (`director`),
KEY `title` (`title`),
KEY `title_2` (`title`)
) TYPE=MyISAM;
--
-- Dumping data for table `videometadata`
--
INSERT INTO `videometadata` VALUES (1,'Twelve Monkeys','Terry Gilliam','A convict, sent back in time to stop a devastating plague, is sent too far back and is hospitalized as insane. (USA)','Joseph Melito,Bruce Willis,Jon Seda,Michael Chance,Vernon Campbell,H. Michael Walls,Bob Adrian,Simon Jones,Carol Florence,Bill Raymond,Ernest Abuba,Irma St. Paule,Madeleine Stowe,Joey Perillo,Bruce Kirkpatrick','0114746',1995,8,129,1,'/myth/video/library/Movie/12 Monkeys (1995).avi','/myth/video/.covers/0114746.jpg',-1,1,'playvideo.sh \"/cdrom/12 Monkeys (1995).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (2,'Thir13en Ghosts','Steve Beck','When Cyrus Kriticos, a very rich collector of unique things dies, he leaves it all to his nephew and his family. All including his house, his fortune, and his malicious collection of ghosts! (USA,Canada)','Tony Shalhoub,Embeth Davidtz,Matthew Lillard,Shannon Elizabeth,Alec Roberts,JR Bourne,Rah Digga,F. Murray Abraham,Matthew Harrison,Jacob Rupp,Mike Crestejo,Aubrey Culp,Charles Andre,Mikhael Speidel,Daniel Wesley','0245674',2001,5,91,1,'/myth/video/library/Movie/13 Ghosts (2001).avi','/myth/video/.covers/0245674.jpg',-1,1,'playvideo.sh \"/cdrom/13 Ghosts (2001).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (3,'2001: A Space Odyssey','Stanley Kubrick','Mankind finds a mysterious, obviously artificial, artifact buried on the moon and, with the intelligent computer HAL, sets off on a quest. (UK,USA)','Keir Dullea,Gary Lockwood,William Sylvester,Daniel Richter,Leonard Rossiter,Margaret Tyzack,Robert Beatty,Sean Sullivan,Douglas Rain,Frank Miller,Bill Weston,Ed Bishop,Glenn Beck,Alan Gifford,Ann Gillis','0062622',1968,8.3,0,1,'/myth/video/library/Movie/2001 - A Space Odyssey (1968).avi','/myth/video/.covers/0062622.jpg',-1,1,'playvideo.sh \"/cdrom/2001 - A Space Odyssey (1968).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (4,'51st State','Ronny Yu','An American master chemist plans to score big on a once in a lifetime drug deal. All does not go as planned and he is soon entangled in a web of deceit. (UK,Canada)','Samuel L. Jackson,Nigel Whitmey,Robert Jezek,Emily Mortimer,Meat Loaf,Jake Abraham,Mac McDonald,Aaron Swartz,David Webber,Michael J. Reynolds,Sonny Muslim,Barbara Barnes,Junix Nocian,Robert Carlyle,Paul Barber','0227984',2001,6.1,92,1,'/myth/video/library/Movie/51St State (2001).avi','/myth/video/.covers/0227984.jpg',-1,1,'playvideo.sh \"/cdrom/51St State (2001).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (5,'A Clockwork Orange','Stanley Kubrick','In a futuristic Britain, a gang of teenagers go on the rampage every night, beating and raping helpless victims...\n (UK)','Malcolm McDowell,Patrick Magee,Michael Bates,Warren Clarke,John Clive,Adrienne Corri,Carl Duering,Paul Farrell,Clive Francis,Michael Gover,Miriam Karlin,James Marcus,Aubrey Morris,Godfrey Quigley,Sheila Raynor','0066921',1971,8.4,136,1,'/myth/video/library/Movie/A Clockwork Orange (1971).avi','/myth/video/.covers/0066921.jpg',-1,1,'playvideo.sh \"/cdrom/A Clockwork Orange (1971).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (6,'About a Boy','Chris Weitz','Based on Nick Hornby\'s best-selling novel, About A Boy is the story of a cynical, immature young man who is taught how to act like a grown-up by a little boy (UK,USA,France,Germany)','Hugh Grant,Nicholas Hoult,Toni Collette,Rachel Weisz,Sharon Small,Madison Cook,Jordan Cook,Nicholas Hutchison,Ryan Speechley,Joseph Speechley,Natalia Tena,Laura Kennington,Tanika Swaby,Peter McNicholl,Christopher Webster','0276751',2002,7.5,101,1,'/myth/video/library/Movie/About A Boy (2002).avi','/myth/video/.covers/0276751.jpg',-1,1,'playvideo.sh \"/cdrom/About A Boy (2002).avi\" 0001',4);
INSERT INTO `videometadata` VALUES (7,'Ali','Michael Mann','A biography of sports legend, Muhammad Ali, from his early days to his days in the ring. (USA)','Will Smith,Jamie Foxx,Jon Voight,Mario Van Peebles,Ron Silver,Jeffrey Wright,Mykelti Williamson,Jada Pinkett Smith,Nona Gaye,Michael Michele,Joe Morton,Bruce McGill,Paul Rodriguez,Barry Shabaka Henley,Giancarlo Esposito','0248667',2001,6.3,159,1,'/myth/video/library/Movie/Ali (2001)-CD1.avi','/myth/video/.covers/0248667.jpg',8,1,'playvideo.sh \"/cdrom/Ali (2001)-CD1.avi\" 0002',4);
INSERT INTO `videometadata` VALUES (8,'Ali','Michael Mann','A biography of sports legend, Muhammad Ali, from his early days to his days in the ring. (USA)','Will Smith,Jamie Foxx,Jon Voight,Mario Van Peebles,Ron Silver,Jeffrey Wright,Mykelti Williamson,Jada Pinkett Smith,Nona Gaye,Michael Michele,Joe Morton,Bruce McGill,Paul Rodriguez,Barry Shabaka Henley,Giancarlo Esposito','0248667',2001,6.3,159,1,'/myth/video/library/Movie/Ali (2001)-CD2.avi','/myth/video/.covers/0248667.jpg',-1,0,'playvideo.sh \"/cdrom/Ali (2001)-CD2.avi\" 0002',4);
I very slightly modified imdb.pl, the script that grabs the imdb info changes are marked with a xxxx. This makes it use countries field for first 4 actors instead and a few other changes I deemed necessary
Code:
#!/usr/bin/perl -w
# /usr/share/mythtv/mythvideo/scripts/imdb.pl
#
# This perl script is intended to perform movie data lookups based on
# the popular www.imdb.com website
#
# For more information on MythVideo's external movie lookup mechanism, see
# the README file in this directory.
#
# Author: Tim Harvey (tharvey AT alumni.calpoly DOT edu)
# Modified: Andrei Rjeousski
# v1.1
# - Added amazon.com covers and improved handling for imdb posters
# v1.2
# - when searching amazon, try searching for main movie name and if nothing is found, search for informal name
# - better handling for amazon posters, see if movie title is a substring in the search results returned by amazon
# - fixed redirects for some movies on impawards
use LWP::Simple; # libwww-perl providing simple HTML get actions
use HTML::Entities;
use URI::Escape;
use XML::Simple;
use vars qw($opt_h $opt_r $opt_d $opt_i $opt_v $opt_D $opt_M $opt_P);
use Getopt::Std;
$title = "IMDB Query";
$version = "v1.2";
$author = "Tim Harvey, Andrei Rjeousski";
# display usage
sub usage {
print "usage: $0 -hdrviMPD [parameters]\n";
print " -h help\n";
print " -d debug\n";
print " -r dump raw query result data only\n";
print " -v display version\n";
print " -i display info\n";
print "\n";
print " -M [options] <query> get movie list\n";
print " some known options are:\n";
print " type=[fuzy] looser search\n";
print " from_year=[int] limit matches to year\n";
print " to_year=[int] limit matches to year\n";
print " sort=[smart] ??\n";
print " tv=[no|both|only] limits between tv and movies\n";
print " Note: multiple options must be separated by ';'\n";
print " -P <movieid> get movie poster\n";
print " -D <movieid> get movie data\n";
exit(-1);
}
# display 1-line of info that describes the version of the program
sub version {
print "$title ($version) by $author\n"
}
# display 1-line of info that can describe the type of query used
sub info {
print "Performs queries using the www.imdb.com website.\n";
}
# display detailed help
sub help {
version();
info();
usage();
}
# returns text within 'data' between 'beg' and 'end' matching strings
sub parseBetween {
my ($data, $beg, $end)=@_; # grab parameters
my $ldata = lc($data);
my $start = index($ldata, lc($beg)) + length($beg);
my $finish = index($ldata, lc($end), $start);
if ($start != (length($beg) -1) && $finish != -1) {
my $result = substr($data, $start, $finish - $start);
# return w/ decoded numeric character references
# (see http://www.w3.org/TR/html4/charset.html#h-5.3.1)
decode_entities($result);
return $result;
}
return "";
}
# get Movie Data
sub getMovieData {
my ($movieid)=@_; # grab movieid parameter
if (defined $opt_d) { printf("# looking for movie id: '%s'\n", $movieid);}
# get the search results page
my $request = "http://www.imdb.com/title/tt" . $movieid . "/";
if (defined $opt_d) { printf("# request: '%s'\n", $request); }
my $response = get $request;
if (defined $opt_r) { printf("%s", $response); }
# parse title and year
my $title = parseBetween($response, "<title>", "</title>");
$title =~ m#(.+) \((\d+).*\)#; # Note some years have a /II after them?
$title = $1;
my $year = $2;
# parse director
my $director = parseBetween($response, ">Directed by</b>", "/a><br>");
$director = parseBetween($director, "/\">", "<");
# parse writer
# (Note: this takes the 'first' writer, may want to include others)
my $writer = parseBetween($response, ">Writing credits</b>", "</table>");
$writer = parseBetween($writer, "/\">", "</");
# parse plot
my $plot = parseBetween($response, ">Plot Outline:</b> ", "<a href=\"");
if (!$plot) {
$plot = parseBetween($response, ">Plot Summary:</b> ", "<a href=\"");
}
# parse user rating
my $userrating = parseBetween($response, ">User Rating:</b>", "> (");
$userrating = parseBetween($userrating, "<b>", "/");
# parse MPAA rating
my $ratingcountry = "USA";
my $movierating = parseBetween($response, ">MPAA</a>:</b> ", "<br>");
if (!$movierating) {
$movierating = parseBetween($response, ">Certification:</b>", "<br>");
$movierating = parseBetween($movierating, "certificates=$ratingcountry",
"/a>");
$movierating = parseBetween($movierating, ">", "<");
}
# parse movie length
my $runtime = parseBetween($response, ">Runtime:</b>\n", " min");
# parse cast
# Note: full cast would be from url:
# www.imdb.com/title/<movieid>/fullcredits
my @actors;
my $cast = "";
my $cast4 = ""; #xxx new var to hold just 1st four actors
my $count = 0;
my $data = parseBetween($response, "Cast overview, first billed only:",
"/table>");
if ($data) {
my $beg = "/\">";
my $end = "</a>";
my $start = index($data, $beg);
my $finish = index($data, $end, $start);
my $actor;
while ($start != -1) {
$start += length($beg);
$actor = substr($data, $start, $finish - $start);
# add to array
$actors[$count++] = $actor;
# advance data to next movie
$data = substr($data, - (length($data) - $finish));
$start = index($data, $beg);
$finish = index($data, $end, $start + 1);
}
$cast = join(',', @actors);
$cast4 = join(',', @actors[0..3]); #xxx add up to first 4 actors to cast4 (change the 3 if you want more)
}
# parse genres
my @genres;
my $lgenres = "";
$count = 0;
$data = parseBetween($response, "<b class=\"ch\">Genre:</b>","<a href=\"/rg/title-tease/keywords/title/tt$movieid/keywords\">(more)</a>");
if ($data) {
my $beg = "/\">";
my $end = "</a>";
my $start = index($data, $beg);
my $finish = index($data, $end, $start);
my $genre;
while ($start != -1) {
$start += length($beg);
$genre = substr($data, $start, $finish - $start);
# add to array
$genres[$count++] = $genre;
# advance data to next movie
$data = substr($data, - (length($data) - $finish));
$start = index($data, $beg);
$finish = index($data, $end, $start + 1);
}
$lgenres = join(',', @genres);
}
# parse countries
my @countries;
my $lcountries = "";
$count = 0;
$data = parseBetween($response, "<b class=\"ch\">Country:</b>","<br>");
if ($data) {
my $beg = "/\">";
my $end = "</a>";
my $start = index($data, $beg);
my $finish = index($data, $end, $start);
my $country;
while ($start != -1) {
$start += length($beg);
$country = substr($data, $start, $finish - $start);
# add to array
$countries[$count++] = $country;
# advance data to next movie
$data = substr($data, - (length($data) - $finish));
$start = index($data, $beg);
$finish = index($data, $end, $start + 1);
}
$lcountries = join(',', @countries);
}
# output fields (these field names must match what MythVideo is looking for)
print "Title:$title\n";
print "Year:$year\n";
print "Director:$director\n";
print "Plot:$plot ($lcountries)\n"; #xxx print "Plot:$plot\n";
print "UserRating:$userrating\n";
print "MovieRating:$cast\n"; #xxx print "MovieRating:$movierating\n";
print "Runtime:$runtime\n";
print "Writers: $writer\n";
print "Cast: $cast\n";
print "Genres: $lgenres\n";
print "Countries: $cast4\n"; #xxx print "Countries: $lcountries\n";
}
# dump Movie Poster
sub getMoviePoster {
my ($movieid)=@_; # grab movieid parameter
if (defined $opt_d) { printf("# looking for movie id: '%s'\n", $movieid);}
# get the search results page
my $request = "http://www.imdb.com/title/tt" . $movieid . "/posters";
if (defined $opt_d) { printf("# request: '%s'\n", $request); }
my $response = get $request;
if (defined $opt_r) { printf("%s", $response); }
my $uri = "";
# look for references to impawards.com posters - they are high quality
my $site = "http://www.impawards.com";
my $impsite = parseBetween($response, "<a href=\"".$site, "\">".$site);
# jersey girl fix
$impsite = parseBetween($response, "<a href=\"http://impawards.com","\">http://impawards.com") if ($impsite eq "");
if ($impsite) {
$impsite = $site . $impsite;
if (defined $opt_d) { print "# Searching for poster at: ".$impsite."\n"; }
my $impres = get $impsite;
if (defined $opt_d) { printf("# got %i bytes\n", length($impres)); }
if (defined $opt_r) { printf("%s", $impres); }
# making sure it isnt redirect
$uri = parseBetween($impres, "0;URL=..", "\">");
if ($uri ne "") {
if (defined $opt_d) { printf("# processing redirect to %s\n",$uri); }
# this was redirect
$impsite = $site . $uri;
$impres = get $impsite;
}
# do stuff normally
$uri = parseBetween($impres, "<img SRC=\"posters/", "\" ALT");
# uri here is relative... patch it up to make a valid uri
if (!($uri =~ /http:(.*)/ )) {
my $path = substr($impsite, 0, rindex($impsite, '/') + 1);
$uri = $path."posters/".$uri;
}
if (defined $opt_d) { print "# found ipmawards poster: $uri\n"; }
}
# if the impawards site attempt didn't give a filename grab it from imdb
if ($uri eq "") {
if (defined $opt_d) { print "# looking for imdb posters\n"; }
my $host = "http://posters.imdb.com/posters/";
$uri = parseBetween($response, $host, "\"><td><td><a href=\"");
if ($uri ne "") {
$uri = $host.$uri;
} else {
if (defined $opt_d) { print "# no poster found\n"; }
}
}
# now we couldnt even find lowres poster from IMDB, lets try looking for dvd
# cover on amazon.com
my @movie_titles;
my $found_low_res = 0;
my $k = 0;
# no poster found, take lowres image from imdb
if ($uri eq "") {
if (defined $opt_d) { print "# looking for lowres imdb posters\n"; }
my $host = "http://www.imdb.com/title/tt" . $movieid . "/";
$response = get $host;
$uri = parseBetween($response, "alt=\"cover\" src=\"http://ia.imdb.com/media/imdb/", "\"");
if (defined $opt_d) { print "# starting to look for movie title\n"; }
# get main title
if (defined $opt_d) { print "# Getting possible movie titles:\n"; }
$movie_titles[$k++] = parseBetween($response, "<title>", "<\/title>");
if (defined $opt_d) { print "# Title: ".$movie_titles[$k-1]."\n"; }
# now we get all other possible movie titles and store them in the titles array
while($response =~ m/>([^>^\(]*)([ ]{0,1}\([^\)]*\)[^\(^\)]*[ ]{0,1}){0,1}\(informal title\)/g) {
$movie_titles[$k++] = $1;
chomp($movie_titles[$k-1]);
$movie_titles[$k-1] =~ s/^\s+//;
$movie_titles[$k-1] =~ s/\s+$//;
if (defined $opt_d) { print "# Title: ".$movie_titles[$k-1]."\n"; }
}
if ($uri ne "" ) {
$uri = "http://ia.imdb.com/media/imdb/".$uri;
$found_low_res = 1;
} else {
if (defined $opt_d) { print "# no poster found\n"; }
}
}
# now we couldnt even find lowres poster from IMDB, lets try looking for dvd
# cover on amazon.com
if ($uri eq "" or $found_low_res) {
if (defined $opt_d) { print "# starting to look for poster on Amazon.com\n"; }
my $titleid = 0;
my $found = 0;
my $ama_uri = "";
my $xml_parser = XML::Simple->new();
do {
# get rid of the year
$movie_titles[$titleid] =~ s/ ?\([^\)]+\) ?//g;
$movie_titles[$titleid] =~ /(.*), The$/i;
if ($1) { $movie_titles[$titleid] = $1; }
$movie_titles[$titleid] =~ s/[\"\']//g; # if we give amazon quotes they give them back
if (defined $opt_d) { print "# Searching for: $movie_titles[$titleid]\n"; }
# Encode the movie title to be save
my $safe_movie_title = $movie_titles[$titleid];
$safe_movie_title =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
# request XML info from amazon
my $xml_uri = "http://xml.amazon.com/onca/xml3?t=000&dev-t=000&KeywordSearch=".$safe_movie_title."&mode=dvd&type=lite&page=1&f=xml";
if (defined $opt_d) { print "# Amazon request string is: $xml_uri\n";}
# get the response
$response = get $xml_uri;
if (defined $opt_r) { printf("%s", $response); }
# parse the response
my $xml_doc = $xml_parser->XMLin($response);
# if we only got one result, fake it as array
if (ref($xml_doc->{Details}) ne 'ARRAY') {
my @tmpArray = ($xml_doc->{Details});
$xml_doc->{Details} = \@tmpArray;
}
$k = 0;
do {
if (ref($xml_doc->{Details}->[$k]) eq 'HASH') {
my $tmp_movie_title = $xml_doc->{Details}->[$k]->{ProductName};
$tmp_movie_title =~ s/[\"\']//g;
if (defined $opt_d) { print "# Amazon: comparing (" . $tmp_movie_title . ") to (" . $movie_titles[$titleid] . ")\n"; }
if ($tmp_movie_title =~ /.*$movie_titles[$titleid].*/) {
if (defined $opt_d) { print "# Amazon: found poster " . $xml_doc->{Details}->[$k]->{ImageUrlLarge} . "\n"; }
$ama_uri = $xml_doc->{Details}->[$k]->{ImageUrlLarge};
$found = 1;
}
}
$k++;
} until ($found || $k == 5);
#only search through first 5 matches
$titleid++;
} until ($found || $titleid > $#movie_titles);
my $image = get $ama_uri if (defined($ama_uri) && $ama_uri ne "");
if ($ama_uri ne "" && length($image) eq "807") {
if (defined $opt_d) { printf("# this image is blank\n"); }
$ama_uri = "";
}
if (!defined($ama_uri)) {
$ama_uri = "";
}
if ($ama_uri ne "") {
$uri = $ama_uri;
}
}
print "$uri\n";
}
# dump Movie list: 1 entry per line, each line as 'movieid:Movie Title'
sub getMovieList {
my ($filename, $options)=@_; # grab parameters
# If we wanted to inspect the file for any reason we can do that now
#
# Convert filename into a query string
# (use same rules that Metadata::guesTitle does)
my $query = $filename;
$query = uri_unescape($query); # in case it was escaped
# Strip off the file extension
if (rindex($query, '.') != -1) {
$query = substr($query, 0, rindex($query, '.'));
}
# Strip off anything following '(' - people use this for general comments
if (rindex($query, '(') != -1) {
$query = substr($query, 0, rindex($query, '('));
}
# Strip off anything following '[' - people use this for general comments
if (rindex($query, '[') != -1) {
$query = substr($query, 0, rindex($query, '['));
}
# IMDB searches do better if any trailing ,The is left off
$query =~ /(.*), The$/i;
if ($1) { $query = $1; }
# prepare the url
$query = uri_escape($query);
if (!$options) { $options = "" ;}
if (defined $opt_d) {
printf("# query: '%s', options: '%s'\n", $query, $options);
}
# get the search results page
# some known IMDB options are:
# type=[fuzy] looser search
# from_year=[int] limit matches to year (broken at imdb)
# to_year=[int] limit matches to year (broken at imdb)
# sort=[smart] ??
# tv=[no|both|only] limits between tv and movies (broken at imdb)
#$options = "tt=on;nm=on;mx=20"; # not exactly clear what these options do
my $request = "http://www.imdb.com/find?q=$query;$options";
if (defined $opt_d) { printf("# request: '%s'\n", $request); }
my $response = get $request;
if (defined $opt_r) {
print $response;
exit(0);
}
# check to see if we got a results page or a movie page
# looking for 'add=<movieid>" target=' which only exists
# in a movie description page
my $movienum = parseBetween($response, "add=", "\" target=");
if ($movienum) {
if (defined $opt_d) { printf("# redirected to movie page\n"); }
my $movietitle = parseBetween($response, "<title>", "</title>");
$movietitle =~ m#(.+) \((\d+)\)#;
$movietitle = $1;
print "$movienum:$movietitle\n";
exit(0);
}
# extract possible matches
# possible matches are grouped in several catagories:
# exact, partial, and approximate
my $popular_results = parseBetween($response, "<b>Popular Titles</b>",
"</ol>");
my $exact_matches = parseBetween($response, "<b>Titles (Exact Matches)</b>",
"</ol>");
my $partial_matches = parseBetween($response, "<b>Titles (Partial Matches)</b>",
"</ol>");
# my $approx_matches = parseBetween($response, "<b>Approximate Matches</b>",
# "</ol>");
# parse movie list from matches
my $beg = "<li>";
my $end = "</li>";
my $count = 0;
my @movies;
# my $data = $exact_matches.$partial_matches;
my $data = $popular_results.$exact_matches;
# resort to partial matches if no exact
if ($data eq "") { $data = $partial_matches; }
# resort to approximate matches if no exact or partial
# if ($data eq "") { $data = $approx_matches; }
if ($data eq "") {
if (defined $opt_d) { printf("# no results\n"); }
return;
}
my $start = index($data, $beg);
my $finish = index($data, $end, $start);
my $year;
my $type;
my $title;
while ($start != -1 && $start < length($data)) {
$start += length($beg);
my $entry = substr($data, $start, $finish - $start);
$start = index($data, $beg, $finish + 1);
$finish = index($data, $end, $start);
my $title = "";
my $year = "";
my $type = "";
my $movienum = "";
my $link_end = "</a>";
$fl_end = index($entry, $link_end);
$fl_end += length($link_end);
my $lhs = substr($entry, 0, $fl_end);
my $rhs = substr($entry, $fl_end);
if ($lhs =~ m/<a href="\/title\/tt(\d+)\/.*\">(.+)<\/a>/i) {
$movienum = $1;
$title = $2;
} else {
if (defined $opt_d) {
print("Unrecognized entry format\n");
}
next;
}
if ($rhs =~ m/\((\d+)\) \((.+)\)/) {
$year = $1;
$type = $2;
} elsif ($rhs =~ m/\((\d+)\)/) {
$year = $1;
}
my $skip = 0;
# fix broken 'tv=no' option
if ($options =~ /tv=no/) {
if ($type eq "TV") {
if (defined $opt_d) {printf("# skipping TV program: %s\n", $title);}
$skip = 1;
}
}
if ($options =~ /tv=only/) {
if ($type eq "") {
if (defined $opt_d) {printf("# skipping Movie: %s\n", $title);}
$skip = 1;
}
}
# fix broken 'from_year=' option
if ($options =~ /from_year=(\d+)/) {
if ($year < $1) {
if (defined $opt_d) {printf("# skipping b/c of yr: %s\n", $title);}
$skip = 1;
}
}
# fix broken 'to_year=' option
if ($options =~ /to_year=(\d+)/) {
if ($year > $1) {
if (defined $opt_d) {printf("# skipping b/c of yr: %s\n", $title);}
$skip = 1;
}
}
# option to strip out videos (I think that's what '(V)' means anyway?)
if ($options =~ /video=no/) {
if ($type eq "V") {
if (defined $opt_d) {
printf("# skipping Video program: %s\n", $title);
}
$skip = 1;
}
}
# (always) strip out video game's (why does IMDB give these anyway?)
if ($type eq "VG") {
if (defined $opt_d) {printf("# skipping videogame: %s\n", $title);}
$skip = 1;
}
# add to array
if (!$skip) {
my $moviename = $title;
if ($year ne "") {
$moviename .= " ($year)";
}
# $movies[$count++] = $movienum . ":" . $title;
$movies[$count++] = $movienum . ":" . $moviename;
}
}
# display array of values
for $movie (@movies) { print "$movie\n"; }
}
#
# Main Program
#
# parse command line arguments
getopts('ohrdivDMP');
# print out info
if (defined $opt_v) { version(); exit 1; }
if (defined $opt_i) { info(); exit 1; }
# print out usage if needed
if (defined $opt_h || $#ARGV<0) { help(); }
if (defined $opt_D) {
# take movieid from cmdline arg
$movieid = shift || die "Usage : $0 -D <movieid>\n";
getMovieData($movieid);
}
elsif (defined $opt_P) {
# take movieid from cmdline arg
$movieid = shift || die "Usage : $0 -P <movieid>\n";
getMoviePoster($movieid);
}
elsif (defined $opt_M) {
# take query from cmdline arg
$options = shift || die "Usage : $0 -M [options] <query>\n";
$query = shift;
if (!$query) {
$query = $options;
$options = "";
}
getMovieList($query, $options);
}
ANYWAY If anyone ploughs through this and gets it all working, well done. It took me over a month solid to write and hone these. I've coded for yonks at all levels on windoze but this is my first forray into linux. I know it may seem mad to do all this in bash, but I did it to learn bash/linux. Maybe this may go someway to explaining why I was so mad when mythvideo was trashed in 0.19 to make it really slow, and try to ignore the database, obviously nullifying the original authors design intentions. In 0.19 why even bother using a database you clearly don't want to. As stated earlier I'll try to create a proper installer script and make it more generic/simpler sometime (maybe) but don't hold yer breath. If anyone else cares to, that'd be greatly appreciated...