The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

mp3info2 - get/set MP3 tags; uses MP3::Tag to get default values.

SYNOPSIS

  # Print the information in tags and autodeduced info
  mp3info2 *.mp3

  # In addition, set the year field to 1981
  mp3info2 -y 1981 *.mp3

  # Same without printout of information
  mp3info2 -p "" -y 1981 *.mp3

  # Do not deduce any field, print the info from the tags only
  mp3info2 -C autoinfo=ID3v2,ID3v1 *.mp3

  # Get the artist from CDDB_File, autodeduce other info, write it to tags
  mp3info2 -C artist=CDDB_File -u *.mp3

  # For the title, prefer information from .inf file; autodeduce and update
  mp3info2 -C title=Inf,ID3v2,ID3v1,filename -u *.mp3

  # Same, and get the author from CDDB file
  mp3info2 -C "#title=Inf,ID3v2,ID3v1,filename#artist=CDDB_File" -u *.mp3

  # Write a script for conversion of .wav to .mp3 autodeducing tags
  mp3info2 -p "lame -h --vbr-new --tt '%t' --tn %n --ta '%a' --tc '%c' --tl '%l' --ty '%y' '%f'\n" *.wav >xxx.sh

DESCRIPTION

The program prints a message summarizing tag info (obtained via MP3::Tag module) for specified files.

It may also update the information in MP3 tags. This happens in two different cases.

  • If the information supplied in command-line options differs from the content of the corresponding ID3 tags (or there is no corresponding ID3 tags).

  • if MP3::Tag obtains the info from other means than MP3 tags, and -u forces the update of the ID3 tags.

(Both ways are disabled by -D option.) ID3v2 tag is written if needed.

The option -C sets MP3::Tag configuration data (separated by commas; the first comma can be replaced by = sign) as MP3::Tag->config() would do. (To call config() multiple times, separate the parts by arbitrary non-alphanumeric character, and repeat this character in the start of -C option.) Note that since ParseData is used to inject the user-specified tag fields (such as -a "A. U. Thor"), usually it should be kept in the autoinfo configuration (and related fields author etc).

The option -u writes (updates) the fetched information to the MP3 ID3 tags. This option is assumed if tag elements are set via command-line options. (This option is overwritten by -D option.)

The option -p prints a message using the next argument as format (by default \\, \t, \n are replaced by backslash, tab and newline; governed by the value of -E option); see "interpolate" in MP3::Tag for details of the format of sprintf()-like escapes.

With option -D (dry run) no update is performed.

Use options

  t a l y g c n

to overwrite the information (title artist album year genre comment track-number) obtained via MP3::Tag heuristics (-u switch is implied if any one of these arguments differs from what would be found otherwise; use -D switch to disable auto-update).

The option -P should contain the parse recipes. They become the configuration item parse_data of MP3::Tag; eventually this information is processed by MP3::Tag::ParseData module. The option is split into [$flag, $string, @patterns] on its first non-alphanumeric character; if multiple options are needed, one should separate them by this character repeated 3 times. This data is processed by MP3::Tag::ParseData (if present in the chain of heuristics).

If option -G is specified, the file names on the command line are considered as glob patterns. This may be useful if the maximal command-line length is too low).

The option -E should contain the letters of the options where \\, \n, \t are interpolated (default: p). If the option -@ is given, all characters @ in the options are replaced by %; this may be convenient if the shell treats % specially.

Extra translation

If a module Music_Translate_Fields is available, it is loaded. It may defined methods translate_artist etc which would be used by MP3::Tag.

EXAMPLES

Only the -P option is complicated enough to deserve comments...

For a (silly) example, one can replace -a Homer -t Iliad by

  -P mz=Homer=%a===mz=Iliad=%t

A less silly example is forcing a particular way of parsing a file name via

  -P "im=%{d0}/%f=%a/%n %t.%e"

This interpolates the string "%{d0}/%f" and parses the result (which is the file name with one level of the directory part preserved) using the pattern "%a/%n %t.%e"; thus the directory name becomes author, the leading numeric part - the track number, and the rest of the file name (without extension) - the title. Note that since multiple patterns are allowed, one can similarly allow for multiple formats of the names, e.g.

  -P "im=%{d0}/%f=%a/%n %t.%e=%a/%t (%y).%e"

allows for the file basename to be also of the form "TITLE (YEAR)". To give more examples,

  -P "if=%D/.comment=%c"

will read comment from the file .comment in the directory of the audio file;

  -P "ifn=%D/.comment=%c"

has similar effect if the file .comment has one-line comments, one per track (this assumes the the track number can be found by other means).

Suppose that a file Parts in a directory of MP3 files has the following format: it has a preamble, then has a short paragraph of information per audio file, preceeded by the track number and dot:

   ...

   12. Rezitativ.
   (Pizarro, Rocco)

   13. Duett: jetzt, Alter, jetzt hat es Eile, (Pizarro, Rocco)

   ...

The following command puts this info into the title of the ID3 tag (provided the audio file names are informative enough so that MP3::Tag can deduce the track number):

 mp3info2 -u -C parse_split='\n(?=\d+\.)' -P 'fl;Parts;%=n. %t'

If this paragraph of information has the form TITLE (COMMENT) with the COMMENT part being optional, then use

 mp3info2 -u -C parse_split='\n(?=\d+\.)' -P 'fl;Parts;%=n. %t (%c);%=n. %t'

If you want to remove a dot or a comma got into the end of the title, use

 mp3info2 -u -C parse_split='\n(?=\d+\.)' \
   -P 'fl;Parts;%=n. %t (%c);%=n. %t;;;iR;%t;%t[.,]$'

The second pattern of this invocation is converted to

  ['iR', '%t' => '%t[.,]$']

which essentially matches the title vs the substitution s/(.*)[.,]$/$1/s.

Now suppose that in addition to Parts, we have a text file Comment with additional info; we want to put this info into the comment field after what is extracted from TITLE (COMMENT); separate these two parts of the comment by an empty line:

 mp3info2 -E C -C '#parse_split=\n(?=\d+\.)#parse_join=\n\n' \
  -P 'f;Comment;%c;;;fl;Parts;%=n. %t;;;i;%t///%c;%t (%c)///%c;;;iR;%t;%t[.,]$'

This assumes that the title and the comment do not contain '///' as a substring. Explanation: the first pattern of -P reads comment from the file Comment into the comment field; the second reads a chunk of Parts into the title field. The third one

  ['i', '%t///%c' => '%t (%c)///%c']

rearranges the title and comment provided the title is of the form TITLE (COMMENT). (The configuration option parse_join takes care of separating two chunks of comment corresponding to two occurences of %c on the right hand side.)

Finally, the fourth pattern is the same as in the preceeding example; it removes spurious punctuation at the end of the title.

  mp3info2 -u -P 'i;%c///with piano;///%c' *.mp3
  mp3info2 -u -P 'iz;%c;with piano%c' *.mp3
  mp3info2 -C autoinfo=ParseData -a "A. U. Thor" *.mp3

Finish by a very simple example: all that the pattern

  -P 'i;%t;%t'

does is removal of trailing and leading blanks from the title (deduced by other means).

AUTHOR

Ilya Zakharevich <cpan@ilyaz.org>.

SEE ALSO

MP3::Tag, MP3::Tag::ParseData