X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2FID3FS%2FAudioFile%2FMp3.pm;h=295693b2d044841ecedd84f4f70bcf636a420a8b;hb=f81050374f8c7aa1fa368de2dbdea2db3631188b;hp=d4faf0955d8cd00047788c92e6aa7e6016ecceb2;hpb=718f65e679aed209f98961cbdf655bfed44ca1a4;p=id3fs.git diff --git a/lib/ID3FS/AudioFile/Mp3.pm b/lib/ID3FS/AudioFile/Mp3.pm index d4faf09..295693b 100644 --- a/lib/ID3FS/AudioFile/Mp3.pm +++ b/lib/ID3FS/AudioFile/Mp3.pm @@ -1,3 +1,19 @@ +# id3fs - a FUSE-based filesystem for browsing audio metadata +# Copyright (C) 2010 Ian Beckwith +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + package ID3FS::AudioFile::Mp3; use strict; @@ -14,42 +30,64 @@ sub new $self->{path}=shift; $self->{mp3}=MP3::Tag->new($self->{path}); $self->get_tags(); - $self->{v1}=undef; - $self->{v1}=$self->{mp3}->{ID3v1} if(exists($self->{mp3}->{ID3v1})); - $self->{v2}=undef; - $self->{v2}=$self->{mp3}->{ID3v2} if(exists($self->{mp3}->{ID3v2})); - $self->{tags}={}; return $self; } +sub set +{ + my ($self, $func, $value)=@_; + return $self->choose($func) unless($value); + unless(exists($self->{mp3}->{ID3v1})) + { + $self->{mp3}->new_tag("ID3v1"); + } + unless(exists($self->{mp3}->{ID3v2})) + { + $self->{mp3}->new_tag("ID3v2"); + } + my $method=$func . "_set"; + $self->{mp3}->$method($value, 1); + return $value; +} + sub choose { - my ($self, $func)=@_; + my($self, $func)=@_; my $thing=undef; - if(defined($self->{v2})) + if(exists($self->{mp3}->{ID3v2})) { - $thing=$self->{v2}->$func(); + $thing=$self->{mp3}->{ID3v2}->$func(); } - if(defined($self->{v1}) && (!defined($thing) || !length($thing))) + if(exists($self->{mp3}->{ID3v1}) && (!defined($thing) || !length($thing))) { - $thing=$self->{v1}->$func(); + $thing=$self->{mp3}->{ID3v1}->$func(); } return $thing; } -sub artist { shift->choose("artist"); } -sub album { shift->choose("album"); } -# We don't care if year is not set -sub year { shift->choose("year"); } -sub audiotype { return "mp3"; } -sub haspic { return undef; } # FIXME +sub year { return(shift->set("year", @_)); } +sub artist { return(shift->set("artist", @_)); } +sub album { return(shift->set("album", @_)); } +sub track { return(shift->set("title", @_)); } +sub tracknum { return(shift->set("tracknum", @_)); } +sub comment { return(shift->set("comment", @_)); } + +sub audiotype { return "mp3"; } +sub haspic { return undef; } # NEXTVERSION + sub v1genre { - my($self)=@_; + my($self, $val)=@_; + if($val) + { + $self->{mp3}->new_tag("ID3v1") unless(defined($self->{mp3}->{ID3v1})); + $self->{mp3}->{ID3v1}->genre($val); + return $val; + } my $genre=undef; - $genre=$self->{v1}->genre() if(defined($self->{v1})); + $genre=$self->{ID3v1}->genre() if(defined($self->{ID3v1})); return $genre; } @@ -80,4 +118,10 @@ sub get_tags } } +sub write +{ + my $self=shift; + $self->{mp3}->update_tags(); +} + 1;