All pastes #1405887 Raw Edit

Anonymous

public text v1 · immutable
#1405887 ·published 2009-04-28 08:54 UTC
rendered paste body
use warnings;
require LWP;

my ($script_name, $script_version, $script_description) =
        ("URL-Title-Fetch", "0.2", "Automatically grabs, parses and prints title from URLs");
Xchat::register($script_name, $script_version, $script_description);

Xchat::hook_print("Channel Message", sub {
	my ($nick, $text, $modechar) = @{$_[0]};
	my @words=split " ",$text;
  	foreach (@words) {
		if ( m/http|www\./) { 
			if ( $_ =~ "www." and $_ !~ "http://" ) { $_="http://".$_;}
			my $request = HTTP::Request->new(GET => $_);
			my $ua = LWP::UserAgent->new;
			my $result = $ua->request($request);
				if ($result->is_success) {
				my $ct = $result->header("Content-Type");
					if($ct =~ m/html|xml/ and $result ne '') {
					my $title = $result->title;
					Xchat::print("URL Title - $title");
					}
				}
				else {
				Xchat::print("Invalid URL or no title");
				} # !/\.(jpg|txt|png|gif|zip|rar|mp3|ogg|flac|wmv|mkv|mp4|avi|torrent|wav|aac)$/	
		}
	}
	return Xchat::EAT_NONE;
	
});