示例#1
0
        /// <summary>
        /// Set the frame full text
        /// </summary>
        /// <param name="frameId">Frame type</param>
        /// <param name="message">Value set in frame</param>
        private void SetFullTextFrame(string frameId, string message)
        {
            var frame = FindFrame(frameId);

            if (frame != null)
            {
                if (!String.IsNullOrEmpty(message))
                {
                    FrameFullText framefulltext = (FrameFullText)frame;
                    framefulltext.Text        = message;
                    framefulltext.TextCode    = _textCode;
                    framefulltext.Description = string.Empty;
                    framefulltext.Language    = _language;
                }
                else
                {
                    _frameModel.Remove(frame);
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(message))
                {
                    FrameFullText frameLCText = (FrameFullText)FrameFactory.Build(frameId);
                    frameLCText.TextCode    = this._textCode;
                    frameLCText.Language    = "eng";
                    frameLCText.Description = string.Empty;
                    frameLCText.Text        = message;
                    _frameModel.Add(frameLCText);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Set the frame text
        /// </summary>
        /// <param name="frameId">Frame type</param>
        /// <param name="message">Value set in frame</param>
        private void SetTextFrame(string frameId, string message)
        {
            var frame = FindFrame(frameId);

            if (frame != null)
            {
                if (!String.IsNullOrEmpty(message))
                {
                    ((FrameText)frame).Text = message;
                }
                else
                {
                    _frameModel.Remove(frame);
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(message))
                {
                    FrameText frameText = (FrameText)FrameFactory.Build(frameId);
                    frameText.Text     = message;
                    frameText.TextCode = _textCode;
                    _frameModel.Add(frameText);
                }
            }
        }
        /// <summary>
        /// Create a frame depending on the tag form its binary representation.
        /// </summary>
        /// <param name="frameId">type of frame</param>
        /// <param name="flags">frame flags</param>
        /// <param name="frame">binary frame</param>
        /// <returns>Frame of tag type</returns>
        public FrameBase Build(string frameId, ushort flags, byte[] buffer)
        {
            // Build a frame
            var frame = FrameFactory.Build(frameId);

            SetFlags(frame, flags);

            uint   index  = 0;
            uint   size   = (uint)buffer.Length;
            Stream stream = new MemoryStream(buffer, false);
            var    reader = new BinaryReader(stream);

            if (GetGrouping(flags) == true)
            {
                frame.Group = reader.ReadByte();
                index++;
            }
            if (frame.Compression == true)
            {
                switch (Version)
                {
                case 3:
                {
                    size = Swap.UInt32(reader.ReadUInt32());
                    break;
                }

                case 4:
                {
                    size = Swap.UInt32(Sync.UnsafeBigEndian(reader.ReadUInt32()));
                    break;
                }

                default:
                {
                    throw new NotImplementedException("ID3v2 Version " + Version + " is not supported.");
                }
                }
                index  = 0;
                stream = new InflaterInputStream(stream);
            }
            if (frame.Encryption == true)
            {
                throw new NotImplementedException("Encryption is not implemented, consequently it is not supported.");
            }
            if (frame.Unsynchronisation == true)
            {
                var memoryStream = new MemoryStream();
                size  = Sync.Unsafe(stream, memoryStream, size);
                index = 0;
                memoryStream.Seek(0, SeekOrigin.Begin);
                stream = memoryStream;
            }
            byte[] frameBuffer = new byte[size - index];
            stream.Read(frameBuffer, 0, (int)(size - index));
            frame.Parse(frameBuffer);
            return(frame);
        }
示例#4
0
        internal FrameBase Build([NotNull] string frameId, ushort flags, [NotNull] byte[] buffer)
        {
            // Build a frame
            var frame = FrameFactory.Build(frameId);

            SetFlags(frame, flags);

            var    index          = 0;
            var    size           = (uint)buffer.Length;
            Stream stream         = new MemoryStream(buffer, false);
            var    streamsToClose = new List <Stream>(3)
            {
                stream
            };

            try
            {
                using (var reader = new BinaryReader(stream, Encoding.UTF8, false))
                {
                    if (GetGrouping(flags))
                    {
                        frame.Group = reader.ReadByte();
                        index++;
                    }

                    if (frame.Compression)
                    {
                        switch (_version)
                        {
                        case 3:
                            size = Swap.UInt32(reader.ReadUInt32());
                            break;

                        case 4:
                            size = Swap.UInt32(Sync.UnsafeBigEndian(reader.ReadUInt32()));
                            break;

                        default:
                            throw new NotImplementedException($"ID3v2 Version {_version} is not supported.");
                        }
                        index  = 0;
                        stream = new InflaterInputStream(stream);
                        streamsToClose.Add(stream);
                    }

                    if (frame.Encryption)
                    {
                        throw new NotImplementedException(
                                  "Encryption is not implemented, consequently it is not supported.");
                    }

                    if (frame.Unsynchronisation)
                    {
                        var memoryStream = new MemoryStream();
                        streamsToClose.Add(memoryStream);
                        size  = Sync.Unsafe(stream, memoryStream, size);
                        index = 0;
                        memoryStream.Seek(0, SeekOrigin.Begin);
                        stream = memoryStream;
                    }

                    var frameBuffer = new byte[size - index];
                    stream.Read(frameBuffer, 0, (int)(size - index));
                    frame.Parse(frameBuffer);
                    return(frame);
                }
            }
            finally
            {
                foreach (var streamToClose in streamsToClose)
                {
                    streamToClose.Close();
                }
            }
        }
示例#5
0
        /// <summary>
        /// Create a frame depending on the tag form its binary representation.
        /// </summary>
        /// <param name="frameId">type of frame</param>
        /// <param name="flags">frame flags</param>
        /// <param name="frame">binary frame</param>
        /// <returns>Frame of tag type</returns>
        public IFrame Build(string frameId, ushort options, byte[] frame)
        {
            // Build a frame
            IFrame frameBase = FrameFactory.Build(frameId);

            frameBase.Flags = options;

            flagHandler.Flags = options;
            uint         index  = 0;
            uint         size   = (uint)frame.Length;
            Stream       stream = new MemoryStream(frame, false);
            BinaryReader reader = new BinaryReader(stream);

            if (flagHandler.Grouping == true)
            {
                //TODO: Implement grouping when watching grass grow stops beeing intresting.
                /* The byte readed here is the group, we are skiping it for now*/
                reader.ReadByte();
                index++;
            }
            if (flagHandler.Compression == true)
            {
                switch (flagHandler.Version)
                {
                case 3:
                {
                    size = Swap.UInt32(reader.ReadUInt32());
                    break;
                }

                case 4:
                {
                    size = Swap.UInt32(Sync.UnsafeBigEndian(reader.ReadUInt32()));
                    break;
                }

                default:
                {
                    throw new NotImplementedException("ID3v2 Version " + flagHandler.Version + " is not supported.");
                }
                }
                index  = 0;
                stream = new InflaterInputStream(stream);
            }
            if (flagHandler.Encryption == true)
            {
                //TODO: Encryption
                throw new NotImplementedException("Encryption is not implemented, consequently it is not supported.");
            }
            if (flagHandler.Unsynchronisation == true)
            {
                Stream memStream = new MemoryStream();
                size   = Sync.Unsafe(stream, memStream, size);
                index  = 0;
                stream = memStream;
            }
            byte[] frameBuffer = new byte[size - index];
            stream.Read(frameBuffer, 0, (int)(size - index));
            frameBase.Parse(frameBuffer);
            return(frameBase);
        }