All pastes #2080038 Raw Edit

Stuff

public text v1 · immutable
#2080038 ·published 2011-09-06 06:13 UTC
rendered paste body
#!/usr/bin/perl -w
use Irssi;
use XML::Simple;
use LWP::Simple;


sub evt_own {
  my($server,$text,$channel,$hostmask)=@_;
  csekk_youtube($server,$text,$channel);
}

sub evt_other {
  my($server,$text,$nick,$hostmask,$channel)=@_;
  csekk_youtube($server,$text,$channel);
}

sub csekk_youtube
{
  my($server,$text,$channel)=@_;
  if ($text =~ m/youtube\.com|youtu\.be/ )
  {
     my $d;
     $text =~ /(v=|be\/|\/v\/)(.{11})/;
     my $match;
     if ($2 eq "") {
        $match = "boo";
     }
     else {
        $match = $2;
     }
     if($d = get("http://gdata.youtube.com/feeds/api/videos/" . $match ))
     {
       if($d ne "Invalid id")

       {
         my $xml = new XML::Simple;
         my $meta = $xml->XMLin($d);
         $server->command("MSG $channel de hiszen ez " . $meta->{title}->{content} );
       }
       else
       {
         Irssi::print("invalid id: $text");
       }
     }
     else
     {
       Irssi::print("connect failed / invalid id / not yt link: " . $text);
     }
  }
}

Irssi::signal_add_last("message public", "evt_other");
Irssi::signal_add_last("message own_public", "evt_own");