Sometimes i find that i need to change an ID3 tag field or more in for a particular MP3 file. This script uses MP3::Info and Getopt::Long to do so. A single array (@fields) is used to hold the names of the fields that can be altered. This same array is used to retrieve the arguments from the command line. Finally, a format is used to pretty print the results (yes, a format).

(update: added flag to prevent setting tag if no args are provided)

use strict; use MP3::Info; use Getopt::Long; use vars qw($tag $value); my %value; my @field = qw(title artist album year comment genre tracknum); @value{@field} = ('') x @field; GetOptions(map { $_.'=s',\$value{$_} } keys %value); my $file = shift or USAGE() and exit; my $tag = get_mp3tag($file) or die "no ID3 tag for '$file'"; my $flag; for (keys %value) { next unless $value{$_}; $tag->{uc $_} = $value{$_}; $flag = 1; } set_mp3tag($file,$tag) if $flag; display_tag($tag); sub display_tag { my %tag = %{+shift}; write while ($tag,$value) = each %tag; } sub USAGE { print "USAGE: $0 [options] file\noptions:\n"; print map { "\t--$_\n" } @field; } format STDOUT = @>>>>>>>>>>: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $tag,$value . __END__ =pod =head1 NAME id3_tweaker.pl - MP3::Info script =head1 DESCRIPTION This is a simple script that uses MP3::Info to alter the a single ID3 tag fields or multiple ID3 tag fields. There is no -help or -h option, just run the script by itself for the USAGE. =head1 SYNOPSIS for *nix: ./id3_tweaker.pl --year='1984' foo.mp3 for win32: perl id3_tweaker.pl --year='1984' foo.mp3 or run with only argument being the file to display info: ./id3_tweaker.pl foo.mp3 retrieve list of tags that can be altered: ./id3_tweaker.pl =cut

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)