2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU Library General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
#Copyright 2001 Giuseppe Corbelli - cowo@lugbs.linux.it
17
#builds a list of handlers for all mediafiles in a directory
23
@ISA = qw(mp3handler ogghandler flachandler);
25
use vars qw ( @ext $AUTOLOAD );
27
#These are supported media files. Each time a new one is added
28
#its extension is put here and appropriate handler is instantiated in
29
#MediaHandler constructor.
30
@ext = ('.mp3', '.ogg', '.flac');
32
#2 args: self name and directory name
33
#returns blessed reference
34
#reads all filenames (extensions in @ext) in given directory,
35
#creates an handler for each one and puts istances in $self->{'LIST'}
37
my ($proto, $dirname) = @_;
38
my ($class) = ref($proto)||$proto;
40
my ($filename, $dh, @filelist, $self);
42
$self->{'DIR'} = $dirname;
43
die ("Cannot open directory $dirname\n") if (!opendir (my ($DH), "$dirname"));
44
die ("No write permissions for directory $dirname\n") if (!-w "$dirname");
45
while ($filename = readdir ($DH)) {
46
next if ( (!-r "$dirname/$filename" ) || (-z "$dirname/$filename") || (-d "$dirname/$filename") );
49
if ($filename =~ m/\Q$_\E/i) {
50
push (@filelist, $filename);
55
$self->{'TOTAL'} = $total;
56
@filelist=sort(@filelist);
57
foreach $filename (@filelist) {
58
if ($filename =~ m/\.ogg/i) {
59
push (@{$self->{'LIST'}}, ogghandler->new("$dirname/$filename"));
61
if ($filename =~ m/\.wav/i) {
63
if ($filename =~ m/\.mp3/i) {
64
push (@{$self->{'LIST'}}, mp3handler->new("$dirname/$filename"));
66
if ($filename =~ m/\.flac/i) {
67
push (@{$self->{'LIST'}}, flachandler->new("$dirname/$filename"));
70
bless ($self, $class);
76
return if $AUTOLOAD =~ /::DESTROY$/;
77
$AUTOLOAD =~ s/^.*:://;
78
($AUTOLOAD =~ /^\s*dir\s*$/i) ? $AUTOLOAD = 'DIR' : 1;
79
($AUTOLOAD =~ /^\s*list\s*$/i) ? $AUTOLOAD = 'LIST' : 1;
80
($AUTOLOAD =~ /^\s*total\s*$/i) ? $AUTOLOAD = 'TOTAL' : 1;
81
return ($self->{$AUTOLOAD});