1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for german-bash.org
6 package quotesite::iBashGrabber;
8 use quotesite::GrabberBase;
9 @ISA = qw(quotesite::GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'ibash.de';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*ibash.de/zitat_(\d+)\.html)'];
26 $self->_prepare_parameters();
31 sub __buildquote_line {
37 while ($t = $p->get_tag('td', '/tr')) {
38 if ($t->[0] eq '/tr') {
41 if (exists($t->[1]->{'colspan'})) {
44 $data .= $p->get_text('/td')
49 sub __buildquote_block {
55 while ($t = $p->get_tag('tr','/table')) {
56 if ($t->[0] eq '/table') {
59 $data .= $self->__buildquote_line($p) . "\n";
75 $metadata->{'URL'} = $url;
76 $metadata->{'ID'} = $2;
77 $metadata->{'TYPE'} = 'quote';
78 $metadata->{'SOURCE'} = $self->{'NAME'};
79 $metadata->{'CONTENT'} = undef;
81 # Get the HTML file containing the quote
82 unless(defined($content = LWP::Simple::get(sprintf('http://www.ibash.de/zitat_%s.html', $2)))) {
83 $self->error('Could not download quote');
87 $p = HTML::TokeParser->new(\$content);
89 while ($t = $p->get_tag('td')) {
90 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'quote')) {
91 $metadata->{'CONTENT'} = $self->__buildquote_block($p);
92 Encode::from_to($metadata->{'CONTENT'}, 'iso-8859-1', 'utf8');
96 unless(defined($metadata->{'CONTENT'})) {
97 $self->error('Could not extract quote content');