Created
August 11, 2009 11:52
-
-
Save yusukebe/165769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $done = AnyEvent->condvar; | |
my $guard = AnyEvent::Twitter::Stream->new( | |
username => $user, | |
password => $password, | |
method => "track", | |
track => 'http', | |
on_tweet => sub { | |
my $tweet = shift; | |
my @links; | |
my $finder = URI::Find->new( | |
sub { | |
my $uri = shift; | |
push( @links, $uri->as_string ); | |
} | |
); | |
$finder->find( \$tweet->{text} ); | |
for my $link ( @links ){ | |
my $permalink = filter( $link ); | |
warn $permalink . "\n" if $permalink; | |
} | |
}, | |
on_error => sub { | |
my $error = shift; | |
warn "ERROR: $error"; | |
$done->send; | |
}, | |
on_eof => sub { | |
$done->send; | |
}, | |
); | |
$done->recv; | |
sub filter { | |
my $url = shift; | |
my $ua = LWP::UserAgent->new(); | |
$ua->timeout( 5 ); | |
my $res = $ua->head( $url ); | |
return if $res->is_error(); | |
my $permalink = $res->base; | |
if( $permalink =~ m!youtube.com!){ | |
return $permalink; | |
}else{ | |
return; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment