Esempio n. 1
0
        /// <summary>
        ///    Adds a tag of a specified type to the current instance,
        ///    optionally copying values from an existing type.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagTypes" /> value specifying the type of
        ///    tag to add to the current instance. At the time of this
        ///    writing, this is limited to <see cref="TagTypes.Ape" />
        ///    and <see cref="TagTypes.Id3v2" />.
        /// </param>
        /// <param name="copy">
        ///    A <see cref="TagLibSharp.Tag" /> to copy values from using
        ///    <see cref="TagLibSharp.Tag.CopyTo" />, or <see
        ///    langword="null" /> if no tag is to be copied.
        /// </param>
        /// <returns>
        ///    The <see cref="TagLibSharp.Tag" /> object added to the current
        ///    instance, or <see langword="null" /> if it couldn't be
        ///    created.
        /// </returns>
        /// <remarks>
        ///    ID3v2 tags are added at the end of the current instance,
        ///    while other tags are added to the beginning.
        /// </remarks>
        public TagLibSharp.Tag AddTag(TagTypes type, TagLibSharp.Tag copy)
        {
            TagLibSharp.Tag tag = null;

            if (type == TagTypes.Id3v2)
            {
                tag = new Id3v2.Tag();
            }
            else if (type == TagTypes.Ape)
            {
                tag = new Ape.Tag();
                (tag as Ape.Tag).HeaderPresent = true;
            }

            if (tag != null)
            {
                if (copy != null)
                {
                    copy.CopyTo(tag, true);
                }

                AddTag(tag);
            }

            return(tag);
        }
Esempio n. 2
0
 private void TagTestWithSave(ref Ape.Tag tag,
                              TagTestFunc testFunc)
 {
     testFunc(tag, "Before Save");
     tag = new Ape.Tag(tag.Render());
     testFunc(tag, "After Save");
 }
Esempio n. 3
0
        /// <summary>
        ///    Reads a tag ending at a specified position and moves the
        ///    cursor to its start position.
        /// </summary>
        /// <param name="end">
        ///    A <see cref="long" /> value reference specifying at what
        ///    position the potential tag ends at. If a tag is found,
        ///    this value will be updated to the position at which the
        ///    found tag starts.
        /// </param>
        /// <returns>
        ///    A <see cref="TagLibSharp.Tag" /> object representing the tag
        ///    found at the specified position, or <see langword="null"
        ///    /> if no tag was found.
        /// </returns>
        private TagLibSharp.Tag ReadTag(ref long end)
        {
            long     start = end;
            TagTypes type  = ReadTagInfo(ref start);

            TagLibSharp.Tag tag = null;

            try {
                switch (type)
                {
                case TagTypes.Ape:
                    tag = new Ape.Tag(file, end - Footer.Size);
                    break;

                case TagTypes.Id3v2:
                    tag = new Id3v2.Tag(file, start);
                    break;

                case TagTypes.Id3v1:
                    tag = new Id3v1.Tag(file, start);
                    break;
                }

                end = start;
            } catch (CorruptFileException) {
            }

            return(tag);
        }
Esempio n. 4
0
        public void TestAlbumArtists()
        {
            Ape.Tag tag = new Ape.Tag();

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, t.AlbumArtists.Length, "Initial (Zero): " + m);
            });

            tag.AlbumArtists = val_mult;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_mult.Length, t.AlbumArtists.Length, "Value Set: " + m);
                for (int i = 0; i < val_mult.Length; i++)
                {
                    Assert.AreEqual(val_mult [i], t.AlbumArtists [i], "Value Set: " + m);
                }
            });

            tag.AlbumArtists = new string [0];

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.AlbumArtists.Length, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 5
0
        /// <summary>
        ///    Reads a tag starting at a specified position and moves the
        ///    cursor to its start position.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="long" /> value reference specifying at what
        ///    position the potential tag starts. If a tag is found,
        ///    this value will be updated to the position at which the
        ///    found tag ends.
        /// </param>
        /// <returns>
        ///    A <see cref="TagLibSharp.Tag" /> object representing the tag
        ///    found at the specified position, or <see langword="null"
        ///    /> if no tag was found.
        /// </returns>
        private TagLibSharp.Tag ReadTag(ref long start)
        {
            long     end  = start;
            TagTypes type = ReadTagInfo(ref end);

            TagLibSharp.Tag tag = null;

            try {
                switch (type)
                {
                case TagTypes.Ape:
                    tag = new Ape.Tag(file, start);
                    break;

                case TagTypes.Id3v2:
                    tag = new Id3v2.Tag(file, start);
                    break;
                }
            } catch (CorruptFileException e) {
                Console.Error.WriteLine("taglib-sharp caught exception creating tag: {0}", e);
            }

            start = end;
            return(tag);
        }
Esempio n. 6
0
        public void TestAlbumArtists()
        {
            Ape.Tag tag = new Ape.Tag ();

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual (0, t.AlbumArtists.Length, "Initial (Zero): " + m);
            });

            tag.AlbumArtists = val_mult;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual (val_mult.Length, t.AlbumArtists.Length, "Value Set: " + m);
                for (int i = 0; i < val_mult.Length; i ++) {
                    Assert.AreEqual (val_mult [i], t.AlbumArtists [i], "Value Set: " + m);
                }
            });

            tag.AlbumArtists = new string [0];

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual (0, t.AlbumArtists.Length, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 7
0
        public void TestPictures()
        {
            Ape.Tag tag = new Ape.Tag();

            Picture [] pictures = new Picture [] {
                new Picture("../examples/covers/sample_a.png"),
                new Picture("../examples/covers/sample_a.jpg"),
                new Picture("../examples/covers/sample_b.png"),
                new Picture("../examples/covers/sample_b.jpg"),
                new Picture("../examples/covers/sample_c.png"),
                new Picture("../examples/covers/sample_c.jpg")
            };

            for (int i = 0; i < 6; i++)
            {
                pictures [i].Type = (PictureType)(i * 2);
            }

            pictures [3].Description = val_sing;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Initial (Zero): " + m);
            });

            tag.Pictures = pictures;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(pictures.Length, t.Pictures.Length, "Value Set: " + m);
                for (int i = 0; i < pictures.Length; i++)
                {
                    string msg = "Value " + i + "Set: " + m;
                    Assert.AreEqual(pictures [i].Data, t.Pictures [i].Data, msg);
                    Assert.AreEqual(pictures [i].Type, t.Pictures [i].Type, msg);
                    Assert.AreEqual(pictures [i].Description, t.Pictures [i].Description, msg);
                    Assert.AreEqual(pictures [i].MimeType, t.Pictures [i].MimeType, msg);
                }
            });

            tag.Pictures = new Picture [0];

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.Pictures.Length, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 8
0
        public void TestClear()
        {
            Ape.Tag tag = new Ape.Tag();

            tag.Title          = "A";
            tag.Performers     = new string [] { "B" };
            tag.AlbumArtists   = new string [] { "C" };
            tag.Composers      = new string [] { "D" };
            tag.Album          = "E";
            tag.Comment        = "F";
            tag.Genres         = new string [] { "Blues" };
            tag.Year           = 123;
            tag.Track          = 234;
            tag.TrackCount     = 234;
            tag.Disc           = 234;
            tag.DiscCount      = 234;
            tag.Lyrics         = "G";
            tag.Grouping       = "H";
            tag.BeatsPerMinute = 234;
            tag.Conductor      = "I";
            tag.Copyright      = "J";
            tag.Pictures       = new Picture [] { new Picture("../examples/covers/sample_a.png") };

            Assert.IsFalse(tag.IsEmpty, "Should be full.");
            tag.Clear();

            Assert.IsNull(tag.Title, "Title");
            Assert.AreEqual(0, tag.Performers.Length, "Performers");
            Assert.AreEqual(0, tag.AlbumArtists.Length, "AlbumArtists");
            Assert.AreEqual(0, tag.Composers.Length, "Composers");
            Assert.IsNull(tag.Album, "Album");
            Assert.IsNull(tag.Comment, "Comment");
            Assert.AreEqual(0, tag.Genres.Length, "Genres");
            Assert.AreEqual(0, tag.Year, "Year");
            Assert.AreEqual(0, tag.Track, "Track");
            Assert.AreEqual(0, tag.TrackCount, "TrackCount");
            Assert.AreEqual(0, tag.Disc, "Disc");
            Assert.AreEqual(0, tag.DiscCount, "DiscCount");
            Assert.IsNull(tag.Lyrics, "Lyrics");
            Assert.IsNull(tag.Comment, "Comment");
            Assert.AreEqual(0, tag.BeatsPerMinute, "BeatsPerMinute");
            Assert.IsNull(tag.Conductor, "Conductor");
            Assert.IsNull(tag.Copyright, "Copyright");
            Assert.AreEqual(0, tag.Pictures.Length, "Pictures");
            Assert.IsTrue(tag.IsEmpty, "Should be empty.");
        }
Esempio n. 9
0
        /// <summary>
        ///    Adds a tag of a specified type to the current instance,
        ///    optionally copying values from an existing type.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagTypes" /> value specifying the type of
        ///    tag to add to the current instance. At the time of this
        ///    writing, this is limited to <see cref="TagTypes.Ape" />,
        ///    <see cref="TagTypes.Id3v1" />, and <see
        ///    cref="TagTypes.Id3v2" />.
        /// </param>
        /// <param name="copy">
        ///    A <see cref="TagLibSharp.Tag" /> to copy values from using
        ///    <see cref="TagLibSharp.Tag.CopyTo" />, or <see
        ///    langword="null" /> if no tag is to be copied.
        /// </param>
        /// <returns>
        ///    The <see cref="TagLibSharp.Tag" /> object added to the current
        ///    instance, or <see langword="null" /> if it couldn't be
        ///    created.
        /// </returns>
        /// <remarks>
        ///    ID3v2 tags are added at the end of the current instance,
        ///    while other tags are added to the beginning.
        /// </remarks>
        public TagLibSharp.Tag AddTag(TagTypes type, TagLibSharp.Tag copy)
        {
            TagLibSharp.Tag tag = null;

            if (type == TagTypes.Id3v1)
            {
                tag = new Id3v1.Tag();
            }
            else if (type == TagTypes.Id3v2)
            {
                Id3v2.Tag tag32 = new Id3v2.Tag();
                tag32.Version = 4;
                tag32.Flags  |= Id3v2.HeaderFlags.FooterPresent;
                tag           = tag32;
            }
            else if (type == TagTypes.Ape)
            {
                tag = new Ape.Tag();
            }

            if (tag != null)
            {
                if (copy != null)
                {
                    copy.CopyTo(tag, true);
                }

                if (type == TagTypes.Id3v1)
                {
                    AddTag(tag);
                }
                else
                {
                    InsertTag(0, tag);
                }
            }

            return(tag);
        }
Esempio n. 10
0
        public void TestMusicBrainzReleaseCountry()
        {
            Ape.Tag tag = new Ape.Tag();

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull(t.MusicBrainzReleaseCountry, "Initial (Null): " + m);
            });

            tag.MusicBrainzReleaseCountry = val_sing;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_sing, t.MusicBrainzReleaseCountry, "Value Set (!Null): " + m);
            });

            tag.MusicBrainzReleaseCountry = string.Empty;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull(t.MusicBrainzReleaseCountry, "Value Cleared (Null): " + m);
            });
        }
Esempio n. 11
0
        public void TestAmazonID()
        {
            Ape.Tag tag = new Ape.Tag();

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull(t.AmazonId, "Initial (Null): " + m);
            });

            tag.AmazonId = val_sing;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(val_sing, t.AmazonId, "Value Set (!Null): " + m);
            });

            tag.AmazonId = string.Empty;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull(t.AmazonId, "Value Cleared (Null): " + m);
            });
        }
Esempio n. 12
0
        public void TestBeatsPerMinute()
        {
            Ape.Tag tag = new Ape.Tag();

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual(0, tag.BeatsPerMinute, "Initial (Zero): " + m);
            });

            tag.BeatsPerMinute = 199;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsFalse(t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual(199, tag.BeatsPerMinute, "Value Set: " + m);
            });

            tag.BeatsPerMinute = 0;

            TagTestWithSave(ref tag, delegate(Ape.Tag t, string m) {
                Assert.IsTrue(t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual(0, t.BeatsPerMinute, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 13
0
        public void TestAlbum()
        {
            Ape.Tag tag = new Ape.Tag ();

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.IsNull (t.Album, "Initial (Null): " + m);
            });

            tag.Album = val_sing;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual (val_sing, t.Album, "Value Set (!Null): " + m);
            });

            tag.Album = string.Empty;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.IsNull (t.Album, "Value Cleared (Null): " + m);
            });
        }
Esempio n. 14
0
        public void TestBeatsPerMinute()
        {
            Ape.Tag tag = new Ape.Tag ();

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual (0, tag.BeatsPerMinute, "Initial (Zero): " + m);
            });

            tag.BeatsPerMinute = 199;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual (199, tag.BeatsPerMinute, "Value Set: " + m);
            });

            tag.BeatsPerMinute = 0;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual (0, t.BeatsPerMinute, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 15
0
        private void TagTestWithSave(ref Ape.Tag tag,
		                              TagTestFunc testFunc)
        {
            testFunc (tag, "Before Save");
            tag = new Ape.Tag (tag.Render ());
            testFunc (tag, "After Save");
        }
Esempio n. 16
0
        public void TestPictures()
        {
            Ape.Tag tag = new Ape.Tag ();

            Picture [] pictures = new Picture [] {
                new Picture ("../examples/covers/sample_a.png"),
                new Picture ("../examples/covers/sample_a.jpg"),
                new Picture ("../examples/covers/sample_b.png"),
                new Picture ("../examples/covers/sample_b.jpg"),
                new Picture ("../examples/covers/sample_c.png"),
                new Picture ("../examples/covers/sample_c.jpg")
            };

            for (int i = 0; i < 6; i ++)
                pictures [i].Type = (PictureType) (i * 2);

            pictures [3].Description = val_sing;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
                Assert.AreEqual (0, t.Pictures.Length, "Initial (Zero): " + m);
            });

            tag.Pictures = pictures;

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
                Assert.AreEqual (pictures.Length, t.Pictures.Length, "Value Set: " + m);
                for (int i = 0; i < pictures.Length; i ++) {
                    string msg = "Value " + i + "Set: " + m;
                    Assert.AreEqual (pictures [i].Data, t.Pictures [i].Data, msg);
                    Assert.AreEqual (pictures [i].Type, t.Pictures [i].Type, msg);
                    Assert.AreEqual (pictures [i].Description, t.Pictures [i].Description, msg);
                    Assert.AreEqual (pictures [i].MimeType, t.Pictures [i].MimeType, msg);
                }
            });

            tag.Pictures = new Picture [0];

            TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
                Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
                Assert.AreEqual (0, t.Pictures.Length, "Value Cleared (Zero): " + m);
            });
        }
Esempio n. 17
0
        public void TestClear()
        {
            Ape.Tag tag = new Ape.Tag ();

            tag.Title = "A";
            tag.Performers = new string [] {"B"};
            tag.AlbumArtists = new string [] {"C"};
            tag.Composers = new string [] {"D"};
            tag.Album = "E";
            tag.Comment = "F";
            tag.Genres = new string [] {"Blues"};
            tag.Year = 123;
            tag.Track = 234;
            tag.TrackCount = 234;
            tag.Disc = 234;
            tag.DiscCount = 234;
            tag.Lyrics = "G";
            tag.Grouping = "H";
            tag.BeatsPerMinute = 234;
            tag.Conductor = "I";
            tag.Copyright = "J";
            tag.Pictures = new Picture [] {new Picture ("../examples/covers/sample_a.png")};

            Assert.IsFalse (tag.IsEmpty, "Should be full.");
            tag.Clear ();

            Assert.IsNull (tag.Title, "Title");
            Assert.AreEqual (0, tag.Performers.Length, "Performers");
            Assert.AreEqual (0, tag.AlbumArtists.Length, "AlbumArtists");
            Assert.AreEqual (0, tag.Composers.Length, "Composers");
            Assert.IsNull (tag.Album, "Album");
            Assert.IsNull (tag.Comment, "Comment");
            Assert.AreEqual (0, tag.Genres.Length, "Genres");
            Assert.AreEqual (0, tag.Year, "Year");
            Assert.AreEqual (0, tag.Track, "Track");
            Assert.AreEqual (0, tag.TrackCount, "TrackCount");
            Assert.AreEqual (0, tag.Disc, "Disc");
            Assert.AreEqual (0, tag.DiscCount, "DiscCount");
            Assert.IsNull (tag.Lyrics, "Lyrics");
            Assert.IsNull (tag.Comment, "Comment");
            Assert.AreEqual (0, tag.BeatsPerMinute, "BeatsPerMinute");
            Assert.IsNull (tag.Conductor, "Conductor");
            Assert.IsNull (tag.Copyright, "Copyright");
            Assert.AreEqual (0, tag.Pictures.Length, "Pictures");
            Assert.IsTrue (tag.IsEmpty, "Should be empty.");
        }
Esempio n. 18
0
		public void TestMusicBrainzReleaseArtistID ()
		{
			Ape.Tag tag = new Ape.Tag ();

			TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
				Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
				Assert.IsNull (t.MusicBrainzReleaseArtistId, "Initial (Null): " + m);
			});
			
			tag.MusicBrainzReleaseArtistId = val_sing;
			
			TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
				Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
				Assert.AreEqual (val_sing, t.MusicBrainzReleaseArtistId, "Value Set (!Null): " + m);
			});
			
			tag.MusicBrainzReleaseArtistId = string.Empty;

			TagTestWithSave (ref tag, delegate (Ape.Tag t, string m) {
				Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
				Assert.IsNull (t.MusicBrainzReleaseArtistId, "Value Cleared (Null): " + m);
			});
		}