line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Audio-MPD-Common |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2007 by Jerome Quelin. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
1
|
|
|
1
|
|
24
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
11
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Audio::MPD::Common::Item::Song; |
14
|
|
|
|
|
|
|
# ABSTRACT: a song object with some audio tags |
15
|
|
|
|
|
|
|
$Audio::MPD::Common::Item::Song::VERSION = '2.003'; |
16
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
17
|
1
|
|
|
1
|
|
6742
|
use MooseX::Has::Sugar; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
18
|
1
|
|
|
1
|
|
134
|
use MooseX::Types::Moose qw{ Int Str }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
19
|
1
|
|
|
1
|
|
6221
|
use Readonly; |
|
1
|
|
|
|
|
3202
|
|
|
1
|
|
|
|
|
463
|
|
20
|
|
|
|
|
|
|
use String::Formatter method_stringf => { |
21
|
|
|
|
|
|
|
-as => '_stringf', |
22
|
|
|
|
|
|
|
codes => { |
23
|
0
|
|
|
|
|
0
|
A => sub { $_[0]->albumartist }, |
24
|
0
|
|
|
|
|
0
|
a => sub { $_[0]->artist }, |
25
|
0
|
|
|
|
|
0
|
C => sub { $_[0]->composer }, |
26
|
0
|
|
|
|
|
0
|
D => sub { $_[0]->disc }, |
27
|
0
|
|
|
|
|
0
|
d => sub { $_[0]->album }, |
28
|
0
|
|
|
|
|
0
|
f => sub { $_[0]->file }, |
29
|
0
|
|
|
|
|
0
|
g => sub { $_[0]->genre }, |
30
|
0
|
|
|
|
|
0
|
i => sub { $_[0]->id }, |
31
|
1
|
|
|
|
|
49
|
l => sub { $_[0]->time }, |
32
|
0
|
|
|
|
|
0
|
M => sub { $_[0]->date }, |
33
|
0
|
|
|
|
|
0
|
m => sub { $_[0]->last_modified }, |
34
|
0
|
|
|
|
|
0
|
N => sub { $_[0]->name }, |
35
|
0
|
|
|
|
|
0
|
n => sub { $_[0]->track }, |
36
|
0
|
|
|
|
|
0
|
P => sub { $_[0]->performer }, |
37
|
0
|
|
|
|
|
0
|
p => sub { $_[0]->pos }, |
38
|
1
|
|
|
|
|
195
|
t => sub { $_[0]->title }, |
39
|
0
|
|
|
|
|
0
|
s => sub { $_[0]->artistsort }, |
40
|
0
|
|
|
|
|
0
|
S => sub { $_[0]->albumartistsort }, |
41
|
0
|
|
|
|
|
0
|
T => sub { $_[0]->musicbrainz_trackid }, |
42
|
0
|
|
|
|
|
0
|
I => sub { $_[0]->musicbrainz_albumartistid }, |
43
|
0
|
|
|
|
|
0
|
B => sub { $_[0]->musicbrainz_albumid }, |
44
|
0
|
|
|
|
|
0
|
E => sub { $_[0]->musicbrainz_artistid }, |
45
|
|
|
|
|
|
|
}, |
46
|
1
|
|
|
1
|
|
774
|
}; |
|
1
|
|
|
|
|
2835
|
|
|
1
|
|
|
|
|
48
|
|
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
286
|
use base qw{ Audio::MPD::Common::Item }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
49
|
1
|
|
|
1
|
|
6
|
use overload '""' => \&as_string; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Readonly my $SEP => ' = '; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# -- public attributes |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has album => ( rw, isa => Str ); |
58
|
|
|
|
|
|
|
has albumartist => ( rw, isa => Str ); |
59
|
|
|
|
|
|
|
has artist => ( rw, isa => Str ); |
60
|
|
|
|
|
|
|
has composer => ( rw, isa => Str ); |
61
|
|
|
|
|
|
|
has date => ( rw, isa => Str ); |
62
|
|
|
|
|
|
|
has disc => ( rw, isa => Str ); |
63
|
|
|
|
|
|
|
has file => ( rw, isa => Str, required ); |
64
|
|
|
|
|
|
|
has genre => ( rw, isa => Str ); |
65
|
|
|
|
|
|
|
has last_modified => ( rw, isa => Str ); |
66
|
|
|
|
|
|
|
has id => ( rw, isa => Int ); |
67
|
|
|
|
|
|
|
has name => ( rw, isa => Str ); |
68
|
|
|
|
|
|
|
has pos => ( rw, isa => Int ); |
69
|
|
|
|
|
|
|
has performer => ( rw, isa => Str ); |
70
|
|
|
|
|
|
|
has title => ( rw, isa => Str ); |
71
|
|
|
|
|
|
|
has track => ( rw, isa => Str ); |
72
|
|
|
|
|
|
|
has time => ( rw, isa => Int ); |
73
|
|
|
|
|
|
|
has artistsort => ( rw, isa => Str ); |
74
|
|
|
|
|
|
|
has albumartistsort => ( rw, isa => Str ); |
75
|
|
|
|
|
|
|
has musicbrainz_trackid => ( rw, isa => Str ); |
76
|
|
|
|
|
|
|
has musicbrainz_albumartistid => ( rw, isa => Str ); |
77
|
|
|
|
|
|
|
has musicbrainz_albumid => ( rw, isa => Str ); |
78
|
|
|
|
|
|
|
has musicbrainz_artistid => ( rw, isa => Str ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# -- public methods |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub as_string { |
84
|
6
|
|
|
6
|
1
|
36170
|
my ($self, $format) = @_; |
85
|
|
|
|
|
|
|
|
86
|
6
|
100
|
|
|
|
21
|
return _stringf($format, $self) if $format; |
87
|
5
|
100
|
|
|
|
200
|
return $self->file unless defined $self->title; |
88
|
4
|
|
|
|
|
147
|
my $str = $self->title; |
89
|
4
|
100
|
|
|
|
150
|
return $str unless defined $self->artist; |
90
|
3
|
|
|
|
|
109
|
$str = $self->artist . $SEP . $str; |
91
|
3
|
100
|
100
|
|
|
130
|
return $str unless defined $self->album && defined $self->track; |
92
|
1
|
|
|
|
|
39
|
return join $SEP, |
93
|
|
|
|
|
|
|
$self->album, |
94
|
|
|
|
|
|
|
$self->track, |
95
|
|
|
|
|
|
|
$str; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=encoding UTF-8 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Audio::MPD::Common::Item::Song - a song object with some audio tags |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 VERSION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
version 2.003 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<Audio::MPD::Common::Item::Song> is more a placeholder with some |
118
|
|
|
|
|
|
|
attributes. Those attributes are taken from the song tags, so some of |
119
|
|
|
|
|
|
|
them can be empty depending on the file. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The constructor should only be called by L<Audio::MPD::Common::Item>'s |
122
|
|
|
|
|
|
|
constructor. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 album |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Album of the song. (format code: %d) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 artist |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Artist of the song. (format code: %a) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 albumartist |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Artist of the album. (format code: %A) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 composer |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Song composer. (format code: %C) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 date |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Last modification date of the song. (format code: %M) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 disc |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Disc number of the album. This is a string to allow tags such as C<1/2>. |
149
|
|
|
|
|
|
|
(format code: %D) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 file |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Path to the song. Only attribute which will always be defined. (format |
154
|
|
|
|
|
|
|
code: %f) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 genre |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Genre of the song. (format code: %g) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 id |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Id of the song in MPD's database. (format code: %i) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 last_modified |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Last time the song was modified. (format code: %m) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 name |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Name of the song (for http streams). (format code: %N) |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 performer |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Song performer. (format code: %P) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 pos |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Position of the song in the playlist. (format code: %p) |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 title |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Title of the song. (format code: %t) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 track |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Track number of the song. (format code: %n) |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 time |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Length of the song in seconds. (format code: %l) |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 METHODS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 as_string |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
my $str = $song->as_string( [$format] ); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Return a string representing $song. If C<$format> is specified, use it |
199
|
|
|
|
|
|
|
to format the string. Otherwise, the string returned will be: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=over 4 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item either "album = track = artist = title" |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item or "artist = title" |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item or "title" |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item or "file" |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=back |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
(in this order), depending on the existing tags of the song. The last |
214
|
|
|
|
|
|
|
possibility always exist of course, since it's a path. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This method is also used to automatically stringify the C<$song>. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
B<WARNING:> the format codes are not yet definitive and may be subject |
219
|
|
|
|
|
|
|
to change! |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Jerome Quelin |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Jerome Quelin. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
230
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |