159

What's a quick and easy way to view and edit ID3 tags (artist, album, etc.) using C#?

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
Mag Roader
  • 6,850
  • 8
  • 32
  • 27

7 Answers7

194

Thirding TagLib Sharp.

TagLib.File f = TagLib.File.Create(path);
f.Tag.Album = "New Album Title";
f.Save();
Nikola
  • 2,093
  • 3
  • 22
  • 43
Luke
  • 2,977
  • 1
  • 20
  • 15
  • 1
    Can anybody tell me how to set Artist property? There are a lot of related properties (FirstArtist, Artist, JointedArtists, FirstPerformer) and almost all of them are read-only or deprecated... – Laserson Oct 14 '10 at 17:24
  • 3
    A bit late, but you can add the performers/artists by the following: mp3.Tag.Performers = new string[] { "Performer 1", "Performer 2", "Performer 3" }; – nokturnal Aug 15 '11 at 20:28
  • Does this library support modern ID3v2 tags? Simucal's snippet suggests not (unless he just took part of it). – James May 18 '13 at 18:38
  • TagLib is GPL. This is hardly an appropriate answer here. – Sean O'Neil Sep 04 '18 at 08:21
67

TagLib Sharp is pretty popular.

As a side note, if you wanted to take a quick and dirty peek at doing it yourself.. here is a C# snippet I found to read an mp3's tag info.

class MusicID3Tag

{

    public byte[] TAGID = new byte[3];      //  3
    public byte[] Title = new byte[30];     //  30
    public byte[] Artist = new byte[30];    //  30 
    public byte[] Album = new byte[30];     //  30 
    public byte[] Year = new byte[4];       //  4 
    public byte[] Comment = new byte[30];   //  30 
    public byte[] Genre = new byte[1];      //  1

}

string filePath = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\041105.mp3";

        using (FileStream fs = File.OpenRead(filePath))
        {
            if (fs.Length >= 128)
            {
                MusicID3Tag tag = new MusicID3Tag();
                fs.Seek(-128, SeekOrigin.End);
                fs.Read(tag.TAGID, 0, tag.TAGID.Length);
                fs.Read(tag.Title, 0, tag.Title.Length);
                fs.Read(tag.Artist, 0, tag.Artist.Length);
                fs.Read(tag.Album, 0, tag.Album.Length);
                fs.Read(tag.Year, 0, tag.Year.Length);
                fs.Read(tag.Comment, 0, tag.Comment.Length);
                fs.Read(tag.Genre, 0, tag.Genre.Length);
                string theTAGID = Encoding.Default.GetString(tag.TAGID);

                if (theTAGID.Equals("TAG"))
                {
                    string Title = Encoding.Default.GetString(tag.Title);
                    string Artist = Encoding.Default.GetString(tag.Artist);
                    string Album = Encoding.Default.GetString(tag.Album);
                    string Year = Encoding.Default.GetString(tag.Year);
                    string Comment = Encoding.Default.GetString(tag.Comment);
                    string Genre = Encoding.Default.GetString(tag.Genre);

                    Console.WriteLine(Title);
                    Console.WriteLine(Artist);
                    Console.WriteLine(Album);
                    Console.WriteLine(Year);
                    Console.WriteLine(Comment);
                    Console.WriteLine(Genre);
                    Console.WriteLine();
                }
            }
        }
Nifle
  • 11,745
  • 10
  • 75
  • 100
mmcdole
  • 91,488
  • 60
  • 186
  • 222
  • 12
    That is only for ID3v1. v2 has another structure, it's in the beginning of the file (as opposed to v1 which was in the end) and has variable length (v1 is always 128 bytes). – jishi Nov 11 '08 at 16:38
  • it's very too long solution & not optimized . http://stackoverflow.com/a/4361634/1395101 – Amin Ghaderi Dec 16 '15 at 21:28
  • `Encoding.Default` can be replaced with `Encoding.UTF8`. For more information visit: http://www.gigamonkeys.com/book/practical-an-id3-parser.html – Mirjalal Jan 17 '16 at 17:34
26

UltraID3Lib...

Be aware that UltraID3Lib is no longer officially available, and thus no longer maintained. See comments below for the link to a Github project that includes this library

//using HundredMilesSoftware.UltraID3Lib;
UltraID3 u = new UltraID3();
u.Read(@"C:\mp3\song.mp3");
//view
Console.WriteLine(u.Artist);
//edit
u.Artist = "New Artist";
u.Write();
arkon
  • 2,209
  • 3
  • 27
  • 36
Matt
  • 652
  • 1
  • 7
  • 18
  • +1 This is the best library by far - since 'UltraID3Lib supports most all of the seventy-four types of frames specified in the ID3 v2.3' as well as the early ID3v1 tags. Best answer. – James May 18 '13 at 18:33
  • +1 This is much easier to use and simpler way to deal with mp3 metadata – amrswalha Aug 15 '13 at 09:21
  • 1
    I used this recently and it works awesome and does not burden the process. It's fast and easy to use and accounts for just about every tag that exists in ID3 versions 1 and 2 (you can use both at once or just one or the other). It does way more than I needed. It also had a very comprehensive help file. I will recommend this to everyone. – user1934286 Sep 12 '13 at 18:59
  • Greetings; Link is inaccessible. Is UltraID3Lib Discontinued? –  Jun 07 '18 at 12:02
  • I found a version of UltraID3Lib included in this GitHub project. https://github.com/clementboone/MyWindowsMediaPlayer The project contains an UltraID3Lib folder that is the complete contents of the zip file that used to be available. – Matt Jun 07 '18 at 17:01
  • It should go without saying that relying a library that is no longer publicly available or maintained probably isn't an ideal solution for most situations – arkon Oct 01 '19 at 08:49
15

TagLib Sharp has support for reading ID3 tags.

Nifle
  • 11,745
  • 10
  • 75
  • 100
tslocum
  • 3,422
  • 5
  • 30
  • 33
2

ID3.NET implemented ID3v1.x and ID3v2.3 and supports read/write operations on the ID3 section in MP3 files. There's also a NuGet package available.

0x8BADF00D
  • 962
  • 1
  • 8
  • 18
2

I wrapped mp3 decoder library and made it available for .net developers. You can find it here:

http://sourceforge.net/projects/mpg123net/

Included are the samples to convert mp3 file to PCM, and read ID3 tags.

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99
0

Audio Tools Library (ATL) is the best. Don't use TagLib sharp. Its has limited support and can't handle chapters. The nuget package is here for ATL. I tried several things, but ATL was the only one that could do everything I needed.

FinestStudios
  • 181
  • 1
  • 7