Initial commit
[www-search-coveralia.git] / lib / WWW / Search / Coveralia.pm
CommitLineData
a97b490d
MG
1package WWW::Search::Coveralia;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/WWW::Search/;
7
8our $VERSION = '0.000_001';
9our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>';
10
11sub DEFAULT_URL;
12sub process_result;
13
14sub _native_setup_search{
15 my ($self, $native_query, $options) = @_;
16 $self->agent_email('marius@ieval.ro');
17 $options //= {};
18 my $base_url = $options->{search_url} // $self->DEFAULT_URL;
19 $self->{search_debug} = $options->{search_debug};
20 $self->{_next_url} = "$base_url?bus=$native_query";
21 $self->user_agent->delay(10/60); # Crawl-Delay: 10 in robots.txt
22}
23
24sub _parse_tree {
25 my ($self, $tree) = @_;
26 my $found = 0;
27
28 my $result_table = $tree->look_down(class => 'mostrar');
29 return unless $result_table;
30 my @results = $result_table->find('tbody')->find('tr');
31 for (@results) {
32 my $result = $self->process_result($_);
33 push @{$self->{cache}}, $result;
34 say STDERR 'Title: ', $result->title, ' URL: ', $result->url if $self->{search_debug};
35 $found++;
36 }
37
38 my $url = $tree->look_down(rel => 'next');
39 $self->{_next_url} = $self->absurl($self->{_prev_url}, $url->attr('href')) if defined $url;
40
41 say STDERR "Found: $found" if $self->{search_debug};
42 say STDERR 'Next URL: ', $self->{_next_url} if $self->{search_debug} && $self->{_next_url};
43 $found
44}
45
461;
47__END__
48
49=head1 NAME
50
51WWW::Search::Coveralia - search coveralia.com with WWW::Search
52
53=head1 SYNOPSIS
54
55 use WWW::Search;
56 my $search = WWW::Search->new('Coveralia::Artists'); # or Coveralia::Albums
57 $search->native_query('query');
58 # see WWW::Search documentation for details
59
60=head1 DESCRIPTION
61
62WWW::Search::Coveralia is a subclass of WWW::Search that searches the L<http://coveralia.com> cover art website.
63
64This module is the backend for L<WWW::Search::Coveralia::Artists> and L<WWW::Search::Coveralia::Albums> and should not be used directly. Read the documentation of those two modules for usage information.
65
66=head1 SEE ALSO
67
68L<http://coveralia.com>, L<WWW::Search>, L<WWW::Search::Coveralia::Artists>, L<WWW::Search::Coveralia::Albums>
69
70=head1 AUTHOR
71
72Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
73
74=head1 COPYRIGHT AND LICENSE
75
76Copyright (C) 2014 by Marius Gavrilescu
77
78This library is free software; you can redistribute it and/or modify
79it under the same terms as Perl itself, either Perl version 5.18.2 or,
80at your option, any later version of Perl 5 you may have available.
81
82
83=cut
This page took 0.012485 seconds and 4 git commands to generate.