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