Music::Tag::FLAC - Plugin module for Music::Tag to get information from flac headers.


Music-Tag-FLAC documentation Contained in the Music-Tag-FLAC distribution.

Index


Code Index:

NAME

Top

Music::Tag::FLAC - Plugin module for Music::Tag to get information from flac headers.

SYNOPSIS

Top

	use Music::Tag

	my $filename = "/var/lib/music/artist/album/track.flac";

	my $info = Music::Tag->new($filename, { quiet => 1 }, "FLAC");

	$info->get_info();

	print "Artist is ", $info->artist;

DESCRIPTION

Top

Music::Tag::FLAC is used to read flac header information. It uses Audio::FLAC::Header.

REQUIRED DATA VALUES

Top

No values are required (except filename, which is usually provided on object creation).

SET DATA VALUES

Top

title, track, totaltracks, artist, album, comment, releasedate, genre, disc, label

Uses standard tags for these

asin

Uses custom tag "ASIN" for this

mb_artistid, mb_albumid, mb_trackid, mip_puid, countrycode, albumartist

Uses MusicBrainz recommended tags for these.

secs, bitrate

Gathers this info from file. Please note that secs is fractional.

picture

This is currently read-only.

OPTIONS

Top

None currently.

METHODS

Top

default_options()

Returns the default options for the plugin.

set_tag()

Save object back to FLAC header.

get_tag()

Load information from FLAC header.

set_values

A list of values that can be set by this module.

saved_values

A list of values that can be saved by this module.

close()

Close the file and destroy the Audio::FLAC::Header

flac

Returns the Audio::FLAC::Header object

BUGS

Top

Plugin does not fully support all fields I would like. Pictures are read only (limitation of Audio::FLAC::Header).

Please use github for bug tracking: http://github.com/riemann42/Music-Tag-FLAC/issues.

SEE ALSO

Top

Audio::FLAC::Header, Music::Tag, Music::Tag::Amazon, Music::Tag::File, Music::Tag::Lyrics, Music::Tag::M4A, Music::Tag::MP3, Music::Tag::MusicBrainz, Music::Tag::OGG, Music::Tag::Option

SOURCE

Top

Source is available at github: http://github.com/riemann42/Music-Tag-FLAC.

AUTHOR

Top

Edward Allen III <ealleniii _at_ cpan _dot_ org>

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either:

a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or

b) the "Artistic License" which comes with Perl.

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 either the GNU General Public License or the Artistic License for more details.

You should have received a copy of the Artistic License with this Kit, in the file named "Artistic". If not, I'll be glad to provide one.

You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit their web page on the Internet at http://www.gnu.org/copyleft/gpl.html.

COPYRIGHT

Top


Music-Tag-FLAC documentation Contained in the Music-Tag-FLAC distribution.

package Music::Tag::FLAC;
use strict; use warnings; use utf8;
our $VERSION = '0.4101';

# Copyright © 2007,2010 Edward Allen III. Some rights reserved.
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the README file.

use Audio::FLAC::Header;
use base qw(Music::Tag::Generic);

sub flac {
	my $self = shift;
	unless ((exists $self->{_Flac}) && (ref $self->{_Flac})) {
		if ($self->info->has_data('filename')) {
			$self->{_Flac} = Audio::FLAC::Header->new($self->info->get_data('filename'));
		}
	}
	return $self->{_Flac};
}

our %tagmap = (
	TITLE	=> 'title',
	TRACKNUMBER => 'track',
	TRACKTOTAL => 'totaltracks',
	ARTIST => 'artist',
	ALBUM => 'album',
	COMMENT => 'comment',
	DATE => 'releasedate',
	GENRE => 'genre',
	DISC => 'disc',
	LABEL => 'label',
	ASIN => 'asin',
    MUSICBRAINZ_ARTISTID => 'mb_artistid',
    MUSICBRAINZ_ALBUMID => 'mb_albumid',
    MUSICBRAINZ_TRACKID => 'mb_trackid',
    MUSICBRAINZ_SORTNAME => 'sortname',
    RELEASECOUNTRY => 'countrycode',
    MUSICIP_PUID => 'mip_puid',
    MUSICBRAINZ_ALBUMARTIST => 'albumartist'
);

sub set_values {
	return ( values %tagmap, 'picture');
}

sub saved_values {
	return ( values %tagmap);
}
 
sub get_tag {
    my $self     = shift;
    if ( $self->flac ) {
		while (my ($t, $v) = each %{$self->flac->tags}) {
			if ((exists $tagmap{$t}) && (defined $v)) {
				my $method = $tagmap{$t};
				$self->info->set_data($method,$v);
			}
		}
        $self->info->set_data('secs', $self->flac->{trackTotalLengthSeconds} );
        $self->info->set_data('bitrate', int($self->flac->{bitRate} / 1000) );

		#"MIME type"     => The MIME Type of the picture encoding
		#"Picture Type"  => What the picture is off.  Usually set to 'Cover (front)'
		#"Description"   => A short description of the picture
		#"_Data"	       => The binary data for the picture.
        if (( $self->flac->picture) && ( not $self->info->has_data('picture'))) {
			my $pic = $self->flac->picture;
            $self->info->set_data('picture', {
					"MIME type" => $pic->{mimeType},
					"Picture Type" => $pic->{description},
					"_Data"	=> $pic->{imageData},
				});
        }
    }
    return $self;
}

sub set_tag {
    my $self = shift;
    if ( $self->flac ) {
		while (my ($t, $v) = each %tagmap) {
			if ($self->info->has_data($v)) {
				$self->flac->tags->{$t} = $self->info->get_data($v);
			}
		}
        $self->flac->write();
    }
    return $self;
}

sub close {
	my $self = shift;
    $self->{_Flac} = undef;
	delete $self->{_Flac};
}

sub default_options {
   {
   	wav_out_system => [ "flac", "-cd", "-c", "[FILENAME]" ],
   }
}

1;

# vim: tabstop=4
__END__