line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Audio-MPD |
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
|
9
|
|
|
9
|
|
270
|
use 5.008; |
|
9
|
|
|
|
|
23
|
|
10
|
9
|
|
|
9
|
|
39
|
use warnings; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
311
|
|
11
|
9
|
|
|
9
|
|
34
|
use strict; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
464
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Audio::MPD::Playlist; |
14
|
|
|
|
|
|
|
# ABSTRACT: class to mess MPD's playlist |
15
|
|
|
|
|
|
|
$Audio::MPD::Playlist::VERSION = '2.004'; |
16
|
9
|
|
|
9
|
|
34
|
use Moose; |
|
9
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
65
|
|
17
|
9
|
|
|
9
|
|
42668
|
use MooseX::Has::Sugar; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
115
|
|
18
|
9
|
|
|
9
|
|
973
|
use MooseX::SemiAffordanceAccessor; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
68
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has _mpd => ( ro, required, weak_ref ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#-- |
24
|
|
|
|
|
|
|
# Constructor |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# my $collection = Audio::MPD::Playlist->new( _mpd => $mpd ); |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# This will create the object, holding a back-reference to the Audio::MPD |
30
|
|
|
|
|
|
|
# object itself (for communication purposes). But in order to play safe and |
31
|
|
|
|
|
|
|
# to free the memory in time, this reference is weakened. |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# Note that you're not supposed to call this constructor yourself, an |
34
|
|
|
|
|
|
|
# Audio::MPD::Playlist is automatically created for you during the creation |
35
|
|
|
|
|
|
|
# of an Audio::MPD object. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#-- |
40
|
|
|
|
|
|
|
# Public methods |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# -- Playlist: retrieving information |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub as_items { |
46
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my @list = $self->_mpd->_cooked_command_as_items("playlistinfo\n"); |
49
|
0
|
|
|
|
|
|
return @list; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub items_changed_since { |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $plid) = @_; |
56
|
0
|
|
|
|
|
|
return $self->_mpd->_cooked_command_as_items("plchanges $plid\n"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# -- Playlist: adding / removing songs |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, @pathes) = @_; |
65
|
|
|
|
|
|
|
my $command = |
66
|
|
|
|
|
|
|
"command_list_begin\n" |
67
|
0
|
|
|
|
|
|
. join( '', map { my $p=$_; $p=~s/"/\\"/g; qq[add "$p"\n] } @pathes ) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
. "command_list_end\n"; |
69
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( $command ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub delete { |
75
|
0
|
|
|
0
|
1
|
|
my ($self, @songs) = @_; |
76
|
|
|
|
|
|
|
my $command = |
77
|
|
|
|
|
|
|
"command_list_begin\n" |
78
|
0
|
|
|
|
|
|
. join( '', map { my $p=$_; $p=~s/"/\\"/g; "delete $p\n" } @songs ) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
. "command_list_end\n"; |
80
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( $command ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub deleteid { |
86
|
0
|
|
|
0
|
1
|
|
my ($self, @songs) = @_; |
87
|
|
|
|
|
|
|
my $command = |
88
|
|
|
|
|
|
|
"command_list_begin\n" |
89
|
0
|
|
|
|
|
|
. join( '', map { "deleteid $_\n" } @songs ) |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
. "command_list_end\n"; |
91
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( $command ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub clear { |
97
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
98
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("clear\n"); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub crop { |
104
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $status = $self->_mpd->status; |
107
|
0
|
|
|
|
|
|
my $cur = $status->song; |
108
|
0
|
|
|
|
|
|
my $len = $status->playlistlength - 1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# we need to reverse the list, to remove the bigest ids before |
111
|
|
|
|
|
|
|
my $command = |
112
|
|
|
|
|
|
|
"command_list_begin\n" |
113
|
0
|
0
|
|
|
|
|
. join( '', map { $_ != $cur ? "delete $_\n" : '' } reverse 0..$len ) |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
. "command_list_end\n"; |
115
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( $command ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# -- Playlist: changing playlist order |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub shuffle { |
124
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
125
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("shuffle\n"); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub swap { |
131
|
0
|
|
|
0
|
1
|
|
my ($self, $from, $to) = @_; |
132
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("swap $from $to\n"); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub swapid { |
138
|
0
|
|
|
0
|
1
|
|
my ($self, $from, $to) = @_; |
139
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("swapid $from $to\n"); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub move { |
145
|
0
|
|
|
0
|
1
|
|
my ($self, $song, $pos) = @_; |
146
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("move $song $pos\n"); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub moveid { |
152
|
0
|
|
|
0
|
1
|
|
my ($self, $song, $pos) = @_; |
153
|
0
|
|
|
|
|
|
$self->_mpd->_send_command("moveid $song $pos\n"); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# -- Playlist: managing playlists |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub load { |
161
|
0
|
|
|
0
|
1
|
|
my ($self, $playlist) = @_; |
162
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( qq[load "$playlist"\n] ); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub save { |
168
|
0
|
|
|
0
|
1
|
|
my ($self, $playlist) = @_; |
169
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( qq[save "$playlist"\n] ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub rm { |
175
|
0
|
|
|
0
|
1
|
|
my ($self, $playlist) = @_; |
176
|
0
|
|
|
|
|
|
$self->_mpd->_send_command( qq[rm "$playlist"\n] ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
9
|
|
|
9
|
|
29093
|
no Moose; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
258
|
|
181
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=pod |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 NAME |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Audio::MPD::Playlist - class to mess MPD's playlist |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 VERSION |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
version 2.004 |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 SYNOPSIS |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
$mpd->playlist->shuffle; |
199
|
|
|
|
|
|
|
# and lots of other methods |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 DESCRIPTION |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L<Audio::MPD::Playlist> is a class meant to access & update MPD's |
204
|
|
|
|
|
|
|
playlist. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Note that you're not supposed to call the constructor yourself, an |
207
|
|
|
|
|
|
|
L<Audio::MPD::Playlist> is automatically created for you during the |
208
|
|
|
|
|
|
|
creation of an L<Audio::MPD> object - it can then be used with the |
209
|
|
|
|
|
|
|
C<playlist()> accessor. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 RETRIEVING INFORMATION |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 as_items |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my @items = $pl->as_items; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Return an array of L<Audio::MPD::Common::Item::Song>s, one for each of the |
218
|
|
|
|
|
|
|
songs in the current playlist. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 items_changed_since |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my @items = $pl->items_changed_since( $plversion ); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Return a list with all the songs (as L<Audio::MPD::Common::Item::Song> objects) |
225
|
|
|
|
|
|
|
added to the playlist since playlist C<$plversion>. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 ADDING / REMOVING SONGS |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 add |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
$pl->add( $path [, $path [...] ] ); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Add the songs identified by C<$path> (relative to MPD's music directory) to the |
234
|
|
|
|
|
|
|
current playlist. No return value. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 delete |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
$pl->delete( $song [, $song [...] ] ); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Remove the specified C<$song> numbers (starting from 0) from the current |
241
|
|
|
|
|
|
|
playlist. No return value. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 deleteid |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$pl->deleteid( $songid [, $songid [...] ] ); |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Remove the specified C<$songid>s (as assigned by mpd when inserted in playlist) |
248
|
|
|
|
|
|
|
from the current playlist. No return value. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 clear |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
$pl->clear; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Remove all the songs from the current playlist. No return value. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 crop |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$pl->crop; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Remove all of the songs from the current playlist B<except> the |
261
|
|
|
|
|
|
|
song currently playing. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 CHANGING PLAYLIST ORDER |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 shuffle |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
$pl->shuffle; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Shuffle the current playlist. No return value. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head2 swap |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
$pl->swap( $song1, $song2 ); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Swap positions of song number C<$song1> and C<$song2> in the current |
276
|
|
|
|
|
|
|
playlist. No return value. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head2 swapid |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$pl->swapid( $songid1, $songid2 ); |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Swap the postions of song ID C<$songid1> with song ID C<$songid2> in the |
283
|
|
|
|
|
|
|
current playlist. No return value. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head2 move |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
$pl->move( $song, $newpos ); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Move song number C<$song> to the position C<$newpos>. No return value. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head2 moveid |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
$pl->moveid( $songid, $newpos ); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Move song ID C<$songid> to the position C<$newpos>. No return value. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 MANAGING PLAYLISTS |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head2 load |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
$pl->load( $playlist ); |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Load list of songs from specified C<$playlist> file. No return value. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head2 save |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
$pl->save( $playlist ); |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Save the current playlist to a file called C<$playlist> in MPD's playlist |
310
|
|
|
|
|
|
|
directory. No return value. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head2 rm |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
$pl->rm( $playlist ); |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Delete playlist named C<$playlist> from MPD's playlist directory. No |
317
|
|
|
|
|
|
|
return value. |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head1 AUTHOR |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Jerome Quelin |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Jerome Quelin. |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
328
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=cut |