protected override void Decode(byte[] content) { if (content.Length == 0) { throw new ID3Exception("Contentlength is zero"); } var info = Header.GetFrameInformation(); bool url = false; url = (info != null) && info.ID == ID3.Frames.FrameID.UserURLLinkFrame; var encoding0 = ID3Utils.GetEncoding(content, 0, 1); Encoding encoding1 = encoding0; if (url) { encoding1 = ID3Utils.Iso88591; } int read; Description = ID3Utils.ReadString(content, 1, -1, encoding0, out read); if (content.Length < read + 1) { throw new ID3Exception("Frame does not contain any text"); } base.Decode(content, read + 1, -1, encoding1, out read); }
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); }
private void Parse2(Stream stream) { byte[] buffer = ID3Utils.Read(stream, 6); FrameID = ID3Utils.ReadString(buffer, 0, 3, ID3Utils.Iso88591); FrameSize = ID3Utils.ReadInt32(buffer, 3, false, 3); //Flags not supported Flags = FrameFlags.None; }
protected override void Decode(byte[] content) { int read; Encoding encoding = ID3Utils.GetEncoding(content, 0, 4); Language = ID3Utils.ReadString(content, 1, 3, ID3Utils.Iso88591); Description = ID3Utils.ReadString(content, 4, -1, encoding, out read); Text = ID3Utils.ReadString(content, read + 4, -1, encoding); }
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, encoding, out read); }
protected override void Decode(byte[] content) { if (content == null || content.Length < 1) { return; } Encoding encoding = ID3Utils.GetEncoding(content, 0, 1); int read; Decode(content, 0, -1, encoding, out read); }
protected override void Decode(byte[] content) { int offset = 0; var encoding = ID3Utils.GetEncoding(content, 0, 4); offset++; ID3Utils.ReadString(content, offset, 3, ID3Utils.Iso88591); offset += 3; Text = ID3Utils.ReadString(content, offset, -1, encoding); }
protected override void Decode(byte[] content) { int offset = 1; if (content.Length < 3) { throw new ID3Exception("Invalid contentlength id=0.");//id -> for debugging } int read; if (_version == ID3Version.ID3v2_2) { //MimeType = ID3Utils.ReadString(content, offset, 3, ID3Utils.Iso88591, out read); MimeType = ID3Utils.ReadString(content, offset, 3, ID3Utils.Iso88591, out read); offset += 3; } else { MimeType = ID3Utils.ReadString(content, 1, -1, ID3Utils.Iso88591, out read); offset += read; } if (content.Length < offset) { throw new ID3Exception("Invalid contentlength id=1."); } if (!Enum.IsDefined(typeof(PictureFormat), content[offset])) { throw new ID3Exception("Invalid pictureformat: 0x{0}", content[offset].ToString("x")); } Format = (PictureFormat)content[offset++]; if (content.Length < offset) { throw new ID3Exception("Invalid contentlength id=2."); } var descenc = ID3Utils.GetEncoding(content, 0, 2); Description = ID3Utils.ReadString(content, offset, -1, descenc, out read); offset += read; if (content.Length < offset) { throw new ID3Exception("Invalid contentlength id=3."); } RawData = new byte[content.Length - offset]; Array.Copy(content, offset, RawData, 0, RawData.Length); }
private void Parse4(Stream stream) { byte[] buffer = ID3Utils.Read(stream, 10); FrameID = ID3Utils.ReadString(buffer, 0, 4, ID3Utils.Iso88591); FrameSize = ID3Utils.ReadInt32(buffer, 4, true, 4); byte[] flags = new byte[] { buffer[8], buffer[9] }; //%0abc0000 Framestatusflags if ((flags[0] & 0x40) == 0) { Flags |= FrameFlags.PreserveTagAltered; } if ((flags[0] & 0x20) == 0) { Flags |= FrameFlags.PreserveFileAltered; } if ((flags[0] & 0x10) != 0) { Flags |= FrameFlags.ReadOnly; } //%0h00kmnp Frameformatflags if ((flags[1] & 0x40) != 0) { Flags |= FrameFlags.GroupIdentified; GroupIdentifier = ID3Utils.Read(stream, 1)[0]; FrameSize -= 1; } if ((flags[1] & 0x8) != 0) { Flags |= FrameFlags.Compressed; } if ((flags[1] & 0x4) != 0) { Flags |= FrameFlags.Encrypted; _encryptionMethod = ID3Utils.Read(stream, 1)[0]; FrameSize -= 1; } if ((flags[1] & 0x2) != 0) { Flags |= FrameFlags.UnsyncApplied; //todo: tag allgemein benachrichtigen? } if ((flags[1] & 0x1) != 0) { Flags |= FrameFlags.DataLengthIndicatorPresent; _dataLengthIndicator = ID3Utils.ReadInt32(stream, true); FrameSize -= 4; } }
protected override void Decode(byte[] content) { if (content.Length == 0) { throw new ID3Exception("Contentlength is zero"); } int read; OwnerIdentifier = ID3Utils.ReadString(content, 0, content.Length, ID3Utils.Iso88591, out read); Data = new byte[content.Length - read]; if (Data.Length > 0) { Array.Copy(content, read, Data, 0, Data.Length); } }
public static void WriteToStream(Tag value, StreamAccessor accessor, out System.Action <long> SetSize) { long pos_size; Stream stream = new MemoryStream(); StreamAccessor accessor2 = new StreamAccessor(stream); StreamAccessor accessor3 = null; long start = 0L; if (value.has_ext) { value.WriteExtHeader(accessor2, out accessor3); start = stream.Position; } foreach (Frame frame in value.frames.Values) { accessor2.WriteAs <Frame>(frame); } if (value.has_ext) { long length = stream.Position - start; accessor3.Write(ID3Utils.CalculateCRC32(stream, start, length), EncodingType.U4BE); accessor3.Stream.Close(); } bool unsync = ID3Utils.ID3RequiredUnsync(stream); if (unsync) { Stream stream2 = ID3Utils.ID3Unsynchronize(stream); stream.Close(); stream = stream2; } value.WriteTagHeader(accessor, unsync, out pos_size); SetSize = delegate(long size){ if (size > StreamAccessor.MaxUInt28) { throw new System.ArgumentOutOfRangeException("Tag の情報量が多すぎて保存できません。Tag の内容は 256MB より小さくなる様にして下さい"); } accessor.PushPosition(pos_size); accessor.Write((uint)size, EncodingType.UInt28BE); accessor.PopPosition(); }; accessor.WriteStream(stream); }
private void Parse3(Stream stream) { byte[] buffer = ID3Utils.Read(stream, 10); FrameID = ID3Utils.ReadString(buffer, 0, 4, ID3Utils.Iso88591); FrameSize = ID3Utils.ReadInt32(buffer, 4, false, 4); byte[] flags = new byte[] { buffer[8], buffer[9] }; //%abc00000 if ((flags[0] & 0x80) == 0) { Flags |= FrameFlags.PreserveTagAltered; } if ((flags[0] & 0x40) == 0) { Flags |= FrameFlags.PreserveFileAltered; } if ((flags[0] & 0x20) != 0) { Flags |= FrameFlags.ReadOnly; } //%ijk00000 if ((flags[1] & 0x80) != 0) { Flags |= FrameFlags.Compressed; _uncompressedSize = ID3Utils.ReadInt32(stream, false); FrameSize -= 4; } if ((flags[1] & 0x40) != 0) { Flags |= FrameFlags.Encrypted; _encryptionMethod = ID3Utils.Read(stream, 1)[0]; FrameSize -= 1; } if ((flags[1] & 0x20) != 0) { Flags |= FrameFlags.GroupIdentified; GroupIdentifier = ID3Utils.Read(stream, 1)[0]; FrameSize -= 1; } }
protected override void Decode(byte[] content) { int offset = 1; if (content.Length < 10) { throw new ID3Exception("Invalid Contentlength"); } int read; Price = ID3Utils.ReadString(content, offset, -1, ID3Utils.Iso88591, out read); offset += read; PurchaseDate = ID3Utils.ReadString(content, offset, 8, ID3Utils.Iso88591); offset += 8; var encoding = ID3Utils.GetEncoding(content, 0, offset); Text = ID3Utils.ReadString(content, offset, -1, encoding); }
protected override void Decode(byte[] content) { int offset = 0; int read; UserEmail = ID3Utils.ReadString(content, 0, -1, ID3Utils.Iso88591, out read); offset += read; Rating = content[offset]; offset++; if (offset < content.Length) { int pos = 0; for (int i = offset; i < content.Length; i++) { PlayedCounter |= ((uint)(content[i] << pos)); //cast to uint to fix warning CS0675 pos += 8; } } }
protected override void Decode(byte[] content) { int offset = 1; int read; Price = ID3Utils.ReadString(content, offset, -1, ID3Utils.Iso88591, out read); offset += read; IsValidUntil = ID3Utils.ReadString(content, offset, -1, ID3Utils.Iso88591, out read); offset += read; ContactURL = ID3Utils.ReadString(content, offset, -1, ID3Utils.Iso88591, out read); offset += read; ReceivedType = (ReceivedType)content[offset]; offset++; var encoding = ID3Utils.GetEncoding(content, 0, offset); offset++; SellerName = ID3Utils.ReadString(content, offset, -1, encoding, out read); offset += read; Description = ID3Utils.ReadString(content, offset, -1, encoding, out read); offset += read; if (offset < content.Length) { //we've got a attached logo LogoMimeType = ID3Utils.ReadString(content, offset, -1, ID3Utils.Iso88591, out read); offset += read; var logoData = new byte[content.Length - offset]; Array.Copy(content, offset, logoData, 0, logoData.Length); Image = ID3Utils.DecodeImage(logoData, LogoMimeType); } }
protected override void Decode(byte[] content) { Encoding e; int index = 1; Strings.Clear(); e = ID3Utils.GetEncoding(content, 0, 1); //int read = 0; //e = ID3Utils.GetEncoding2(content, 0, out read); //index = read; while (index < content.Length) { int r = 0; Strings.Add(ID3Utils.ReadString(content, index, -1, e, out r)); index += r; } if (Strings.Count == 0) { Strings.Add(String.Empty); } }
private Image DecodeImage() { return(ID3Utils.DecodeImage(RawData, MimeType)); }
public string GetURL() { return(ID3Utils.GetURL(RawData, MimeType)); }
public static Tag ReadFromStream(StreamAccessor accessor, out int tagsize) { Tag tag = new Tag(); bool unsync; int size; try{ size = tag.ReadTagHeader(accessor, out unsync); tagsize = size + 10; }catch (System.Exception e) { __dll__.log.WriteError(e, "TagHeader の読込に失敗しました。"); tagsize = 0; return(null); } System.IO.Stream str = accessor.ReadSubStream((long)size); StreamAccessor acc_str; if (unsync) { System.IO.Stream stream = ID3Utils.ID3ResolveUnsync(str); str.Close(); acc_str = new StreamAccessor(stream); } else { acc_str = new StreamAccessor(str); } if (tag.has_ext) { uint crc32; int padding; try{ tag.ReadExtHeader(acc_str, out crc32, out padding); }catch (Exception exception2) { exception = exception2; __dll__.log.WriteError(exception, "ExtendedHeader の読込に失敗しました。"); return(null); } if (tag.hascrc) { long crc_start = acc_str.Stream.Position; long crc_len = (acc_str.Stream.Length - crc_start) - padding; if (crc_len < 0L) { __dll__.log.WriteError(string.Format("Extended Header-Padding Size の値が不正です。大きすぎます:{0}", padding)); return(null); } if (crc32 != ID3Utils.CalculateCRC32(acc_str.Stream, crc_start, crc_len)) { __dll__.log.WriteError("ファイルの CRC32 値が一致しませんでした。"); return(null); } } } tag.frames = new afh.Collections.DictionaryP <string, Frame>(); while (true) { Frame val = acc_str.Read <Frame>(EncodingType.NoSpecified); if (val == Frame.EndOfFrames) { acc_str.Stream.Close(); return(tag); } tag.frames.Add(val.FrameId, val); } }