Exemplo n.º 1
0
		public void TestYear ()
		{
			Riff.DivXTag tag = new Riff.DivXTag ();

			Assert.IsTrue (tag.IsEmpty, "Initially empty");
			Assert.AreEqual (0, tag.Year, "Initially zero");

			ByteVector rendered = tag.Render ();
			tag = new Riff.DivXTag (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 Riff.DivXTag (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 Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.AreEqual (0, tag.Year, "Still zero");
		}
Exemplo n.º 2
0
		public void TestPerformers ()
		{
			Riff.DivXTag tag = new Riff.DivXTag ();

			Assert.IsTrue (tag.IsEmpty, "Initially empty");
			Assert.AreEqual (0, tag.Performers.Length, "Initially empty");

			ByteVector rendered = tag.Render ();
			tag = new Riff.DivXTag (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 Riff.DivXTag (rendered);
			Assert.IsFalse (tag.IsEmpty, "Still not empty");
			Assert.AreEqual ("A123456789; B123456789; C12345", 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 Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.AreEqual (0, tag.Performers.Length, "Still empty");
		}
Exemplo n.º 3
0
		public void TestTitle ()
		{
			Riff.DivXTag tag = new Riff.DivXTag ();

			Assert.IsTrue (tag.IsEmpty, "Initially empty");
			Assert.IsNull (tag.Title, "Initially null");

			ByteVector rendered = tag.Render ();
			tag = new Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.IsNull (tag.Title, "Still null");

			tag.Title = "01234567890123456789012345678901234567890123456789";
			Assert.IsFalse (tag.IsEmpty, "Not empty");
			Assert.AreEqual ("01234567890123456789012345678901234567890123456789", tag.Title);

			rendered = tag.Render ();
			tag = new Riff.DivXTag (rendered);
			Assert.IsFalse (tag.IsEmpty, "Still not empty");
			Assert.AreEqual ("01234567890123456789012345678901", tag.Title);

			tag.Title = string.Empty;
			Assert.IsTrue (tag.IsEmpty, "Again empty");
			Assert.IsNull (tag.Title, "Again null");

			rendered = tag.Render ();
			tag = new Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.IsNull (tag.Title, "Still null");
		}
Exemplo n.º 4
0
        /// <summary>
        ///    Saves the changes made in the current instance to the
        ///    file it represents.
        /// </summary>
        public override void Save()
        {
            Mode = AccessMode.Write;
            try {
                ByteVector data = new ByteVector();

                // Enclose the Id3v2 tag in an "ID32" item and
                // embed it as the first tag.
                if (id32_tag != null)
                {
                    ByteVector tag_data = id32_tag.Render();
                    if (tag_data.Count > 10)
                    {
                        if (tag_data.Count % 2 == 1)
                        {
                            tag_data.Add(0);
                        }
                        data.Add("ID32");
                        data.Add(ByteVector.FromUInt(
                                     (uint)tag_data.Count,
                                     false));
                        data.Add(tag_data);
                    }
                }

                // Embed "INFO" as the second tag.
                if (info_tag != null)
                {
                    data.Add(info_tag.RenderEnclosed());
                }

                // Embed "MID " as the third tag.
                if (mid_tag != null)
                {
                    data.Add(mid_tag.RenderEnclosed());
                }

                // Embed the DivX tag in "IDVX and embed it as
                // the fourth tag.
                if (divx_tag != null && !divx_tag.IsEmpty)
                {
                    ByteVector tag_data = divx_tag.Render();
                    data.Add("IDVX");
                    data.Add(ByteVector.FromUInt(
                                 (uint)tag_data.Count, false));
                    data.Add(tag_data);
                }

                // Read the file to determine the current RIFF
                // size and the area tagging does in.
                uint riff_size;
                long tag_start, tag_end;
                Read(false, ReadStyle.None, out riff_size,
                     out tag_start, out tag_end);

                // If tagging info cannot be found, place it at
                // the end of the file.
                if (tag_start < 12 || tag_end < tag_start)
                {
                    tag_start = tag_end = Length;
                }

                int length = (int)(tag_end - tag_start);

                // If the tag isn't at the end of the file,
                // try appending using padding to improve
                // write time now or for subsequent writes.
                if (tag_end != Length)
                {
                    int padding_size = length - data.Count - 8;
                    if (padding_size < 0)
                    {
                        padding_size = 1024;
                    }


                    data.Add("JUNK");
                    data.Add(ByteVector.FromUInt(
                                 (uint)padding_size, false));
                    data.Add(new ByteVector(padding_size));
                }

                // Insert the tagging data.
                Insert(data, tag_start, length);

                // If the data size changed, and the tagging
                // data is within the RIFF portion of the file,
                // update the riff size.
                if (data.Count - length != 0 &&
                    tag_start <= riff_size)
                {
                    Insert(ByteVector.FromUInt((uint)
                                               (riff_size + data.Count - length),
                                               false), 4, 4);
                }

                // Update the tag types.
                TagTypesOnDisk = TagTypes;
            } finally {
                Mode = AccessMode.Closed;
            }
        }
Exemplo n.º 5
0
 public override void Save()
 {
     Mode = AccessMode.Write;
     try
     {
         ByteVector data = new ByteVector();
         if (id32_tag != null)
         {
             ByteVector tag_data = id32_tag.Render();
             if (tag_data.Count > 10)
             {
                 if (tag_data.Count % 2 == 1)
                 {
                     tag_data.Add(0);
                 }
                 data.Add("ID32");
                 data.Add(ByteVector.FromUInt((uint)tag_data.Count, false));
                 data.Add(tag_data);
             }
         }
         if (info_tag != null)
         {
             data.Add(info_tag.RenderEnclosed());
         }
         if (mid_tag != null)
         {
             data.Add(mid_tag.RenderEnclosed());
         }
         if (divx_tag != null && !divx_tag.IsEmpty)
         {
             ByteVector tag_data = divx_tag.Render();
             data.Add("IDVX");
             data.Add(ByteVector.FromUInt((uint)tag_data.Count, false));
             data.Add(tag_data);
         }
         uint riff_size;
         long tag_start, tag_end;
         Read(false, ReadStyle.None, out riff_size, out tag_start, out tag_end);
         if (tag_start < 12 || tag_end < tag_start)
         {
             tag_start = tag_end = Length;
         }
         int length = (int)(tag_end - tag_start);
         if (tag_end != Length)
         {
             int padding_size = length - data.Count - 8;
             if (padding_size < 0)
             {
                 padding_size = 1024;
             }
             data.Add("JUNK");
             data.Add(ByteVector.FromUInt((uint)padding_size, false));
             data.Add(new ByteVector(padding_size));
         }
         Insert(data, tag_start, length);
         if (data.Count - length != 0 && tag_start <= riff_size)
         {
             Insert(ByteVector.FromUInt((uint)(riff_size + data.Count - length), false), 4, 4);
         }
         TagTypesOnDisk = TagTypes;
     }
     finally
     {
         Mode = AccessMode.Closed;
     }
 }
Exemplo n.º 6
0
		public void TestGenres ()
		{
			Riff.DivXTag tag = new Riff.DivXTag ();

			Assert.IsTrue (tag.IsEmpty, "Initially empty");
			Assert.AreEqual (0, tag.Genres.Length, "Initially empty");

			ByteVector rendered = tag.Render ();
			tag = new Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.AreEqual (0, tag.Genres.Length, "Still empty");

			tag.Genres = new string [] {"Action", "Comedy", "Non-Genre", "Claymation"};
			Assert.IsFalse (tag.IsEmpty, "Not empty");
			Assert.AreEqual ("Action", tag.JoinedGenres);

			rendered = tag.Render ();
			tag = new Riff.DivXTag (rendered);
			Assert.IsFalse (tag.IsEmpty, "Still not empty");
			Assert.AreEqual ("Action", 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 Riff.DivXTag (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 Riff.DivXTag (rendered);
			Assert.IsTrue (tag.IsEmpty, "Still empty");
			Assert.AreEqual (0, tag.Genres.Length, "Still empty");
		}