|
|
|
@ -35,7 +35,7 @@ sub parse {
|
|
|
|
|
my ($self, $text) = @_; |
|
|
|
|
|
|
|
|
|
my @lines = split /\r?\n/, $text; |
|
|
|
|
$self->{items} = []; |
|
|
|
|
my @items = (); |
|
|
|
|
|
|
|
|
|
# safeguard |
|
|
|
|
return "Not looks like playlist" |
|
|
|
@ -46,8 +46,8 @@ sub parse {
|
|
|
|
|
if ($line =~ m/(File|Title|Length)(\d+)\s*=\s*(.*)/oi) { |
|
|
|
|
my ($key, $num, $value) = (lc($1), $2 - 1, $3); |
|
|
|
|
$value =~ s/(^\s*|\s*$)//og; |
|
|
|
|
$self->{items}->[$num] //= {}; |
|
|
|
|
$self->{items}->[$num]->{$key} = $value; |
|
|
|
|
$items[$num] //= {}; |
|
|
|
|
$items[$num]->{$key} = $value; |
|
|
|
|
next; |
|
|
|
|
} |
|
|
|
|
if ($line =~ m/numberofentries\s*=\s*(\d+)/oi) { |
|
|
|
@ -57,17 +57,17 @@ sub parse {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
warn "Number of entries not matches parsed items" |
|
|
|
|
if ($count != scalar @{$self->{items}}); |
|
|
|
|
if ($count != scalar @items); |
|
|
|
|
|
|
|
|
|
return $self->items; |
|
|
|
|
return wantarray ? @items : [ @items ]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub dump { |
|
|
|
|
my ($self) = @_; |
|
|
|
|
my ($self, @items) = @_; |
|
|
|
|
my $count = 0; |
|
|
|
|
my @lines = ('[playlist]'); |
|
|
|
|
|
|
|
|
|
foreach my $item ($self->items) { |
|
|
|
|
foreach my $item (@items) { |
|
|
|
|
$count += 1; |
|
|
|
|
foreach my $key (qw(file title length)) { |
|
|
|
|
push @lines, sprintf("%s%d=%s", ucfirst($key), $count, $item->{$key}); |
|
|
|
|