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;
        }
        public void CreateTest()
        {
            var frame = new CommentFrame("ENG", "ABCD", "EFGH", Encoding.Unicode);

            Assert.AreEqual(frame.Descriptor.ID, "COMM");
            Assert.AreEqual(frame.Language, "ENG");
            Assert.AreEqual(frame.ContentDescriptor, "ABCD");
            Assert.AreEqual(frame.Text, "EFGH");
            Assert.AreEqual(frame.TextEncoding, Encoding.Unicode);
        }
Beispiel #3
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 void ConvertUTF8Test()
        {
            var commentFrame = new CommentFrame();
            commentFrame.Descriptor.ID = "COMM";
            commentFrame.TextEncoding = new UTF8Encoding();
            commentFrame.ContentDescriptor = "ABCD";
            commentFrame.Text = "EFGH";
            commentFrame.Language = "eng";

            var rawFrame = commentFrame.Convert(TagVersion.Id3V23);
            Assert.AreEqual(rawFrame.ID, "COMM");

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

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
        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;
        }