Parse-M3U-Extended
view release on metacpan or search on metacpan
lib/Parse/M3U/Extended.pm view on Meta::CPAN
{
type => 'item',
value => 'http://example.com/foo.mp3',
}
{
type => 'directive',
tag => 'EXTM3U',
}
{
type => 'directive',
tag => 'EXT-X-ALLOW-CACHE',
value => 'YES',
}
=cut
sub _simple {
my $type = shift;
my $key = shift // 'value';
return sub {{
type => $type,
$key => pop,
}};
}
my @_tests = (
['marker', qr/^#\s*(EXTM3U)\s*$/, _simple('directive', 'tag')],
['directive', qr/^#\s*(EXT[^:]+)(?::(.+))?\s*/, sub {
shift() ? {
type => 'directive',
tag => $_[0],
(defined $_[1] ? (value => $_[1]) : ())
} : _simple('comment')->($_[0] . (defined $_[1] && ":$_[1]"))
}],
['comment', qr/^#(.*)/, _simple('comment')],
['item', qr/(.+)/x, _simple('item')],
);
sub m3u_parser {
my @lines = split /\r?\n/, shift;
my @playlist;
my $m3ue = $lines[0] =~ /^#EXTM3U/;
for my $l (@lines) {
my @match = grep { defined $_->[2] }
map { [$_->[0], $_->[2], $l =~ /$_->[1]/] }
@_tests;
my ($type, $func, @vals) = @{shift @match};
push @playlist, $func->($m3ue, @vals);
}
return @playlist;
}
=head1 SEE ALSO
=over
=item * IETF Internet Draft: draft-pantos-http-live-streaming-08
=back
=head1 COPYRIGHT
Copyright (c) 2012, 2016 - Olof Johansson <olof@cpan.org>
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
1;
( run in 0.557 second using v1.01-cache-2.11-cpan-140bd7fdf52 )