1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for german-bash.org
6 package GermanBashGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
19 my $self = $class->SUPER::new();
21 $self->{'NAME'} = 'germanbash';
22 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/(\d+))',
23 '(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/action/show/id/(\d+))'];
26 $self->_prepare_parameters();
43 $metadata->{'URL'} = $url;
44 $metadata->{'ID'} = $2;
45 $metadata->{'TYPE'} = 'quote';
46 $metadata->{'SOURCE'} = $self->{'NAME'};
47 $metadata->{'CONTENT'} = undef;
49 # Get the HTML file containing the quote
50 unless(defined($content = LWP::Simple::get(sprintf('http://german-bash.org/%s', $2)))) {
51 $self->error('Could not download quote');
55 $p = HTML::TokeParser->new(\$content);
57 while ($t = $p->get_tag('div')) {
58 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'zitat')) {
59 $metadata->{'CONTENT'} = $p->get_text('/div');
60 $metadata->{'CONTENT'} =~ s/^\s*//mg;
65 unless(defined($metadata->{'CONTENT'})) {
66 $self->error('Could not extract quote content');