Ejemplo n.º 1
0
        public void ExtendedHeaderEncoderTest()
        {
            var crc = new byte[] {0x20, 0x21, 0x22, 0x23};

            var tagContainer = new TagContainer();
            tagContainer.Tag.SetHeaderFlags(true, true, true);
            tagContainer.Tag.SetVersion(3, 0);
            tagContainer.Tag.SetExtendedHeader(10, true);
            tagContainer.Tag.SetCrc32(crc);

            var titleFrame = new TextFrame();
            titleFrame.TextEncoding = TextEncodingType.UTF16;
            titleFrame.Descriptor.ID = "TIT2";
            titleFrame.Content = "ABCD";

            tagContainer.Add(titleFrame);

            var id3Tag = m_TagController.Encode(tagContainer);

            Assert.AreEqual(id3Tag.MajorVersion, 3);
            Assert.AreEqual(id3Tag.Revision, 0);
            Assert.IsTrue(id3Tag.UnsynchronisationFlag);
            Assert.IsTrue(id3Tag.UnsynchronisationFlag);
            Assert.IsTrue(id3Tag.ExtendedHeaderAvailable);
            Assert.IsNotNull(id3Tag.ExtendHeaderV3);
            Assert.IsTrue(ComparePayload(id3Tag.ExtendHeaderV3.CRC, crc));
            Assert.AreEqual(id3Tag.Frames.Count, 1);
        }
Ejemplo n.º 2
0
		public void ValidationOKTest()
		{
			/*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

			var tagContainer = new TagContainerV3();
			tagContainer.Tag.SetExtendedHeader(0, false);
			tagContainer.Tag.SetHeaderFlags(false, false, false);

			var textFrame = new TextFrame("TALB", "My Albun", Encoding.Default);
			var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", Encoding.Default);
			var linkFrame = new UserDefinedURLLinkFrame("id3tag", "id3tag.codeplex.com", Encoding.Default);
			var pictureFrame = new PictureFrame(
				Encoding.Default,
				"image/jpeg",
				"la",
				PictureType.Other,
				new byte[] { 0x11, 0x12, 0x13, 0x14 });

			tagContainer.Add(textFrame);
			tagContainer.Add(userDefineTextFrame);
			tagContainer.Add(linkFrame);
			tagContainer.Add(pictureFrame);

			WriteTagContainer(tagContainer);

			// OK... passed!
		}
Ejemplo n.º 3
0
        public void ConstructorTest()
        {
            var textFrame = new TextFrame("TALB", "ABCD", TextEncodingType.UTF16);

            Assert.AreEqual(textFrame.Descriptor.ID, "TALB");
            Assert.AreEqual(textFrame.Content, "ABCD");
            Assert.AreEqual(textFrame.TextEncoding, TextEncodingType.UTF16);
        }
Ejemplo n.º 4
0
        public void ConverterISO88591_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = TextEncodingType.ISO_8859_1,
                                    Content = "ABCD",
                                    Descriptor = {ID = "TALB"}
                                };

            var rawFrame = textFrame.Convert();

            Assert.AreEqual(rawFrame.ID, "TALB");
            Assert.AreEqual(rawFrame.Payload[0], 0); // ISO_8859 coding
            Assert.AreEqual(rawFrame.Payload.Length, 5);
        }
Ejemplo n.º 5
0
        public void ConverterISO88591_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = Encoding.Default,
                                    Content = "ABCD",
                                    Descriptor = {ID = "TALB"}
                                };

            var rawFrame = textFrame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.ID, "TALB");
            Assert.AreEqual(rawFrame.Payload[0], 0); // ISO_8859 coding
            Assert.AreEqual(rawFrame.Payload.Length, 5);
        }
Ejemplo n.º 6
0
        public void ConverterUTF16_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = TextEncodingType.UTF16,
                                    Content = "ABCD",
                                    Descriptor = {ID = "TALB"}
                                };

            var rawFrame = textFrame.Convert();

            Assert.AreEqual(rawFrame.ID, "TALB");
            Assert.AreEqual(rawFrame.Payload[0], 1); // UTF 16
            Assert.AreEqual(rawFrame.Payload[1], 0xFF); // BOM 1
            Assert.AreEqual(rawFrame.Payload[2], 0xFE); // BOM 2
            Assert.AreEqual(rawFrame.Payload.Length, 11);
        }
Ejemplo n.º 7
0
        public void ConverterUTF16BE_Test()
        {
            var textFrame = new TextFrame
                                {
                                    TextEncoding = TextEncodingType.UTF16_BE,
                                    Content = "ABCD",
                                    Descriptor = {ID = "TALB"}
                                };

            var rawFrame = textFrame.Convert();

            Assert.AreEqual(rawFrame.ID, "TALB");

            var refBytes = new byte[]
                               {
                                   0x02, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
Ejemplo n.º 8
0
        public void ConverterUTF16BE_Test()
        {
            var textFrame = new TextFrame
                                {
									TextEncoding = new UnicodeEncoding(true, false),
                                    Content = "ABCD",
                                    Descriptor = {ID = "TALB"}
                                };

            var rawFrame = textFrame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.ID, "TALB");

            var refBytes = new byte[]
                               {
                                   0x02, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
Ejemplo n.º 9
0
        public void SimpleEncoderTest()
        {
            var tagContainer = new TagContainer();
            tagContainer.Tag.SetHeaderFlags(false, false, false);
            tagContainer.Tag.SetVersion(3, 0);

            var titleFrame = new TextFrame();
            titleFrame.TextEncoding = TextEncodingType.UTF16;
            titleFrame.Descriptor.ID = "TIT2";
            titleFrame.Content = "ABCD";

            tagContainer.Add(titleFrame);

            var id3Tag = m_TagController.Encode(tagContainer);

            Assert.AreEqual(id3Tag.MajorVersion, 3);
            Assert.AreEqual(id3Tag.Revision, 0);
            Assert.IsFalse(id3Tag.UnsynchronisationFlag);
            Assert.IsFalse(id3Tag.UnsynchronisationFlag);
            Assert.IsFalse(id3Tag.ExtendedHeaderAvailable);
            Assert.IsNull(id3Tag.ExtendHeaderV3);
            Assert.AreEqual(id3Tag.Frames.Count, 1);
        }
Ejemplo n.º 10
0
        public void ValidationPictureFrameFailed1()
        {
            /*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

            var tagContainer = new TagContainer();
            tagContainer.Tag.SetExtendedHeader(0, false);
            tagContainer.Tag.SetHeaderFlags(false, false, false);
            tagContainer.Tag.SetVersion(3, 0);

            var textFrame = new TextFrame("TALB", "My Albun", TextEncodingType.ISO_8859_1);
            var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", TextEncodingType.ISO_8859_1);
            var linkFrame = new UserDefinedURLLinkFrame("id3tag", "id3tag.codeplex.com", TextEncodingType.ISO_8859_1);
            var pictureFrame = new PictureFrame(TextEncodingType.UTF16_BE, "image/jpeg", "la", PictureType.Other,
                                                new byte[] { 0x11, 0x12, 0x13, 0x14 });

            tagContainer.Add(textFrame);
            tagContainer.Add(userDefineTextFrame);
            tagContainer.Add(linkFrame);
            tagContainer.Add(pictureFrame);

            WriteTagContainer(tagContainer);

            // OK... passed!
        }
Ejemplo n.º 11
0
        public TagContainer BuildTag(ID3V2TagData data)
        {
            var container = Id3TagFactory.CreateId3Tag(data.Version);
            if (data.Version == TagVersion.Id3V23)
            {
                //
                //  Configure the ID3v2.3 header
                //
                var extendedHeaderV23 = container.GetId3V23Descriptor();
                // Configure the tag header.
                extendedHeaderV23.SetHeaderFlags(data.Unsynchronisation, data.ExtendedHeader, data.ExperimentalIndicator);

                if (data.ExtendedHeader)
                {
                    extendedHeaderV23.SetExtendedHeader(data.PaddingSize, data.CrCPresent);
                    extendedHeaderV23.SetCrc32(data.Crc);
                }
            }
            else
            {
                //
                //  Configure the ID3v2.4 header
                //
                var extendedHeaderV24 = container.GetId3V24Descriptor();
                extendedHeaderV24.SetHeaderFlags(false, false, false, true);
            }

            // OK. Build the frames.
            var albumFrame = new TextFrame("TALB", data.Album, data.TextEncoding);
            var artistFrame = new TextFrame("TPE2", data.Artist, data.TextEncoding);
            var yearFrame = new TextFrame("TYER", data.Year, data.TextEncoding);
            var titleFrame = new TextFrame("TIT2", data.Title, data.TextEncoding);
            var textComment = new UserDefinedTextFrame("Your comment", data.Comment, data.TextEncoding);
            var comment = new CommentFrame("ENG", "Your Comment", data.Comment, data.TextEncoding);
            var encoder = new TextFrame("TENC", data.Encoder, data.TextEncoding);

            container.Add(albumFrame);
            container.Add(artistFrame);
            container.Add(yearFrame);
            container.Add(titleFrame);
            container.Add(textComment);
            container.Add(comment);
            container.Add(encoder);

            if (data.PictureFrameEnabled)
            {
                if (File.Exists(data.PictureFile))
                {
                    WritePictureFrame(data, container);
                }
                else
                {
                    MessageBox.Show("Picture file not found.");
                }
            }

            if (data.WriteLyricsFlag)
            {
                WriteUnsychronisedLyrics(data.LyricsDescriptor, data.Lyrics,container);
            }

            return container;
        }
Ejemplo n.º 12
0
        public void EncodeWithExtendedHeaderTest2()
        {
            //
            // Configure the tag
            //
            var tagContainer1 = new TagContainerV3();
            tagContainer1.Tag.SetHeaderFlags(true, true, true);
            tagContainer1.Tag.SetExtendedHeader(10, true);
            tagContainer1.Tag.SetCrc32(new byte[] {0x10, 0x20, 0x30, 0x40});

            var titleFrame = new TextFrame
                                 {
                                     Descriptor = {ID = "TIT2"},
                                     TextEncoding = Encoding.Unicode,
                                     Content = "Title1"
                                 };

            tagContainer1.Add(titleFrame);

            //
            // Write and read the tag again. 
            //
            var tagContainer2 = WriteAndRead(tagContainer1);

            //
            // Compare both container!
            //
            CompareContainer(tagContainer1, tagContainer2);
        }
Ejemplo n.º 13
0
        public void EncodeWithoutExtendedHeaderTest()
        {
            //
            // Configure the tag
            //
            var tagContainer1 = new TagContainerV3();
            tagContainer1.Tag.SetHeaderFlags(false, false, false);

            var titleFrame = new TextFrame
                                 {
                                     Descriptor = {ID = "TIT2"},
                                     TextEncoding = Encoding.Unicode,
                                     Content = "Title1"
                                 };

            tagContainer1.Add(titleFrame);

            //
            // Write and read the tag again. 
            //
            var tagContainer2 = WriteAndRead(tagContainer1);

            //
            // Compare both container!
            //
            CompareContainer(tagContainer1, tagContainer2);
        }
Ejemplo n.º 14
0
 private static IFrame AnalyseFrameId(RawFrame rawFrame)
 {
     IFrame frame;
     if (rawFrame.ID[0] == 'T' || rawFrame.ID[0] == 'W')
     {
         switch (rawFrame.ID[0])
         {
             case 'T':
                 if (rawFrame.ID != "TXXX")
                 {
                     frame = new TextFrame();
                 }
                 else
                 {
                     frame = new UserDefinedTextFrame();
                 }
                 break;
             case 'W':
                 if (rawFrame.ID != "WXXX")
                 {
                     frame = new UrlLinkFrame();
                 }
                 else
                 {
                     frame = new UserDefinedURLLinkFrame();
                 }
                 break;
             default:
                 throw new ID3TagException("Unknown Text or URL frame!");
         }
     }
     else
     {
         // Other frames
         switch (rawFrame.ID)
         {
             case "AENC":
                 frame = new AudioEncryptionFrame();
                 break;
             case "PRIV":
                 frame = new PrivateFrame();
                 break;
             case "MCDI":
                 frame = new MusicCdIdentifierFrame();
                 break;
             case "COMM":
                 frame = new CommentFrame();
                 break;
             case "APIC":
                 frame = new PictureFrame();
                 break;
             case "PCNT":
                 frame = new PlayCounterFrame();
                 break;
             case "POPM":
                 frame = new PopularimeterFrame();
                 break;
             case "UFID":
                 frame = new UniqueFileIdentifierFrame();
                 break;
             default:
                 frame = new UnknownFrame();
                 break;
         }
     }
     return frame;
 }
Ejemplo n.º 15
0
        public TagContainer BuildTag(ID3V2TagData data)
        {
            var tagController = new TagContainer();

            // Configure the tag header.
            tagController.Tag.SetVersion(3, 0);
            tagController.Tag.SetHeaderFlags(data.Unsynchronisation, data.ExtendedHeader, data.ExperimentalIndicator);

            if (data.ExtendedHeader)
            {
                tagController.Tag.SetExtendedHeader(data.PaddingSize, data.CrCPresent);
                tagController.Tag.SetCrc32(data.Crc);
            }

            // OK. Build the frames.
            var albumFrame = new TextFrame("TALB", data.Album, data.EncodingType);
            var artistFrame = new TextFrame("TPE2", data.Artist, data.EncodingType);
            var yearFrame = new TextFrame("TYER", data.Year, data.EncodingType);
            var titleFrame = new TextFrame("TIT2", data.Title, data.EncodingType);
            var textComment = new UserDefinedTextFrame("Your comment", data.Comment, data.EncodingType);
            var comment = new CommentFrame("ENG", "Your Comment", data.Comment, data.EncodingType);
            var encoder = new TextFrame("TENC", data.Encoder, data.EncodingType);

            tagController.Add(albumFrame);
            tagController.Add(artistFrame);
            tagController.Add(yearFrame);
            tagController.Add(titleFrame);
            tagController.Add(textComment);
            tagController.Add(comment);
            tagController.Add(encoder);

            if (data.PictureFrameEnabled)
            {
                if (File.Exists(data.PictureFile))
                {
                    WritePictureFrame(data, tagController);
                }
                else
                {
                    MessageBox.Show("Picture file not found.");
                }
            }

            return tagController;
        }