]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
[imdb] v1.03
authorbw1 <redacted>
Fri, 8 Jan 2021 16:12:41 +0000 (17:12 +0100)
committerbw1 <redacted>
Sun, 24 Jan 2021 21:09:25 +0000 (22:09 +0100)
+ update url
+ self check

scripts/imdb.pl

index cf5fca7ce998b8e85fa0c0d10c8e853ea16d2c3c..c72476eeb2cf5e278bc667423cefe60052161e1b 100644 (file)
@@ -4,7 +4,7 @@ use LWP::UserAgent;
 use HTML::Entities;
 use vars qw($VERSION %IRSSI $cache);
 
-$VERSION = '1.02';
+$VERSION = '1.03';
 %IRSSI = (
     authors    => 'Eric Jansen',
     contact    => 'chaos@sorcery.net',
@@ -13,7 +13,8 @@ $VERSION = '1.02';
     license    => 'GPL',
     modules    => 'LWP::UserAgent HTML::Entities',
     url                => 'http://xyrion.org/irssi/',
-    changed    => '2018-06-14'
+    changed    => '2021-01-08',
+    selfcheckcmd=> 'imdb check',
 );
 
 my $ua = new LWP::UserAgent;
@@ -22,6 +23,8 @@ $ua->agent('Irssi; ' . $ua->agent);
 # Set the timeout to five second, so it won't freeze the client too long on laggy connections
 $ua->timeout(5);
 
+my $last_result;
+
 sub event_nickchange {
 
     my ($channel, $nick, $old_nick) = @_;
@@ -42,7 +45,7 @@ sub event_nickchange {
        else {
 
            # Fetch the movie detail page
-           my $req = new HTTP::Request(GET => "http://us.imdb.com/title/tt$id");
+           my $req = new HTTP::Request(GET => "http://www.imdb.com/title/tt$id");
            my $res = $ua->request($req);
 
            # Get the title and year from the fetched page
@@ -58,9 +61,14 @@ sub event_nickchange {
 
                # Decode special characters in the title
                $title= decode_entities($title);
+               $last_result= { title=> $title, year=> $year };
 
                # Print it
-               $channel->printformat(MSGLEVEL_CRAP, 'imdb_lookup', $old_nick, $title, $year);
+               if ($channel->{type} eq "CHANNEL" ) {
+                   $channel->printformat(MSGLEVEL_CRAP, 'imdb_lookup', $old_nick, $title, $year);
+               } else {
+                   Irssi::printformat(MSGLEVEL_CRAP, 'imdb_lookup', $old_nick, $title, $year);
+               }
 
                # And cache it
                $cache->{$id} = {
@@ -72,7 +80,36 @@ sub event_nickchange {
     }
 }
 
+# /imdb
+sub cmd {
+    my ($args, $server, $witem)=@_;
+    if ($args =~ m/check/) {
+       my $s='ok';
+       $last_result= {};
+       $witem->{'ownnick'}->{'nick'}="sepp";
+       my $nick={ nick=>"susi_1234567" };
+       event_nickchange( $witem, $nick , "imdb");
+       unless ( $last_result->{title} =~ m/You Can Dance/ ) {
+           $s="Error: title ($last_result->{title})";
+       }
+       unless ($last_result->{year} =~ m/2008/ ) {
+           $s="Error: year ($last_result->{year})";
+       }
+       Irssi::print("imdb: self check: $s");
+       my $schs_version = $Irssi::Script::selfcheckhelperscript::VERSION;
+       Irssi::command("selfcheckhelperscript $s") if ( defined $schs_version );
+    } elsif ( $args =~ m/\d{7}/ ) {
+       $args =~ s/\s//g;
+       $witem->{'ownnick'}->{'nick'}="sepp";
+       my $nick={ nick=>"susi_$args" };
+       event_nickchange( $witem, $nick , "imdb");
+    }
+}
+
 Irssi::theme_register([
     'imdb_lookup', '{nick $0} is watching {hilight $1} ($2)'
 ]);
 Irssi::signal_add('nicklist changed', 'event_nickchange');
+Irssi::command_bind($IRSSI{name},\&cmd);
+
+# vim:set ts=8 sw=4:
git clone https://git.99rst.org/PROJECT