X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FGrabberBase.pm;h=576d7e487e4c44671c919bd03706a2d2396f6150;hb=09d45a4c4460dce9322f4528dad5123322ab6b38;hp=8ff32b4192f39aaccffb30b31fee95a4e90fd342;hpb=0b7cfa083ea4bfb098647aaa65d79270a11d23c2;p=videosite.git diff --git a/videosite/GrabberBase.pm b/videosite/GrabberBase.pm index 8ff32b4..576d7e4 100644 --- a/videosite/GrabberBase.pm +++ b/videosite/GrabberBase.pm @@ -3,19 +3,20 @@ package videosite::GrabberBase; use videosite::Base; +use MIME::Base64; +use Data::Dumper; @ISA = qw(videosite::Base); use strict; sub new { my $class = shift; - my $self = $class->SUPER::new(); - - $self = {%{$self}, + my $self = $class->SUPER::new( NAME => 'FlashGrab', TYPE => 'grabber', PATTERNS => [], - }; + @_, + ); return bless($self, $class); } @@ -32,7 +33,7 @@ sub get($$) { if ($url =~ m|$pattern|) { $self->debug("Match"); foreach ($self->connectors()) { - $self->debug("Using connector %s", $_->{-name}); + $self->debug("Using connector %s", $_->{'name'}); $self->selectconn($_); $res = $self->_parse($url, $pattern); if (defined($res)) { @@ -40,6 +41,12 @@ sub get($$) { last; } } + if (defined($res)) { + if (defined($self->_cached_ua())) { + $res->{COOKIES} = encode_base64("#LWP-Cookies-1.0\n" . $self->_cached_ua()->cookie_jar->as_string(), ""); + } + } + return wantarray?($res, $pattern):$res; } } @@ -68,4 +75,25 @@ sub _parse { return undef; } +sub _selftest { + my $self = shift; + my $info; + + unless(exists($self->{_SELFTESTURL}) and exists($self->{_SELFTESTTITLE})) { + return 0; + } + + unless(defined($info = $self->get($self->{_SELFTESTURL}))) { + $self->error("Could not get information from %s", $self->{_SELFTESTURL}); + return undef; + } + + unless($info->{TITLE} eq $self->{_SELFTESTTITLE}) { + $self->error("Title from info does not equal expected result (%s != %s)", $info->{TITLE}, $self->{_SELFTESTTITLE}); + return undef; + } + + return 1; +} + 1;