|
|
|
@ -80,4 +80,39 @@ sub _parse_attrs {
|
|
|
|
|
return \%attrs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub _dump_attrs { |
|
|
|
|
my ($self, $attrs) = @_; |
|
|
|
|
my @parts = (''); |
|
|
|
|
|
|
|
|
|
while (my ($key, $value) = each %{$attrs}) { |
|
|
|
|
push @parts, sprintf("%s=%s", $key, $value); |
|
|
|
|
} |
|
|
|
|
return @parts ? join(" ", @parts) : ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub dump { |
|
|
|
|
my ($self) = @_; |
|
|
|
|
my @lines = (); |
|
|
|
|
push @lines, sprintf('#EXTM3U%s', $self->_dump_attrs($self->{attrs})); |
|
|
|
|
|
|
|
|
|
foreach my $item ($self->items) { |
|
|
|
|
push @lines, sprintf("#EXTINF:%s%s,%s", $item->{duration}, |
|
|
|
|
$self->_dump_attrs($item->{attrs}), $item->{title}); |
|
|
|
|
push @lines, $item->{file}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
push @lines, ''; |
|
|
|
|
return join("\n", @lines); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub save { |
|
|
|
|
my ($self, $file) = @_; |
|
|
|
|
|
|
|
|
|
open(my $FH, ">", $file) or die $!; |
|
|
|
|
print $FH $self->dump(); |
|
|
|
|
close($FH); |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|