Exemplo n.º 1
0
        /// <summary>
        /// Internally parses the current data and loads all fields.
        /// </summary>
        protected void ParseData()
        {
            if ((m_Data[0] != (byte)'I') || (m_Data[1] != (byte)'D') || (m_Data[2] != (byte)'3'))
            {
                throw new InvalidDataException(string.Format("Missing ID3 identifier!"));
            }

            Version    = m_Data[3];
            m_Revision = m_Data[4];
            Flags      = CheckFlags(m_Data[5]);
            m_BodySize = ID3v2DeUnsync.Int32(m_Data, 6);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses the specified buffer starting at index to load all data for this frame
        /// This function will throw exceptions on parser errors.
        /// </summary>
        /// <param name="reader">FrameReader to read from.</param>
        void ParseVersion4(DataFrameReader reader)
        {
            if ((m_Header.TagHeader.Flags & ID3v2HeaderFlags.Unsynchronisation) == 0)
            {
                // no full unsync done, check if we have to unsync now
                if (m_Header.Flags.Unsynchronisation)
                {
                    m_Content = ID3v2DeUnsync.Buffer(m_Content);
                }
            }
            if (m_Header.Flags.Compression)
            {
                m_Content = Decompress(m_Content);
            }

            if (m_Header.Flags.Encryption)
            {
                m_Content = Decrypt(m_Content);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the header (check <see cref="State"/> before usage).
        /// </summary>
        /// <returns></returns>
        public ID3v2Header ReadHeader(out byte[] tagData)
        {
            if (State != ID3v2ReaderState.ReadHeader)
            {
                throw new InvalidOperationException(string.Format("Cannot read header at state {0}", State));
            }

            var header = new ID3v2Header();

            if (!header.Parse(m_Reader))
            {
                tagData = null;
                return(null);
            }
            m_BodyBytes = header.BodySize;
            if ((header.Flags & ID3v2HeaderFlags.Footer) != 0)
            {
                m_BodyBytes -= 10;
            }
            State++;
            if (header.Version < 2)
            {
                tagData = null;
                return(null);
            }

            tagData = m_Reader.GetBuffer(header.HeaderSize + header.BodySize);
            var bodyData = tagData.GetRange(header.HeaderSize);

            // need to unsync whole tag?
            if ((header.Flags & ID3v2HeaderFlags.Unsynchronisation) != 0)
            {
                bodyData    = ID3v2DeUnsync.Buffer(bodyData);
                m_BodyBytes = bodyData.Length;
            }

            // update reader (use cached data)
            m_Header = header;
            m_Reader = new DataFrameReader(bodyData);
            return(header);
        }
Exemplo n.º 4
0
        bool ParseVersion4(DataFrameReader reader)
        {
            if (!reader.EnsureBuffer(4))
            {
                return false;
            }

            // calc size
            int size = ID3v2DeUnsync.Int32(reader.Read(0, 4), 0);

            // get data
            if (!reader.EnsureBuffer(size))
            {
                return false;
            }

            m_Data = reader.GetBuffer(size);

            // get flags
            m_Flags = ID3v2ExtendedHeaderFlags.FromID3v24(m_Data);
            return true;
        }