]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
[imdb] update connection to the website
authorbw1 <redacted>
Thu, 14 Jun 2018 18:57:12 +0000 (20:57 +0200)
committerbw1 <redacted>
Thu, 14 Jun 2018 18:57:12 +0000 (20:57 +0200)
scripts/imdb.pl

index b23d65c2a6382f4ffad6e5bdd3562ce520d1a11e..cf5fca7ce998b8e85fa0c0d10c8e853ea16d2c3c 100644 (file)
@@ -1,25 +1,26 @@
+use strict;
 use Irssi;
 use LWP::UserAgent;
-use strict;
+use HTML::Entities;
 use vars qw($VERSION %IRSSI $cache);
 
-$VERSION = '1.01';
+$VERSION = '1.02';
 %IRSSI = (
     authors    => 'Eric Jansen',
     contact    => 'chaos@sorcery.net',
     name       => 'imdb',
     description => 'Automatically lookup IMDB-numbers in nicknames',
     license    => 'GPL',
-    modules    => 'LWP::UserAgent',
+    modules    => 'LWP::UserAgent HTML::Entities',
     url                => 'http://xyrion.org/irssi/',
-    changed    => 'Sat Mar  1 12:39:49 CET 2003'
+    changed    => '2018-06-14'
 );
 
 my $ua = new LWP::UserAgent;
 $ua->agent('Irssi; ' . $ua->agent);
 
-# Set the timeout to one second, so it won't freeze the client too long on laggy connections
-$ua->timeout(1);
+# Set the timeout to five second, so it won't freeze the client too long on laggy connections
+$ua->timeout(5);
 
 sub event_nickchange {
 
@@ -41,16 +42,22 @@ sub event_nickchange {
        else {
 
            # Fetch the movie detail page
-           my $req = new HTTP::Request(GET => "http://us.imdb.com/Title?$id");
+           my $req = new HTTP::Request(GET => "http://us.imdb.com/title/tt$id");
            my $res = $ua->request($req);
 
            # Get the title and year from the fetched page
-           if($res->is_success && $res->content =~ /<title>(.+?) \((\d+)\)<\/title>/) {
+           if($res->is_success
+               && $res->content  =~ /<title>(.+?) \((.+)\).*<\/title>/) {
+
+       # https://www.imdb.com/title/tt1234567/
+       # <title>&quot;So You Think You Can Dance&quot; The Top 14 Perform (TV Episode 2008) - IMDb</title>
+       # https://www.imdb.com/title/tt0234567/
+       # <title>The Ranchman's Nerve (1911) - IMDb</title>
 
                my ($title, $year) = ($1, $2);
 
                # Decode special characters in the title
-               $title =~ s/&#(\d+);/pack('U*', $1)/eg;
+               $title= decode_entities($title);
 
                # Print it
                $channel->printformat(MSGLEVEL_CRAP, 'imdb_lookup', $old_nick, $title, $year);
git clone https://git.99rst.org/PROJECT