//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"); } }
public static string GetURL(byte[] RawData, string MimeType) { if (RawData == null) { throw new InvalidOperationException("Decode the frame first"); } if (MimeType != MimeURL) { throw new InvalidOperationException("MimeType != " + MimeURL); } return(ID3Utils.ReadString(RawData, 0, -1, ID3Utils.Iso88591)); }
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); }
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); } }