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)

In reply to ID3 Tag Tweaker by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.