Beispiel #1
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!
		}
        public void Convert_ISO8859_1_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = TextEncodingType.ISO_8859_1;
            frame.Descriptor.ID = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

            var rawFrame = frame.Convert();

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

            var rawFrame = frame.Convert();

            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.Length, 21);
        }
        public void Convert_UTF8_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = TextEncodingType.UTF8;
            frame.Descriptor.ID = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

            var rawFrame = frame.Convert();

            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));
        }
        public void Convert_UTF16BE_Test()
        {
            var frame = new UserDefinedTextFrame();
            frame.TextEncoding = Encoding.BigEndianUnicode;
            frame.Descriptor.ID = "TXXX";
            frame.Description = "ABCD";
            frame.Value = "EFGH";

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

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

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

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
Beispiel #6
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!
        }
        public void CreateTest()
        {
            var frame = new UserDefinedTextFrame("ABCD", "EFGH", TextEncodingType.UTF16);

            Assert.AreEqual(frame.Descriptor.ID, "TXXX");
            Assert.AreEqual(frame.Description, "ABCD");
            Assert.AreEqual(frame.Value, "EFGH");
            Assert.AreEqual(frame.TextEncoding, TextEncodingType.UTF16);
        }
        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;
        }
Beispiel #9
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;
 }
        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;
        }