]>
Commit | Line | Data |
---|---|---|
0feded2e MG |
1 | package Music::Tag::Coveralia; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/Music::Tag::Generic/; | |
7 | ||
bedda035 | 8 | our $VERSION = '0.001'; |
0feded2e | 9 | |
4ef78399 | 10 | use HTTP::Tiny; |
0feded2e MG |
11 | use WWW::Search; |
12 | ||
13 | sub required_values { qw/album/ } | |
14 | sub set_values { qw/picture/ } | |
15 | ||
4ef78399 MG |
16 | my $ht = HTTP::Tiny->new(agent => "Music-Tag-Coveralia/$VERSION"); |
17 | ||
0feded2e MG |
18 | sub get_tag { |
19 | my ($self) = @_; | |
20 | ||
280c0357 | 21 | my $album = $self->info->album; |
0feded2e MG |
22 | my $ws = WWW::Search->new('Coveralia::Albums'); |
23 | $self->status(1, "Searching coveralia for the album $album"); | |
24 | $ws->native_query(WWW::Search::escape_query($album)); | |
25 | while (my $res = $ws->next_result) { | |
26 | $self->status(1, 'Found album ' . $res->title . ' by ' . $res->artist); | |
280c0357 | 27 | next if $self->info->has_data('artist') && $self->info->artist ne $res->artist; |
0feded2e MG |
28 | $self->status(0, 'Selected album ' . $res->title . ' by ' . $res->artist); |
29 | if ($res->cover('frontal')) { | |
4ef78399 MG |
30 | my $resp = $ht->get($res->cover('frontal')); |
31 | last unless $resp->{success}; | |
280c0357 | 32 | $self->info->picture({_Data => $resp->{content}}); |
0feded2e MG |
33 | $self->tagchange('picture'); |
34 | } | |
35 | last | |
36 | } | |
37 | ||
38 | return $self->info | |
39 | } | |
40 | ||
41 | 1; | |
42 | __END__ | |
43 | ||
44 | =encoding utf-8 | |
45 | ||
46 | =head1 NAME | |
47 | ||
48 | Music::Tag::Coveralia - Get cover art from coveralia.com | |
49 | ||
50 | =head1 SYNOPSIS | |
51 | ||
52 | use Music::Tag; | |
53 | my $mt = Music::Tag->new($filename); | |
54 | $mt->add_plugin('Coveralia'); | |
55 | $mt->get_tag; | |
56 | ||
57 | =head1 DESCRIPTION | |
58 | ||
59 | This plugin gets cover art from L<http://coveralia.com>, based on album and (optionally) artist. | |
60 | ||
61 | =head1 REQUIRED DATA VALUES | |
62 | ||
63 | =over | |
64 | ||
65 | =item album | |
66 | ||
67 | Used as the search term. | |
68 | ||
69 | =back | |
70 | ||
71 | =head1 USED DATA VALUES | |
72 | ||
73 | =over | |
74 | ||
75 | =item artist | |
76 | ||
77 | If present, the first album found from this artist is chosen. Otherwise the first album found is chosen. | |
78 | ||
79 | =back | |
80 | ||
81 | =head1 SET DATA VALUES | |
82 | ||
83 | =over | |
84 | ||
85 | =item picture | |
86 | ||
87 | =back | |
88 | ||
89 | =head1 SEE ALSO | |
90 | ||
91 | L<Music::Tag>, L<WWW::Search::Coveralia>, L<http://coveralia.com> | |
92 | ||
93 | =head1 AUTHOR | |
94 | ||
95 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
96 | ||
97 | =head1 COPYRIGHT AND LICENSE | |
98 | ||
bedda035 | 99 | Copyright (C) 2014-2015 by Marius Gavrilescu |
0feded2e MG |
100 | |
101 | This library is free software; you can redistribute it and/or modify | |
102 | it under the same terms as Perl itself, either Perl version 5.20.1 or, | |
103 | at your option, any later version of Perl 5 you may have available. | |
104 | ||
105 | ||
106 | =cut |