reworked DB::new et al *again*
[id3fs.git] / lib / ID3FS / AudioFile.pm
index 8d86314..cac87d3 100644 (file)
@@ -16,6 +16,7 @@ sub new
     my $path=shift;
     my $ext=($path=~/.*\.(.*)/)[0];
     return undef unless($ext);
+    my $me=shift;
     $ext=lc($ext);
     if($ext eq "mp3")
     {
@@ -31,7 +32,7 @@ sub new
     }
     else
     {
-       print("Unknown extension: $ext\n");
+       print("$me: $path: Unknown extension: $ext\n");
        return undef;
     }
     return $self;
@@ -82,34 +83,26 @@ sub year
 sub tags
 {
     my $self=shift;
-    my @tags=$self->{audiofile}->tags();
-    return({}) unless(@tags);
-    my $tags={};
-    if(@tags)
+    my @intags=$self->{audiofile}->tags();
+    my @outtags=();
+    return() unless(@intags);
+    @intags = grep { defined($_); } @intags;
+    # combine then split on commas
+    # so multiple comma-delimited tags will work
+    @intags=split(/\s*,\s*/, join(', ', @intags));
+    for my $tag (@intags)
     {
-       @tags = grep { defined($_); } @tags;
-       # combine then split on commas
-       # so multiple comma-delimited tags will work
-       @tags=split(/\s*,\s*/, join(', ', @tags));
-       for my $tag (@tags)
+       next unless(length($tag));
+       next unless($tag =~ /\S+/);
+       $tag=$self->sanitise($tag);
+       my ($tagname, $tagval)=($tag, undef);
+       if($tag=~/^([^\/]+)\/(.*)/)
        {
-           next unless(length($tag));
-           next unless($tag =~ /\S+/);
-           $tag=$self->sanitise($tag);
-
-           if($tag=~/([^\/]+)\/(.*)/)
-           {
-               my $tagname = $1;
-               my $tagval  = $self->stripslashes($2);
-               $tags->{$tagname}=$tagval;
-           }
-           else
-           {
-               $tags->{$tag}=undef;
-           }
+           ($tagname, $tagval)=($1, $2);
        }
+       push(@outtags, [ $tagname, $tagval ]);
     }
-    return $tags;
+    return @outtags;
 }
 
 sub sanitise