line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MP3::M3U; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
655
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
407
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
1
|
|
my ($class, $file, $root) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
die "$file doesn't exist" unless -e $file; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $self = {}; |
14
|
0
|
|
|
|
|
|
$self->{_file} = $file; |
15
|
0
|
|
|
|
|
|
$self->{_root} = substr $file, 0, (index $file, '/', 1); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
bless $self, $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub parse { |
23
|
|
|
|
|
|
|
# parse playlist and return arrayref of mp3 filenames |
24
|
|
|
|
|
|
|
# my $path = substring $playlist, 0, (rindex $playlist, "/"); |
25
|
0
|
|
|
0
|
1
|
|
my ($self, $search, $replace) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my @files = (); |
28
|
0
|
0
|
|
|
|
|
open M3U, $self->{_file} or die "Cannnot open $self->{_file}. $!"; |
29
|
0
|
|
|
|
|
|
while() { |
30
|
0
|
0
|
|
|
|
|
next if /^#/; |
31
|
0
|
|
|
|
|
|
chomp; |
32
|
0
|
|
|
|
|
|
s/\r//g; |
33
|
0
|
|
|
|
|
|
s|\\|/|g; # convert "\" to "/" |
34
|
0
|
|
|
|
|
|
my $file = $_; |
35
|
0
|
0
|
0
|
|
|
|
if ( $search and $replace ) { |
36
|
0
|
|
|
|
|
|
$search =~ s|\\|/|g; # convert "\" to "/" |
37
|
0
|
|
|
|
|
|
$replace =~ s|\\|/|g; # convert "\" to "/" |
38
|
0
|
|
|
|
|
|
$file =~ s/$search/$replace/; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
|
|
|
|
if ( !-e $file ) { |
41
|
0
|
|
|
|
|
|
$file = $self->{_root} . $file; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
push @files, $file; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
close M3U; |
46
|
0
|
|
|
|
|
|
return \@files; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |