Browse Source

+ Playlist::PLS->dump

master
Alex 'AdUser' Z 10 years ago
parent
commit
7454241e57
  1. 27
      lib/Playlist/PLS.pm

27
lib/Playlist/PLS.pm

@ -70,4 +70,31 @@ sub load {
return $self->items;
}
sub dump {
my ($self) = @_;
my $count = 0;
my @lines = ('[playlist]');
foreach my $item ($self->items) {
$count += 1;
foreach my $key (qw(file title length)) {
push @lines, sprintf("%s%d=%s", ucfirst($key), $count, $item->{$key});
}
}
splice(@lines, 1, 0, sprintf("numberofentries=%d", $count));
push @lines, "Version=2", "";
return join("\n", @lines);
}
sub save {
my ($self, $file) = @_;
open(my $FH, ">", $file) or die $!;
print $FH $self->dump();
close($FH);
return 1;
}
1;

Loading…
Cancel
Save