#!/usr/bin/perl -w

# pretty-prints Vorbis Comment info from FLAC files

use strict;
use English;
use Audio::FLAC::Header;

use constant LINEWIDTH => 101;
use constant FLACFMT => "%02d | %-30.30s | %-30.30s | %-30.30s\n";

printf FLACFMT, 0, 'Title', 'Artist', 'Album';
printf '-' x LINEWIDTH . "\n";

my ($file, $flac, $track, $song, $artist, $album);

FLACFILE: foreach $file (@ARGV) {

$flac = Audio::FLAC::Header->new($file);
if (not defined $flac) {
	warn "$file: failed to get FLAC header metadata";
	next FLACFILE;
}

$track   = $flac->tags()->{TRACKNUMBER};
$song    = $flac->tags()->{TITLE};
$artist  = $flac->tags()->{ARTIST};
$album   = $flac->tags()->{ALBUM};

$track = 0 if not defined $track;
$song = "<null>" if not defined $song;
$artist = "<null>" if not defined $artist;
$album = "<null>" if not defined $album;

printf FLACFMT, $track, $song, $artist, $album;

}

