| 1 | package App::xspf2m3u::Command::convert; | ||
| 2 | $App::xspf2m3u::Command::convert::VERSION = '0.2.0'; | ||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use autodie; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use 5.016; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use Path::Tiny qw/ path /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | ▶ | use App::xspf2m3u -command; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 0 | ▶ | use XML::XSPF (); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 12 | |||
| 13 | { | ||
| 14 | no warnings 'redefine'; | ||
| 15 | *XML::XSPF::_isValidURI = sub { return 1; }; | ||
| 16 | } | ||
| 17 | sub abstract { "convert .xspf playlists to .m3u ones" } | ||
| 18 | |||
| 19 | sub description { return abstract(); } | ||
| 20 | |||
| 21 | sub opt_spec | ||
| 22 | { | ||
| 23 | return ( [ "output|o=s", "Output path" ], ); | ||
| 24 | } | ||
| 25 | |||
| 26 | sub validate_args | ||
| 27 | { | ||
| 28 | my ( $self, $opt, $args ) = @_; | ||
| 29 | |||
| 30 | $self->usage_error("args required") if not @$args; | ||
| 31 | if (0) | ||
| 32 | { | ||
| 33 | $self->usage_error("can only accept one path") if @$args != 1; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | sub execute | ||
| 38 | { | ||
| 39 | my ( $self, $opt, $args ) = @_; | ||
| 40 | |||
| 41 | my $text = ''; | ||
| 42 | foreach my $fn (@$args) | ||
| 43 | { | ||
| 44 | my $playlist = XML::XSPF->parse($fn); | ||
| 45 | |||
| 46 | foreach my $track ( $playlist->trackList ) | ||
| 47 | { | ||
| 48 | if ( my $loc = $track->location ) | ||
| 49 | { | ||
| 50 | if ( $loc =~ /[\n\r]/ ) | ||
| 51 | { | ||
| 52 | die "Invalid newline in location <<$loc>>!"; | ||
| 53 | } | ||
| 54 | $text .= "$loc\n"; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | path( $opt->{output} )->spew_utf8($text); | ||
| 59 | |||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ | ||