]>
Commit | Line | Data |
---|---|---|
1 | package WWW::Search::Coveralia; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/WWW::Search/; | |
7 | ||
8 | our $VERSION = '0.000_001'; | |
9 | our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>'; | |
10 | ||
11 | sub DEFAULT_URL; | |
12 | sub process_result; | |
13 | ||
14 | sub _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 | ||
24 | sub _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 | ||
46 | 1; | |
47 | __END__ | |
48 | ||
49 | =head1 NAME | |
50 | ||
51 | WWW::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 | ||
62 | WWW::Search::Coveralia is a subclass of WWW::Search that searches the L<http://coveralia.com> cover art website. | |
63 | ||
64 | This 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 | ||
68 | L<http://coveralia.com>, L<WWW::Search>, L<WWW::Search::Coveralia::Artists>, L<WWW::Search::Coveralia::Albums> | |
69 | ||
70 | =head1 AUTHOR | |
71 | ||
72 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
73 | ||
74 | =head1 COPYRIGHT AND LICENSE | |
75 | ||
76 | Copyright (C) 2014 by Marius Gavrilescu | |
77 | ||
78 | This library is free software; you can redistribute it and/or modify | |
79 | it under the same terms as Perl itself, either Perl version 5.18.2 or, | |
80 | at your option, any later version of Perl 5 you may have available. | |
81 | ||
82 | ||
83 | =cut |