Coding

Obsolete

SharpTagger is obsolete and remains here for historical reasons only. Please check out TagLib# for your .NET tagging purposes. It is 100% managed code and used by popular projects such as Banshee.

Why SharpTagger?

People love TagLib, a lot. It's not hard to see why, as it is a very sexy library. The only problem is that the default abilities are below what Muine needs. As such, this library is a glorious collection of hacks which built into one beautiful class, which provide above and beyond for all of Muine's needs. (Except for m4a, but no one's perfect.) To see this baby in action, install this and MuineTagger, and take it for a spin.

Requirements

  • TagLib 1.4
  • Mono
  • GtkSharp 1.9.5 (for Gdk.Pixbuf)

Installation

wget http://www.public.asu.edu/~bnickel/SharpTagger/SharpTagger-1.1.1.tar.bz2
tar -xvjf SharpTagger-1.1.1.tar.bz2
cd SharpTagger-1.1.1
./configure --prefix=/usr && make && sudo make install

Files

SharpTagger-1.1.1.tar.bz2
  • No internal changes.
  • Adopted automake.
SharpTagger-1.1.1-compile-sh.tar.bz2
  • Use correct name for Vorbis "GENRE" and "PERFORMER".
  • Handle multi-string fields correctly in Vorbis and Ape tags.
SharpTagger-1.1.0.tar.bz2
  • Fixes support for saving genres with Ogg Vorbis files.
  • Major code refinement.
  • Don't crash on new Tag ("").
  • Use new Replay Gain API currently broken in TagLib 1.4
  • Added new properties: DiscName and Discs to extend support for multi-disc albums.
SharpTagger-1.0.0.tar.bz2
  • First release as an independent library.
  • Full Replay Gain read/write support to come after the next release of TagLib.

Example

// SetArtists.cs
using System;

class SetArtists
{
   public static void Main (string [] args)
   {
      if (args.Length < 2)
         throw new Exception ("Usage: mono SetArtist.exe album file [file2 ...]");
      char [] splitter  = {'/'};
      string [] artists = args [0].Split (splitter);
      
      SharpTagger.Tag tag = new SharpTagger.Tag ();
      tag.ScanAudio = false;
      for (int i = 1; i < args.Length; i ++)
         if (tag.Open (args [i]))
         {
            tag.Artists = artists;
            tag.Close (true);
         }
   }
}

---------------------------
mcs SetArtists.cs /pkg:sharp-tagger
---------------------------
mono SetArtists.exe "Artist 1/Artist 2/Artist 3" *.mp3

Documentation

Namespace SharpTagger

class Tag

Tag (string filename, bool scan)
Creates a new Tag, sets ScanAudio to scan, and loads filename.
Arguments
string filename
The name of the file to load.
bool scan
Scan for the song's length.
Tag (string filename)
Creates a new Tag and loads filename.
Arguments
string filename
The name of the file to load.
Tag ()
Creates a new Tag without loading a file.
bool Open (string filename)
Loads tag information for filename.
Return Value
bool
True if the file loaded successfully, false otherwise.
Arguments
string filename
The name of the file to load.
bool Save ()
Saves tag information to disc.
Return Value
bool
True if the file saved successfully, false otherwise.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
void Close (bool save)
Closes the tag, freeing its data, and saving if save is true.
Arguments
bool save
Save the tag to disc before closing it.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false) and save is true, an exception is thrown.
string Filename
The file name of the open tag. If the tag isn't open, it is an empty string.
bool IsOpen
Whether or not a tag is loaded.
bool ScanAudio
Whether or not to scan audio information (length) when the tag is loading.
string Title
The song's title.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string Album
The song's album.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string DiscName
The name of the specific disc a song is on (for if an album has multiple named discs).
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string Comment
A comment about the song.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string [] Artists
The song's artists.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string [] Performers
The song's performers.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string [] Genres
The song's genres.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
string [] Moods
The song's moods.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Disc
The specific disc number in a set featuring this song. Zero if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Discs
The total number of discs in the set featuring this song. Zero if not set or if Disc equals zero.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Year
The year this song was produced. Zero if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Track
The song's track on the given Disc of the Album. Zero if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Tracks
The total number of tracks on the given Disc of the Album. Zero if not set or if Track is zero.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
uint Duration
The length of this song. Zero if undescovered.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
float Gain
The replay gain of this song, from -64dB to 64dB. Zero if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
Warnings
  • At this time, TagLib (1.4) does not properly support replay gain in MP3 files.
float Peak
The peak volume of this song. Zero if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
Warnings
  • Peak is not returned for MP3 files (because I don't understand the specification.
Gdk.Pixbuf AlbumCover
The album cover attached to this song. Null if not set.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
Warnings
  • Peak is not returned for MP3 files (because I don't understand the specification.
string MimeType
The song's mime type.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown.
int MTime
The modification time of this song.
Exceptions thrown
System.Exception
If no tag is open (IsOpen == false), an exception is thrown