Bump version and update Changes
[www-search-coveralia.git] / lib / WWW / Search / Coveralia / Result / Artist.pm
CommitLineData
a97b490d
MG
1package WWW::Search::Coveralia::Result::Artist;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/WWW::SearchResult/;
7
e8e50668 8our $VERSION = '0.001';
a97b490d
MG
9
10use HTML::TreeBuilder;
11use List::MoreUtils qw/pairwise/;
12use WWW::Search;
13use WWW::Search::Coveralia::Result::Album;
14
15sub new{
16 my ($class, $obj, $id, $name) = @_;
17 my $self = $class->SUPER::new;
18 $self->{id} = $id;
19 $self->{obj} = $obj;
20
21 $self->title($name);
22 $self->add_url("http//www.coveralia.com/autores/$id.php");
23 $self
24}
25
26sub albums{
27 my ($self) = @_;
28 unless ($self->{albums}) {
29 my $id = $self->{id};
30 my $tree = HTML::TreeBuilder->new_from_url("http://www.coveralia.com/caratulas-de/$id.php");
31 my @albums = $tree->look_down(class => 'artista');
32 my @cover_lists = $tree->look_down(class => qr/\blista_normal\b/);
33
34 $self->{albums} = [pairwise {
35 my ($album, $cover_list) = ($a, $b);
36 my ($year) = $album->find('span') && ($album->find('span')->as_text =~ /^\((\d+)/);
37 $year = $year || undef;
38 $album = $album->find('a');
39 my $title = $album->as_text;
40 my $url = $self->{obj}->absurl('', $album->attr('href'));
41 my %covers = map {lc $_->as_text => $self->{obj}->absurl('', $_->attr('href'))} $cover_list->find('a');
42 WWW::Search::Coveralia::Result::Album->new($self->{obj}, $url, $title, $self->title, $year, \%covers);
43 } @albums, @cover_lists];
44 }
45
46 @{$self->{albums}}
47}
48
491;
50__END__
51
52=encoding utf-8
53
54=head1 NAME
55
56WWW::Search::Coveralia::Result::Artist - an artist found by WWW::Search::Coveralia::Artists
57
58=head1 SYNOPSIS
59
60 my $result = $search->next_result;
61 say 'URL: ', $result->url;
62 say 'Name: ', $result->name;
63 my @albums = $result->albums;
64 # @albums is an array of WWW::Search::Coveralia::Result::Album objects
65
66=head1 DESCRIPTION
67
68WWW::Search::Coveralia::Result::Artist is the result of a WWW::Search::Coveralia::Artists search.
69
70Useful methods:
71
72=over
73
74=item B<url>
75
76Returns a link to the artist page on coveralia.
77
78=item B<title>
79
80Returns the name of the artist.
81
82=item B<albums>
83
84Returns a list of albums (L<WWW::Search::Coveralia::Result::Album> objects) belonging to this artist. Calls B<parse_page> if not called already.
85
86=item B<parse_page>
87
88Downloads the covers page and extracts the albums. It is called automatically by B<albums> when necessary.
89
90=back
91
92=head1 SEE ALSO
93
94L<WWW::Search::Coveralia::Artists>
95
96=head1 AUTHOR
97
98Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
99
100=head1 COPYRIGHT AND LICENSE
101
102Copyright (C) 2014 by Marius Gavrilescu
103
104This library is free software; you can redistribute it and/or modify
105it under the same terms as Perl itself, either Perl version 5.18.1 or,
106at your option, any later version of Perl 5 you may have available.
107
108
109=cut
This page took 0.014697 seconds and 4 git commands to generate.