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
hairboat
  • 2,903
  • 18
  • 51
  • 72
Jonik
  • 6,673
  • 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. – Robert S Ciaccio Nov 01 '10 at 01: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. – Robert S Ciaccio Nov 01 '10 at 05:52
  • i agree, Picard is just brilliant – Rohan Monga Nov 13 '10 at 09:51

9 Answers9

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)
Glorfindel
  • 4,057
huyz
  • 758
  • Does it support ID3v2? – Jonik Jun 19 '11 at 02: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 Jul 19 '11 at 12:12
  • "Error: No available formula for mid3v2". Somebody interested in contributing a formula? – ManuelSchneid3r Feb 13 '14 at 12:58
  • 5
    @Jonik id3lib can write and manipulate both ID3v1 and ID3v2 – jchook Jun 03 '15 at 01:14
  • 2
    It also comes with id3v2, which is the "do-everything" command. It will let you write any arbitrary tag to a file. – Edward Falk Sep 02 '16 at 15:26
  • Re: MacPorts vs Homebrew. I actually have both (they don't get in each other's way.) Homebrew is definitely the way to go if you can. Macports is massive, prefers to use its own libraries, and will download and compile whatever it needs. Homebrew is much smaller and simpler, and (AFAIK) only works with pre-built binaries. It uses the libraries already on the Mac whenever possible. Supposedly Homebrew has less available software, but it hasn't failed me yet. – Edward Falk Sep 02 '16 at 15:29
  • So my experience was this: I used Macports to install Imagemagick and it spent fifteen minutes downloading and compiling things and in the end the executable wouldn't run because of some missing dependency. Homebrew downloaded a ready-run binary in two minutes and I was good to go. – Edward Falk Sep 02 '16 at 15:30
  • @EdwardFalk: brew install id3lib (at least today) does not install id3v2 but brew install id3v2 works. Unfortunately, the man page is inadequate. --help is also inadequate but at least it doesn't omit the - and -- from the options. – WGroleau Jul 30 '20 at 17:30
  • In all honesty, I just threw up my hands and gave up and wrote my own. Some tools crash on certain tags, others can't do the things I want. Still others were id3v1 or id3v2 only. The tool I wrote is a single python script named "id3". https://github.com/efalk/AudioTools – Edward Falk Jul 30 '20 at 20:24
  • Warning: I've lost track artwork after setting song title using id3tag and Unicode is not supported. – Naitree May 02 '21 at 03:55
  • @Naitree Another warning for others: just trying to change the track number with that tool and it wiped out everything that I did not set which makes it rather worthless. Maybe there's more to it but I rarely have this problem so probably will just do it manually. – Pryftan Dec 02 '22 at 19:39
  • As of October 2023 id3lib doesn't support ID3v2.4.0. As recommended below use mutagen or some other actively maintained package. – Stefan Schmidt Oct 31 '23 at 10:54
14

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

  • 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 Nov 13 '10 at 11:39
  • @Jonik what did you use to wrap the library? Some python you wrote? – Robert S Ciaccio Nov 15 '10 at 05: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 Nov 15 '10 at 06: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... – Robert S Ciaccio Nov 15 '10 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 Nov 15 '10 at 20:08
  • @Jonik: awesome, thanks! If I add anything cool I'll share-alike :) – Robert S Ciaccio Nov 17 '10 at 08:51
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!".

kraymer
  • 2,982
  • 2
  • 18
  • 15
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.

Nelson
  • 1,094
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.

bryn
  • 151
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.

eric
  • 513
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...)

gWaldo
  • 162
  • 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 Nov 15 '10 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.

Ben Wyatt
  • 2,044