]>
Commit | Line | Data |
---|---|---|
a97b490d MG |
1 | package WWW::Search::Coveralia::Result::Artist; |
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 List::MoreUtils qw/pairwise/; | |
12 | use WWW::Search; | |
13 | use WWW::Search::Coveralia::Result::Album; | |
14 | ||
15 | sub 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 | ||
26 | sub 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 | ||
49 | 1; | |
50 | __END__ | |
51 | ||
52 | =encoding utf-8 | |
53 | ||
54 | =head1 NAME | |
55 | ||
56 | WWW::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 | ||
68 | WWW::Search::Coveralia::Result::Artist is the result of a WWW::Search::Coveralia::Artists search. | |
69 | ||
70 | Useful methods: | |
71 | ||
72 | =over | |
73 | ||
74 | =item B<url> | |
75 | ||
76 | Returns a link to the artist page on coveralia. | |
77 | ||
78 | =item B<title> | |
79 | ||
80 | Returns the name of the artist. | |
81 | ||
82 | =item B<albums> | |
83 | ||
84 | Returns 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 | ||
88 | Downloads 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 | ||
94 | L<WWW::Search::Coveralia::Artists> | |
95 | ||
96 | =head1 AUTHOR | |
97 | ||
98 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
99 | ||
100 | =head1 COPYRIGHT AND LICENSE | |
101 | ||
102 | Copyright (C) 2014 by Marius Gavrilescu | |
103 | ||
104 | This library is free software; you can redistribute it and/or modify | |
105 | it under the same terms as Perl itself, either Perl version 5.18.1 or, | |
106 | at your option, any later version of Perl 5 you may have available. | |
107 | ||
108 | ||
109 | =cut |