File Coverage

blib/lib/Music/Tag/LyricsFetcher.pm
Criterion Covered Total %
statement 23 32 71.8
branch 3 6 50.0
condition 3 9 33.3
subroutine 7 8 87.5
pod 3 3 100.0
total 39 58 67.2


line stmt bran cond sub pod time code
1             package Music::Tag::LyricsFetcher;
2 1     1   7185 use strict; use warnings; use utf8;
  1     1   4  
  1     1   40  
  1         6  
  1         2  
  1         29  
  1         5  
  1         14  
  1         7  
3             our $VERSION = '0.4101';
4              
5             # Copyright © 2008,2010 Edward Allen III. Some rights reserved.
6             #
7             # You may distribute under the terms of either the GNU General Public
8             # License or the Artistic License, as specified in the README file.
9              
10 1     1   1139 use Lyrics::Fetcher;
  1         6544  
  1         143  
11 1     1   14 use base qw(Music::Tag::Generic);
  1         2  
  1         602  
12              
13             sub default_options {{
14 1     1 1 86 'lyricsoverwrite' => 0,
15             'lyricsfetchers' => undef,
16             }}
17              
18             sub get_tag {
19 1     1 1 2363 my $self = shift;
20 1 50 33     4 unless ( $self->info->has_data('artist') && $self->info->has_data('title') ) {
21 0         0 $self->status("Lyrics lookup requires ARTIST and TITLE already set!");
22 0         0 return;
23             }
24 1 50 33     129 if ( $self->info->lyrics && not $self->options->{lyricsoverwrite} ) {
25 0         0 $self->status("Lyrics already in tag");
26             }
27             else {
28 1         25 my $lyrics = Lyrics::Fetcher->fetch($self->info->get_data('artist'), $self->info->get_data('title'), $self->options->{lyricsfetchers});
29 1 50 33     95 if (($Lyrics::Fetcher::Error eq "OK") && ($lyrics)) {
30 0         0 my $lyricsl = $lyrics;
31 0         0 $lyricsl =~ s/[\r\n]+/ \/ /g;
32 0         0 $self->tagchange( "Lyrics", substr( "$lyricsl", 0, 50 ) . "..." );
33 0         0 $self->info->set_data('lyrics',$lyrics);
34 0         0 $self->info->changed(1);
35             }
36             else {
37 1         9 $self->status("Lyrics not found: ", $Lyrics::Fetcher::Error);
38             }
39             }
40 1         26 return $self;
41             }
42              
43             sub set_values {
44 0     0 1   return qw(lyrics);
45             }
46              
47             1;
48              
49             __END__