Bump version and update Changes
[www-search-coveralia.git] / lib / WWW / Search / Coveralia / Result / Album.pm
CommitLineData
a97b490d
MG
1package WWW::Search::Coveralia::Result::Album;
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 PerlX::Maybe;
12
13sub artist { shift->_elem(artist => @_) }
14sub year { shift->_elem(year => @_) }
15
16sub new{
17 my ($class, $obj, $url, $title, $artist, $year, $covers) = @_;
18 my $self = $class->SUPER::new;
19 $self->{obj} = $obj;
20 $self->{covers} = $covers if $covers;
21
22 $self->title($title);
23 $self->artist($artist);
24 $self->year($year);
25 $self->add_url($url);
26 $self
27}
28
29sub parse_page{
30 my ($self) = @_;
31 my $tree = HTML::TreeBuilder->new_from_url($self->url);
32 my $cover_list = $tree->look_down(class => 'lista_normal');
33 my @covers = grep { ($_->find('img')->attr('class') // '') ne 'sprites_enviax' } $cover_list->find('a');
34 $self->{covers} = {map {lc $_->as_text => $self->{obj}->absurl('', $_->attr('href'))} @covers};
35 my @songs = $tree->look_down(id => 'pagina_disco_lista')->find('tr');
36 $self->{songs} = [map {
37 my ($nr, $title, @extra) = $_->find('td');
38 my %ret = (id => $nr->as_text, name => $title->as_text);
39 for (@extra) {
40 next if ($_->attr('class') // '') eq 'letrano';
41 $ret{lyrics} = $self->{obj}->absurl('', $_->find('a')->attr('href')) if $_->as_text =~ /letra/i;
42 $ret{video} = $self->{obj}->absurl('', $_->find('a')->attr('href')) if $_->as_text =~ /video/i;
43 $ret{tab} = $self->{obj}->absurl('', $_->find('a')->attr('href')) if $_->as_text =~ /acorde/i;
44 }
45 \%ret
46 } @songs]
47}
48
49sub covers{
50 my ($self) = @_;
51 $self->parse_page unless $self->{covers};
52 %{$self->{covers}}
53}
54
55sub cover{
56 my ($self, $cover) = @_;
57 $self->parse_page unless $self->{covers};
58 $self->{covers}{$cover}
59}
60
61sub songs{
62 my ($self) = @_;
63 $self->parse_page unless $self->{songs};
64 @{$self->{songs}}
65}
66
671;
68__END__
69
70=encoding utf-8
71
72=head1 NAME
73
74WWW::Search::Coveralia::Result::Album - an album found by WWW::Search::Coveralia::Albums
75
76=head1 SYNOPSIS
77
78 my $result = $search->next_result;
79 say 'URL: ', $result->url;
80 say 'Name: ', $result->name;
81 my @albums = $result->albums;
82 # @albums is an array of WWW::Search::Coveralia::Result::Album objects
83
84=head1 DESCRIPTION
85
86WWW::Search::Coveralia::Result::Album is the result of a WWW::Search::Coveralia::Albums search.
87
88Useful methods:
89
90=over
91
92=item B<url>
93
94Returns a link to the album page on coveralia.
95
96=item B<title>
97
98Returns the name of the album.
99
100=item B<artist>
101
102Returns the name of the artist of this album.
103
104=item B<year>
105
106Returns the year when this album was released, or undef if the year is not known.
107
108=item B<covers>
109
110Returns a hash of cover art, with the kind of cover art as key and the link to the cover art page as value. This will change for the first stable version.
111
112Typical keys:
113
114=over
115
116=item frontal
117
118Front cover
119
120=item trasera
121
122Back cover
123
124=item cd/cd1/cd2/dvd/dvd1/dvd2/...
125
126CD/DVD art
127
128=item interior1 / interior frontal
129
130Interior frontal cover.
131
132=item interior2 / interior trasera
133
134Interior back cover.
135
136=back
137
138=item B<cover>($type)
139
140Convenience method. Returns a link to the cover art of a particular type. This will change for the first stable version.
141
142=item B<songs>
143
144Returns a list of songs in this album. Each song is a hashref with the following keys:
145
146=over
147
148=item id
149
150The track number of this song.
151
152=item name
153
154The name of this song.
155
156=item lyrics
157
158Optional. A link to the lyrics of this song. Will likely change for the first stable version.
159
160=item video
161
162Optional. A link to the music video of this song. Will likely change for the first stable version.
163
164=item tab
165
166Optional. A link to the tab of this song. Will likely change for the first stable version.
167
168=back
169
170=item B<parse_page>
171
172Downloads the covers page and extracts the albums. It is called automatically by other methods when necessary.
173
174=back
175
176=head1 SEE ALSO
177
178L<WWW::Search::Coveralia::Albums>
179
180=head1 AUTHOR
181
182Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
183
184=head1 COPYRIGHT AND LICENSE
185
186Copyright (C) 2014 by Marius Gavrilescu
187
188This library is free software; you can redistribute it and/or modify
189it under the same terms as Perl itself, either Perl version 5.18.1 or,
190at your option, any later version of Perl 5 you may have available.
191
192
193=cut
This page took 0.019992 seconds and 4 git commands to generate.