From 3ed1591b5189c9fd6474880b50ff9af831df6e16 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Sun, 12 Jun 2011 19:44:50 +0200 Subject: [PATCH] Base, YouTube: Do not use process persistent LWP::UserAgent objects, they accumulate cookies and stop working after a while --- videosite/Base.pm | 8 ++++++-- videosite/YouTubeGrabber.pm | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/videosite/Base.pm b/videosite/Base.pm index 855cb47..67ca218 100644 --- a/videosite/Base.pm +++ b/videosite/Base.pm @@ -12,8 +12,6 @@ sub new { my $class = shift; my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}}; - $self->{_ua} = LWP::UserAgent->new('agent' => 'Mozilla/5.0', 'cookie_jar' => HTTP::Cookies->new); - bless($self, $class); $self->_prepare_parameters(); @@ -174,4 +172,10 @@ sub setdebug { $self->{'_DEBUG'} = shift; } +sub ua { + my $self = shift; + + return LWP::UserAgent->new('agent' => 'Mozilla/5.0', 'cookie_jar' => HTTP::Cookies->new); +} + 1; diff --git a/videosite/YouTubeGrabber.pm b/videosite/YouTubeGrabber.pm index 8073237..ebb2f69 100644 --- a/videosite/YouTubeGrabber.pm +++ b/videosite/YouTubeGrabber.pm @@ -93,7 +93,7 @@ sub _parse_by_video_info { my $quality = $self->_getval('QUALITY'); my $metadata; my $videourl; - my $ua = $self->{_ua}; + my $ua = $self->ua(); my $preflist; my $r; my $content; @@ -166,7 +166,7 @@ sub _parse_by_scrape { my $p; my $e; my $tag; - my $ua = $self->{_ua}; + my $ua = $self->ua(); my $r; my $videourl; my $quality = $self->_getval('QUALITY'); -- 1.8.3.1