While retrieving a list of multimedia files, I ended up with a list of files with 4-character names that meant nothing. Grrr…. So I decided to create a small utility to rename the files according to a pattern I already had on my machine based on the artist, album, and song title.
But a problem quickly arose: How to retrieve this metadata (mainly from MP3 files)?
So I did what I often do when I have a question, I did a little search. And I found on this StackOverflow result a link to TagLib# (also working on Mono)! This library from Novell does all the work for me! It allows me to access metadata for many different types of files. Here is the basic example among several provided on their site:
try
{
TagLib.File file = TagLib.File.Create ("/path/to/music/file.mp3");
// Read some information.
string title = file.Tag.Title;
uint track = file.Tag.Track;
string album = file.Tag.Album;
string [] artists = file.Tag.Artists; // Remember, each song can have more than one artist.
... // Do stuff to title, album, artists.
// Store that information in the tag.
file.Tag.Title = title;
file.Tag.Track = track;
file.Tag.Album = album;
file.Tag.Artists = artists;
file.Save ();
}
catch {...}
So if you ever need metadata, I highly recommend this one!