Read & Update MP3 ID3 Tags in Ruby
ID3 is a format to store metadata within MP3 files which might include album info, artist info, cover images, thumbnails, and so on. These tags help software like Windows Media Player, iTunes, etc. categorize music and build a library for you to browse. Also, there exists software like Easy ID3 Tag Editor, etc. which allow you to create and edit ID3 tags' all fields.
So, what's the use? There are many, you might want to create your own web-based ID3 editor/library, or you might want to create an index of MP3 files you have and so on.
In this article we'll be looking at a Ruby module called taglib-ruby which is a Ruby interface for the C++ library called taglib. We'll use the Ruby module to read & write to MP3 files' tags. TagLib also supports many other file formats like OGG, FLAC, etc, but here we will only be looking at MP3.
You'll need to install taglib library (http://taglib.github.io/), if your system's package manager can install it then fine, else you'll need to compile it.
After installing taglib library, issue the following command to install taglib-ruby.
That's all, now we can start reading ID3 tags from MP3 files.
Let's lay hands on some code which will read tags from an MP3 and print them out:
I guess that was self explanatory enough.
Writing is quite similar to ready, we can also add album art images, cover images if we want, follow the code example below:
|All times are GMT +5.5. The time now is 09:27.|