AudioFile-Info
view release on metacpan or search on metacpan
lib/AudioFile/Info.pm view on Meta::CPAN
'Artist: ', $song->artist, "\n".
'Album: ', $song->album, "\n",
'Track: ', $song->track, "\n";
'Year: ', $song->year, "\n",
'Genre: ', $song->genre, "\n";
Currently you can access the title, artist, album, track number, year
and genre of the file.
With certain plugins (see below for a description of plugins) you can
now write data back to the file. This is as simple as passing a new string
to the accessor function.
$song->title('something new');
=head2 AudioFile::Info Plugins
AudioFile::Info is simply a wrapper around various other modules which
read and write MP3 and Ogg Vorbis files. It makes use of these modules
by using plugin modules which act as an interface between
AudioFile::Info and the other modules. AudioFile::Info is pretty much
useless without at least one these plugins installed.
Each time you install a plugin, AudioFile::Info notes how it compares
with other installed plugins. It then works out how which of your
installed plugins is best for handling the various types of audio
files. When you use the module to read a file it will use the
"best" plugin for the file type.
You can override this behaviour and tell it to use a particular
plugin by using an extended version of the C<new> method.
C<new> takes an optional argument which is a reference to a hash
that contains details of which plugin to use for each file type.
You use it like this.
my $song = AudioFile::Info->new($file,
{ mp3 => 'AudioFile::Info::MP3::Info' });
In this case, if C<$file> is the name of an MP3 file then
AudioFile::Info will use C<AudioFile::Info::MP3::Info> to handle it
rather than the default MP3 plugin. If C<$file> contains the name
of an Ogg Vorbis file then the default Ogg Vorbis plugin will still
be used. You can change the Ogg Vorbis plugin by using the C<ogg>
key in the optional hash.
Currently plugins are available for the following modules.
=over 4
=item *
MP3::ID3Lib
=item *
MP3::Info
=item *
MP3::Tag
=item *
Ogg::Vorbis::Header
=item *
Ogg::Vorbis::Header::PurePerl
=back
Plugins for other modules may appear in the future. Let me know if you
want a plugin that doesn't already exist.
=cut
package AudioFile::Info;
use 5.006;
use strict;
use warnings;
use Carp;
use YAML 'LoadFile';
our $VERSION = '2.0.2';
=head1 METHODS
=head2 AudioFile::Info->new(FILE, [\%OPTIONS])
Constructor method which returns a new Audio::File::Info object. Well,
actually it returns an instance of one of the AudioFile::Info plugin
objects, but for the average user the difference is largely academic.
Takes one mandatory argument, which is a full local path to an audio
file, and an optional reference to a hash containing options.
Currently the only options the method understands are 'mp3' or 'ogg'.
The corresponding values for these keys is the name of a plugin module
to use to process files of that type. This will override the default
plugin which AudioFile::Info will choose for itself from the installed
plugins.
=cut
sub new {
my $class = shift;
my $file = shift or die "No music file given.";
my $param = shift || {};
my $path = $INC{'AudioFile/Info.pm'};
$path =~ s/Info.pm$/plugins.yaml/;
my ($ext) = $file =~ /\.(\w+)$/;
die "Can't work out the type of the file $file\n"
unless defined $ext;
( run in 1.073 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )