Ejemplo n.º 1
0
        public void ValidationOKTest()
        {
            /*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

            var tagContainer = new TagContainerV3();
            tagContainer.Tag.SetExtendedHeader(0, false);
            tagContainer.Tag.SetHeaderOptions(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!
        }
        public void Convert_ISO8859_1_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = Encoding.Default;
            frame.Descriptor.Id = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

            RawFrame rawFrame = frame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TXXX");
            Assert.AreEqual(rawFrame.Payload.Count, 10);
            Assert.AreEqual(rawFrame.Payload[0], 0); // ISO coding
        }
        public void Convert_UTF16_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = Encoding.Unicode;
            frame.Descriptor.Id = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

            RawFrame rawFrame = frame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TXXX");
            Assert.AreEqual(rawFrame.Payload[0], 1); // ISO coding
            Assert.AreEqual(rawFrame.Payload[1], 0xFF); // BOM 1
            Assert.AreEqual(rawFrame.Payload[2], 0xFE); // BOM 2
            Assert.AreEqual(rawFrame.Payload.Count, 21);
        }
        public void Convert_UTF8_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = Encoding.UTF8;
            frame.Descriptor.Id = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

            RawFrame rawFrame = frame.Convert(TagVersion.Id3V23);

            Assert.AreEqual(rawFrame.Id, "TXXX");

            var refBytes = new byte[]
                               {
                                   0x03,
                                   0x41, 0x42, 0x43, 0x44,
                                   0x00,
                                   0x45, 0x46, 0x47, 0x48
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
Ejemplo n.º 5
0
        public TagContainer BuildTag(ID3V2TagData data)
        {
            TagContainer container = Id3TagFactory.CreateId3Tag(data.Version);
            if (data.Version == TagVersion.Id3V23)
            {
                //
                //  Configure the ID3v2.3 header
                //
                TagDescriptorV3 extendedHeaderV23 = container.GetId3V23Descriptor();
                // Configure the tag header.
                extendedHeaderV23.SetHeaderOptions(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
                //
                TagDescriptorV4 extendedHeaderV24 = container.GetId3V24Descriptor();
                extendedHeaderV24.SetHeaderOptions(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;
        }
        public void CreateTest()
        {
            var frame = new UserDefinedTextFrame("ABCD", "EFGH", Encoding.Unicode);

            Assert.AreEqual(frame.Descriptor.Id, "TXXX");
            Assert.AreEqual(frame.Description, "ABCD");
            Assert.AreEqual(frame.Value, "EFGH");
            Assert.AreEqual(frame.TextEncoding, Encoding.Unicode);
        }