54

Anyone know of a command-line* ID3 tool, with support for ID3v2, that you can get working on Mac OS X with reasonable effort? It should support both reading and writing tags.

(* I want to be able to call it e.g. from some Python scripts, so a GUI tool won't do.)

The id3tool utility is otherwise good, but doesn't support ID3v2 (and thus doesn't play that well with iTunes). I had to compile it from source, but that was pretty straightforward on a Mac with Xcode & developer tools (including, notably, a C compiler). Anyway, I'd especially like something with similar command-line options as id3tool. Here's an example of tagging one file:

id3tool -t "Song Title" -r Artist -a "Album Name" -c 2 track-02.mp3
3
  • i've been working on writing something like this... there are some libraries available in python and there is a tool called beets that makes use of them so i've been investigating how it's written. Commented Nov 1, 2010 at 1:59
  • 2
    in addition... MusicBrainz Picard is written in Python and is open source so there's probably a lot to be gleaned from it's code and library usage as well. Commented Nov 1, 2010 at 5:52
  • i agree, Picard is just brilliant Commented Nov 13, 2010 at 9:51

9 Answers 9

64

If you have Homebrew installed (highly recommended), you can just do:

brew install id3lib

This installs several id3 command-line tools, including id3tag, id3convert, id3cp and id3info. No need for python or perl scripting; just use regular shell commands.

Usage: id3tag [OPTIONS]... [FILES]...
   -h         --help            Print help and exit
   -V         --version         Print version and exit
   -1         --v1tag           Render only the id3v1 tag (default=off)
   -2         --v2tag           Render only the id3v2 tag (default=off)
   -aSTRING   --artist=STRING   Set the artist information
   -ASTRING   --album=STRING    Set the album title information
   -sSTRING   --song=STRING     Set the title information
   -cSTRING   --comment=STRING  Set the comment information
   -CSTRING   --desc=STRING     Set the comment description
   -ySTRING   --year=STRING     Set the year
   -tSTRING   --track=STRING    Set the track number
   -TSTRING   --total=STRING    Set the total number of tracks
   -gSHORT    --genre=SHORT     Set the genre
   -w         --warning         Turn on warnings (for debugging) (default=off)
   -n         --notice          Turn on notices (for debugging) (default=off)
12
  • Does it support ID3v2?
    – Jonik
    Commented Jun 19, 2011 at 2:37
  • id3lib also works in other distributions such as macports. Speaking of, is there any point in switching from ports to homebrew? I had so much pain switching from fink...
    – HiQ CJ
    Commented Jul 19, 2011 at 12:12
  • "Error: No available formula for mid3v2". Somebody interested in contributing a formula? Commented Feb 13, 2014 at 12:58
  • 6
    @Jonik id3lib can write and manipulate both ID3v1 and ID3v2
    – jchook
    Commented Jun 3, 2015 at 1:14
  • 3
    It also comes with id3v2, which is the "do-everything" command. It will let you write any arbitrary tag to a file. Commented Sep 2, 2016 at 15:26
14

There's an OS X compatible version of the id3lib library available here on GitHub. It claims to support both ID3v1 and ID3v2.

6
  • 2
    Thanks! This fully answers my question. There was only source package available, but installing from that (on a Mac with developer tools) was pretty smooth: the standard Unix fare of configure, make and make install. id3lib consists of 4 separate binaries: id3info (for reading tags), id3tag (for writing tags), id3convert, and id3cp. Everything works fine (and iTunes honours the v2 tags written with id3tag).
    – Jonik
    Commented Nov 13, 2010 at 11:39
  • @Jonik what did you use to wrap the library? Some python you wrote? Commented Nov 15, 2010 at 5:50
  • @calavera: Yeah, I have simple scripts that try to determine track number or name from a filename (such as "Artist - 03 - Track.mp3"), and if found, write it to ID3 tag too.
    – Jonik
    Commented Nov 15, 2010 at 6:37
  • @Jonk: would you be willing to share? I don't have a lot of experience with python so something like that would be great to play around with and extend... Commented Nov 15, 2010 at 16:01
  • @calavera: Here you go. Usage: add-track-names.py *mp3 or add-track-numbers.py *mp3. Common stuff (most code) is in a separate .py file. I'm not really a Python coder either, so the code's probably far from "pythonic". :) But I (re)learned a lot when I wrote it, and it's probably easy to extend if your tagging needs are anything like mine.
    – Jonik
    Commented Nov 15, 2010 at 20:08
8

The Python module mutagen includes the command-line tool mid3v2 as replacement for id3lib's and supports ID3v2.4.0.

From the usage documentation:

You can set the value for any ID3v2 frame by using '--' and then a frame ID.
For example:
mid3v2 --TIT3 "Monkey!" file.mp3 would set the "Subtitle/Description" frame to "Monkey!".

3
  • 1
    Mutagen can be installed with sudo pip install mutagen after installing pip with sudo easy_install pip.
    – Lri
    Commented Aug 12, 2012 at 17:04
  • you can directly run sudo easy_install mutagen too Commented Sep 3, 2017 at 17:09
  • mutagen's mid3v2 correctly sets Unicode song titles and preserves artwork as expected.
    – Naitree
    Commented May 2, 2021 at 3:56
5

You may want to try id3v2. It's based on the id3lib that Huyz mentioned, but seems to be a better command line tool than those with id3lib. It easily dumps the ID3V2 tags from iTunes produced MP3s, but not iTunes produced M4A files (as with Apple Lossless).

If you need M4A files, another option is ffmpeg. Its ffprobe command line tool prints out metadata in the files and I believe you can write metadata via ffmpeg. It works with both MP3 and M4A files produced by iTunes. ffprobe may not show all metadata; mp4v2 is another good option.

All three programs are easily installed via Homebrew. Right now (Jan 2012) ffmpeg requires gcc to compile, so brew install --use-gcc ffmpeg.

3
  • thanks for suggesting mp4v2 for m4a! works like a charm, whereas id3v2 did not :( Commented Feb 25, 2015 at 19:25
  • mp4v2 is the only one that edited tags in a way that was compatible with iTunes (macOS 10.13, iTunes 12.7). Commented Nov 15, 2017 at 9:27
  • Warning: I've lost track artwork after setting song title using id3v2 and Unicode is not supported.
    – Naitree
    Commented May 2, 2021 at 3:55
5

Having had various 'abort trap' type issues with id3v2 I discovered eyeD3, which is a python module also existing as a command line tool. It seems to be more recently updated than some of the other programs mentioned above.

3

There is always AppleScript. I'm not a big fan of it, but iTunes is scriptable and you can manipulate all the mp3 tags from there. You can invoke Applescript from the command line using osascript.

3

This site: http://dougscripts.com/itunes/ has many good command line scripts and tools that layer on top of itunes to do things with your music library. Some of them may do what you want. Some of the tools are free and some are licensed.

3

since you're comfortable with cli and Python, I can recommend some Perl modules on CPAN. MP3::Tag, (as well as MP3::Tag::ID3v1 and ::ID3v2 and ::Utils), MP3::Info, MP3::ID3Lib are all available for reading and manipulating ID3 tags.

If you go to search.cpan.org and search for "MP3", you'll find a world* of options!

(* Where "world" is a small, limited set of options...)

1
  • 1
    CLI and Python yes, but Perl modules on CPAN... not so much :-) (If you can use those in Python too, I wasn't aware of that. Or did you mean writing Perl instead?) Personally I got this solved already, but maybe this is helpful for others.
    – Jonik
    Commented Nov 15, 2010 at 14:21
2

This old thread at Mac OS X Hints looks like it might be a good place for you to start. It's from 2003, so I'm not sure if the tool they're talking about is still being developed. You also may have to compile it yourself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .