示例#1
0
        //http://id3.org/id3v2.4.0-structure
        private void Parse4(Stream stream)
        {
            HeaderLength = ID3Utils.ReadInt32(stream, false);
            byte[] flags = ID3Utils.Read(stream, 1);
            Flags = (ID3v2ExtendedHeaderFlags)flags[0];

            if ((Flags & ID3v2ExtendedHeaderFlags.CrcPresent) == ID3v2ExtendedHeaderFlags.CrcPresent)
            {
                CRC = ID3Utils.Read(stream, 5);
            }

            if ((Flags & ID3v2ExtendedHeaderFlags.Restrict) == ID3v2ExtendedHeaderFlags.Restrict)
            {
                //%ppqrrstt
                TagSizeRestriction       = (ID3v2TagSizeRestriction)(flags[0] & 0xC0);       //p --> last 2 bit
                TextEncodingRestriction  = (ID3v2TextEncodingRestriction)(flags[0] & 0x20);  //q
                TextFieldSizeRestriction = (ID3v2TextFieldSizeRestriction)(flags[0] & 0x18); //r
                ImageEncodingRestriction = (ID3v2ImageEncodingRestriction)(flags[0] & 0x4);  //s
                ImageSizeRestriction     = (ID3v2ImageSizeRestriction)(flags[0] & 0x3);      //t
            }

            if ((flags[0] & 0x8F) != 0)
            {
                throw new ID3Exception("Invalid Extendedheaderflags");
            }
        }
示例#2
0
        public Frame GetFrame(FrameHeader header, ID3Version version, Stream stream)
        {
            var frame = GetFrame(header.FrameID, version, header);

            frame.DecodeContent(ID3Utils.Read(stream, header.FrameSize));
            return(frame);
        }
示例#3
0
        protected void Decode(byte[] content, int offset, int count, Encoding encoding, out int read)
        {
            if (content.Length == 0)
            {
                throw new ID3Exception("Contentlength is zero");
            }

            Text = ID3Utils.ReadString(content, 0, content.Length - 1, ID3Utils.Iso88591, out read);
        }
示例#4
0
        public static ID3v2Header FromStream(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("stream not readable");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("stream not seekable");
            }

            BinaryReader reader = new BinaryReader(stream);
            ID3v2Header  header;

            byte[] buffer = new byte[HeaderLength];
            int    read   = stream.Read(buffer, 0, buffer.Length);

            if (read < 10)
            {
                throw new EndOfStreamException();
            }

            if (buffer[0] == 0x49 && //I
                buffer[1] == 0x44 && //D
                buffer[2] == 0x33)
            {
                header = new ID3v2Header();

                header.Version    = (ID3Version)buffer[3];
                header.RawVersion = new byte[] { buffer[3], buffer[4] };
                header.Flags      = (ID3v2HeaderFlags)buffer[5];

                /*header.DataLength = buffer[6] * (1 << 21);
                 * header.DataLength += buffer[7] * (1 << 14);
                 * header.DataLength += buffer[8] * (1 << 7);
                 * header.DataLength += buffer[9];
                 */
                header.DataLength = ID3Utils.ReadInt32(buffer, 6, true);

                return(header);
            }

            stream.Position -= read;
            return(null);
        }
示例#5
0
        private void Parse3(Stream stream)
        {
            HeaderLength = ID3Utils.ReadInt32(stream, false);
            byte[] flags = ID3Utils.Read(stream, 2);
            PaddingSize = ID3Utils.ReadInt32(stream, false);

            if ((flags[0] & 0x7F) != 0 || flags[1] != 0)
            {
                throw new ID3Exception("Invalid ExtendedHeaderflags");
            }
            //Flags = (ID3v2ExtendedHeaderFlags)flags[0];

            if ((flags[0] & 0x80) != 0)
            {
                Flags |= ID3v2ExtendedHeaderFlags.CrcPresent;
                CRC    = ID3Utils.Read(stream, 4);
            }
        }
示例#6
0
 private Image DecodeImage()
 {
     return(ID3Utils.DecodeImage(RawData, MimeType));
 }