MP3::InfoTag - functions working on ID3 tags
use MP3::Info; use MP3::InfoTag ':typical';
my $tag = get_mp3tag($file, 1) || createNewTag();
print("file '$file': current ID3 tag: ".printTag($tag));
# write tag fields based on a given string; for better understanding
# a specific string is used here instead of a variable. All of these
# tag fields will be lower case because of the `case => 0' argument.
my $changed = string2tag(
{ name => '[02] Iron Maiden - Rainmaker',
pattern => '[((TRACKNUM))] ((ARTIST)) - ((TITLE))',
tag => $tag,
case => 0
} );
# let's be control freaks and look for warnings
if (my @warnings = MP3::InfoTag::flushWarnings()) {
print("Warning for file '$file': ".join('; ', @warnings));
}
# write changes to file if necessary
if (!defined $changed) {
print("file '$file': string2tag failed: ".MP3::InfoTag::getError());
} elsif ($changed > 0) {
set_mp3tag($file, $tag);
}
This module contains functions for several tasks that occur while working with ID3 tags of MP3 files.
The functions of this module work with a hash representing the ID3 tag, they do
not manipulate any files.
This module has a tight relationship to the MP3::Info module which uses the
same hash structure.
You'll need to read tags from files and write them to files; for these tasks
MP3::Info provides the necessary operations.
Thus you should regard this module as an extension that provides some functions which might be useful when working with ID3 tags.
By default this module does not export any functions into the caller's
namespace.
Anyway, you can export all functions on demand.
For convenience, you may use the keyword ':typical' (see SYNOPSIS)
to export he most important functions, i.e. all functions except of
flushWarnings and getError.
There are two major types of MPEG Layer 3 tag formats, ID3v1 and
ID3v2. Whenever the `ID3 tag' is mentioned in this manual you can
substitute this with ID3v1 or more specifically ID3v1.1 if the
TRACKNUM field is used. ID3v2 tags are not supported.
tag. Empty fields will be
suppressed unless showEmpty is set to a true value.
Returns the string representation.
field of the given tag to value.
Given values are thoroughly checked for validity and, if necessary, warning or
error messages are produced.
Returns undef if an error occured, true otherwise.
Returns the number of changed tag fields or undef if an error occured.
These are the valid hash entries of args:
tag.
Usually this will be a filename.
pattern defines the format of str by placeholders which indicate the
position of the information to be extracted.
These placeholders have the form ((FIELD)) where FIELD stands for the name
of a tag field.
The name `IGNORE' is also accepted and results in dropping the corresponding
part of str instead of writing it to a tag field.
tag can be an empty tag (see createNewTag) but it is also allowed
to contain values. Some of these will be overwritten as soon as the appropriate
information is extracted from str.
0 all characters in lower case 1 Capitalize the first character, the rest will be lower case 2 Capitalize The First Character Of Each Word, Even_This-Way
Returns undef if an error occured, true otherwise.
These are the valid hash entries of args:
tag can be an empty tag (see createNewTag) but it is also allowed
to contain values. Some of these will be overwritten as soon as the appropriate
information is extracted from name.
str is an in/out argument.
When this function is called str must contain the pattern mentioned above.
When this function has finished str will contain the
same string but all placeholders like ((TITLE)) will be replaced by the
corresponding tag field's value.
str) is converted according to one of the following modes:
0 all characters in lower case 1 Capitalize the first character, the rest will be lower case 2 Capitalize The First Character Of Each Word, Even_This-Way
MP3::Info
Joachim Jautz
http://www.jay-jay.net/contact.html
Copyright (c) 2004 Joachim Jautz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License, distributed with Perl.