public TagLib.Tag AddTag(TagTypes type, TagLib.Tag copy) { TagLib.Tag target = null; if (type == (TagTypes.None | TagTypes.Id3v1)) { target = new TagLib.Id3v1.Tag(); } else if (type == (TagTypes.None | TagTypes.Id3v2)) { TagLib.Id3v2.Tag tag2; target = new TagLib.Id3v2.Tag { Version = 4, Flags = (byte) (tag2.Flags | HeaderFlags.FooterPresent) }; } else if (type == (TagTypes.None | TagTypes.Ape)) { target = new TagLib.Ape.Tag(); } if (target != null) { if (copy != null) { copy.CopyTo(target, true); } if (type == (TagTypes.None | TagTypes.Id3v1)) { base.AddTag(target); return target; } base.InsertTag(0, target); } return target; }
private TagLib.Tag ReadTag(ref long end) { long position = end; TagTypes types = this.ReadTagInfo(ref position); TagLib.Tag tag = null; try { TagTypes types2 = types; switch (types2) { case (TagTypes.None | TagTypes.Id3v1): tag = new TagLib.Id3v1.Tag(this.file, position); break; case (TagTypes.None | TagTypes.Id3v2): tag = new TagLib.Id3v2.Tag(this.file, position); break; default: if (types2 == (TagTypes.None | TagTypes.Ape)) { tag = new TagLib.Ape.Tag(this.file, end - 0x20L); } break; } end = position; } catch (CorruptFileException) { } return tag; }
public void TestPerformers () { Id3v1.Tag tag = new Id3v1.Tag (); Assert.IsTrue (tag.IsEmpty, "Initially empty"); Assert.AreEqual (0, tag.Performers.Length, "Initially empty"); ByteVector rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Performers.Length, "Still empty"); tag.Performers = new string [] {"A123456789", "B123456789", "C123456789", "D123456789", "E123456789"}; Assert.IsFalse (tag.IsEmpty, "Not empty"); Assert.AreEqual ("A123456789; B123456789; C123456789; D123456789; E123456789", tag.JoinedPerformers); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual ("A123456789; B123456789; C1234567", tag.JoinedPerformers); tag.Performers = new string [0]; Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Performers.Length, "Again empty"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Performers.Length, "Still empty"); }
public void TestAlbum () { Id3v1.Tag tag = new Id3v1.Tag (); Assert.IsTrue (tag.IsEmpty, "Initially empty"); Assert.IsNull (tag.Album, "Initially null"); ByteVector rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.IsNull (tag.Album, "Still null"); tag.Album = "01234567890123456789012345678901234567890123456789"; Assert.IsFalse (tag.IsEmpty, "Not empty"); Assert.AreEqual ("01234567890123456789012345678901234567890123456789", tag.Album); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual ("012345678901234567890123456789", tag.Album); tag.Album = string.Empty; Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.IsNull (tag.Album, "Again null"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.IsNull (tag.Album, "Still null"); }
public void TestRender () { ByteVector rendered = new Id3v1.Tag ().Render (); Assert.AreEqual (128, rendered.Count); Assert.IsTrue (rendered.StartsWith (Id3v1.Tag.FileIdentifier)); }
public void TestClear () { Id3v1.Tag tag = new Id3v1.Tag (); tag.Title = "A"; tag.Performers = new string [] {"B"}; tag.Album = "C"; tag.Year = 123; tag.Comment = "D"; tag.Track = 234; tag.Genres = new string [] {"Blues"}; Assert.IsFalse (tag.IsEmpty, "Should be full."); tag.Clear (); Assert.IsNull (tag.Title, "Title"); Assert.AreEqual (0, tag.Performers.Length, "Performers"); Assert.IsNull (tag.Album, "Album"); Assert.AreEqual (0, tag.Year, "Year"); Assert.IsNull (tag.Comment, "Comment"); Assert.AreEqual (0, tag.Track, "Track"); Assert.AreEqual (0, tag.Genres.Length, "Genres"); Assert.IsTrue (tag.IsEmpty, "Should be empty."); }
public void TestGenres () { Id3v1.Tag tag = new Id3v1.Tag (); Assert.IsTrue (tag.IsEmpty, "Initially empty"); Assert.AreEqual (0, tag.Genres.Length, "Initially empty"); ByteVector rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Genres.Length, "Still empty"); tag.Genres = new string [] {"Rap", "Jazz", "Non-Genre", "Blues"}; Assert.IsFalse (tag.IsEmpty, "Not empty"); Assert.AreEqual ("Rap", tag.JoinedGenres); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual ("Rap", tag.JoinedGenres); tag.Genres = new string [] {"Non-Genre"}; Assert.IsTrue (tag.IsEmpty, "Surprisingly empty"); Assert.AreEqual (0, tag.Genres.Length, "Surprisingly empty"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Genres.Length, "Still empty"); tag.Genres = new string [0]; Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Genres.Length, "Again empty"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Genres.Length, "Still empty"); }
public void TestTrack () { Id3v1.Tag tag = new Id3v1.Tag (); Assert.IsTrue (tag.IsEmpty, "Initially empty"); Assert.AreEqual (0, tag.Track, "Initially zero"); ByteVector rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Track, "Still zero"); tag.Track = 123; Assert.IsFalse (tag.IsEmpty, "Not empty"); Assert.AreEqual (123, tag.Track); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual (123, tag.Track); tag.Track = 0; Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Track, "Again zero"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Track, "Still zero"); }
public void TestYear () { Id3v1.Tag tag = new Id3v1.Tag (); Assert.IsTrue (tag.IsEmpty, "Initially empty"); Assert.AreEqual (0, tag.Year, "Initially zero"); ByteVector rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Year, "Still zero"); tag.Year = 1999; Assert.IsFalse (tag.IsEmpty, "Not empty"); Assert.AreEqual (1999, tag.Year); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsFalse (tag.IsEmpty, "Still not empty"); Assert.AreEqual (1999, tag.Year); tag.Year = 20000; Assert.IsTrue (tag.IsEmpty, "Again empty"); Assert.AreEqual (0, tag.Year, "Again zero"); rendered = tag.Render (); tag = new Id3v1.Tag (rendered); Assert.IsTrue (tag.IsEmpty, "Still empty"); Assert.AreEqual (0, tag.Year, "Still zero"); }