[mythtv] [PATCH] Mythvideo: better HTTP for imdb.pl
Neil Whelchel
koyama at firstlight.net
Mon Apr 11 22:40:08 UTC 2005
Hello,
This patch modifies imdb.pl to use wget instead of LWP.
Wget seems to handle bad/slow connections much better.
-Neil Whelchel-
First Light Internet Services
760 366-0145
- We don't do Window$, that's what the janitor is for -
Bubble Memory, n.:
A derogatory term, usually referring to a person's
intelligence. See also "vacuum tube".
-------------- next part --------------
--- imdb.pl.orig Sat Apr 9 12:36:36 2005
+++ imdb.pl Mon Apr 11 15:07:17 2005
@@ -16,7 +16,6 @@
# - 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;
@@ -68,6 +67,19 @@
usage();
}
+sub get($$){
+ my ($request, $timeout)=@_;
+ open(NET, "wget -q -t 4 -T 6 --read-timeout=$timeout -O - \"$request\" |");
+ my $response;
+ while(<NET>){
+ $response.=$_;
+ }
+ close(NET);
+ return($response);
+}
+
+
+
# returns text within 'data' between 'beg' and 'end' matching strings
sub parseBetween {
my ($data, $beg, $end)=@_; # grab parameters
@@ -93,7 +105,8 @@
# 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;
+
+ my $response = get ($request, 8);
if (defined $opt_r) { printf("%s", $response); }
# parse title and year
@@ -235,7 +248,7 @@
# 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;
+ my $response = get($request, 8);
if (defined $opt_r) { printf("%s", $response); }
my $uri = "";
@@ -251,7 +264,7 @@
$impsite = $site . $impsite;
if (defined $opt_d) { print "# Searching for poster at: ".$impsite."\n"; }
- my $impres = get $impsite;
+ my $impres = get($impsite, 8);
if (defined $opt_d) { printf("# got %i bytes\n", length($impres)); }
if (defined $opt_r) { printf("%s", $impres); }
@@ -261,7 +274,7 @@
if (defined $opt_d) { printf("# processing redirect to %s\n",$uri); }
# this was redirect
$impsite = $site . $uri;
- $impres = get $impsite;
+ $impres = get($impsite, 8);
}
@@ -299,7 +312,7 @@
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;
+ $response = get($host, 8);
$uri = parseBetween($response, "alt=\"cover\" src=\"http://ia.imdb.com/media/imdb/", "\"");
@@ -356,7 +369,7 @@
if (defined $opt_d) { print "# Amazon request string is: $xml_uri\n";}
# get the response
- $response = get $xml_uri;
+ $response = get($xml_uri, 8);
if (defined $opt_r) { printf("%s", $response); }
# parse the response
@@ -388,7 +401,7 @@
$titleid++;
} until ($found || $titleid > $#movie_titles);
- my $image = get $ama_uri if (defined($ama_uri) && $ama_uri ne "");
+ my $image = get($ama_uri, 20) 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 = "";
@@ -451,7 +464,7 @@
#$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;
+ my $response = get($request, 8);
if (defined $opt_r) {
print $response;
exit(0);
More information about the mythtv-dev
mailing list