]>
Commit | Line | Data |
---|---|---|
a97b490d MG |
1 | package WWW::Search::Coveralia::Result::Album; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/WWW::SearchResult/; | |
7 | ||
8 | our $VERSION = '0.000_001'; | |
9 | ||
10 | use HTML::TreeBuilder; | |
11 | use PerlX::Maybe; | |
12 | ||
13 | sub artist { shift->_elem(artist => @_) } | |
14 | sub year { shift->_elem(year => @_) } | |
15 | ||
16 | sub 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 | ||
29 | sub 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 | ||
49 | sub covers{ | |
50 | my ($self) = @_; | |
51 | $self->parse_page unless $self->{covers}; | |
52 | %{$self->{covers}} | |
53 | } | |
54 | ||
55 | sub cover{ | |
56 | my ($self, $cover) = @_; | |
57 | $self->parse_page unless $self->{covers}; | |
58 | $self->{covers}{$cover} | |
59 | } | |
60 | ||
61 | sub songs{ | |
62 | my ($self) = @_; | |
63 | $self->parse_page unless $self->{songs}; | |
64 | @{$self->{songs}} | |
65 | } | |
66 | ||
67 | 1; | |
68 | __END__ | |
69 | ||
70 | =encoding utf-8 | |
71 | ||
72 | =head1 NAME | |
73 | ||
74 | WWW::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 | ||
86 | WWW::Search::Coveralia::Result::Album is the result of a WWW::Search::Coveralia::Albums search. | |
87 | ||
88 | Useful methods: | |
89 | ||
90 | =over | |
91 | ||
92 | =item B<url> | |
93 | ||
94 | Returns a link to the album page on coveralia. | |
95 | ||
96 | =item B<title> | |
97 | ||
98 | Returns the name of the album. | |
99 | ||
100 | =item B<artist> | |
101 | ||
102 | Returns the name of the artist of this album. | |
103 | ||
104 | =item B<year> | |
105 | ||
106 | Returns the year when this album was released, or undef if the year is not known. | |
107 | ||
108 | =item B<covers> | |
109 | ||
110 | Returns 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 | ||
112 | Typical keys: | |
113 | ||
114 | =over | |
115 | ||
116 | =item frontal | |
117 | ||
118 | Front cover | |
119 | ||
120 | =item trasera | |
121 | ||
122 | Back cover | |
123 | ||
124 | =item cd/cd1/cd2/dvd/dvd1/dvd2/... | |
125 | ||
126 | CD/DVD art | |
127 | ||
128 | =item interior1 / interior frontal | |
129 | ||
130 | Interior frontal cover. | |
131 | ||
132 | =item interior2 / interior trasera | |
133 | ||
134 | Interior back cover. | |
135 | ||
136 | =back | |
137 | ||
138 | =item B<cover>($type) | |
139 | ||
140 | Convenience 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 | ||
144 | Returns a list of songs in this album. Each song is a hashref with the following keys: | |
145 | ||
146 | =over | |
147 | ||
148 | =item id | |
149 | ||
150 | The track number of this song. | |
151 | ||
152 | =item name | |
153 | ||
154 | The name of this song. | |
155 | ||
156 | =item lyrics | |
157 | ||
158 | Optional. A link to the lyrics of this song. Will likely change for the first stable version. | |
159 | ||
160 | =item video | |
161 | ||
162 | Optional. A link to the music video of this song. Will likely change for the first stable version. | |
163 | ||
164 | =item tab | |
165 | ||
166 | Optional. 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 | ||
172 | Downloads 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 | ||
178 | L<WWW::Search::Coveralia::Albums> | |
179 | ||
180 | =head1 AUTHOR | |
181 | ||
182 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
183 | ||
184 | =head1 COPYRIGHT AND LICENSE | |
185 | ||
186 | Copyright (C) 2014 by Marius Gavrilescu | |
187 | ||
188 | This library is free software; you can redistribute it and/or modify | |
189 | it under the same terms as Perl itself, either Perl version 5.18.1 or, | |
190 | at your option, any later version of Perl 5 you may have available. | |
191 | ||
192 | ||
193 | =cut |