/// <summary> /// Renders the current instance as an APEv2 item. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> public ByteVector Render() { uint flags = (uint)((ReadOnly) ? 1 : 0) | ((uint)Type << 1); if (IsEmpty) { return(new ByteVector()); } ByteVector result = null; if (_type == ItemType.Binary) { if (_text == null && _data != null) { result = _data; } } if (result == null && _text != null) { result = new ByteVector(); for (int i = 0; i < _text.Length; i++) { if (i != 0) { result.Add(0); } result.Add(ByteVector.FromString( _text [i], StringType.UTF8)); } } // If no data is stored, don't write the item. if (result == null || result.Count == 0) { return(new ByteVector()); } ByteVector output = new ByteVector(); output.Add(ByteVector.FromUInt((uint)result.Count, false)); output.Add(ByteVector.FromUInt(flags, false)); output.Add(ByteVector.FromString(_key, StringType.UTF8)); output.Add(0); output.Add(result); _sizeOnDisk = output.Count; return(output); }
public void CopyResize() { ByteVector a = new ByteVector(TestVector); ByteVector b = ByteVector.FromString("ABCDEFGHIJKL", StringType.UTF8); a.Resize(12); Assert.AreEqual(b, a); Assert.AreEqual(b.ToString(), a.ToString()); Assert.IsFalse(a.Count == TestVector.Count); }
protected override ByteVector RenderFields(byte version) { StringType encoding = CorrectEncoding(TextEncoding, version); ByteVector v = new ByteVector(); v.Add((byte)encoding); v.Add(ByteVector.FromString(Language, StringType.Latin1)); v.Add(ByteVector.FromString(text, encoding)); return(v); }
public void SetText(ByteVector type, string text) { if (string.IsNullOrEmpty(text)) { ilst_box.RemoveChild(FixId(type)); return; } ByteVectorCollection l = new ByteVectorCollection(); l.Add(ByteVector.FromString(text, StringType.UTF8)); SetData(type, l, (uint)AppleDataBox.FlagType.ContainsText); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { var encoding = CorrectEncoding(TextEncoding, version); var v = new ByteVector { (byte)encoding, ByteVector.FromString(Language, StringType.Latin1), ByteVector.FromString(Text, encoding) }; return(v); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { if (raw_data != null && raw_version == version) { return(raw_data); } StringType encoding = CorrectEncoding(TextEncoding, version); bool wxxx = FrameId == FrameType.WXXX; ByteVector v; if (wxxx) { v = new ByteVector((byte)encoding); } else { v = new ByteVector(); } string[] text = text_fields; if (version > 3 || wxxx) { if (wxxx) { if (text.Length == 0) { text = new string[] { null, null } } ; else if (text.Length == 1) { text = new string[] { text [0], null } } ; } v.Add(ByteVector.FromString( string.Join("/", text), StringType.Latin1)); } else { v.Add(ByteVector.FromString( string.Join("/", text), StringType.Latin1)); } return(v); }
protected override ByteVector RenderFields(byte version) { ByteVector data = ByteVector.FromULong(play_count); while (data.Count > 0 && data[0] == 0) { data.RemoveAt(0); } data.Insert(0, rating); data.Insert(0, 0); data.Insert(0, ByteVector.FromString(user, StringType.Latin1)); return(data); }
/// <summary> /// Renders the current instance to a <see cref="ByteVector"/> /// </summary> /// <param name="is_bigendian"> /// A <see cref="System.Boolean"/> indicating the endianess for rendering. /// </param> /// <param name="offset"> /// A <see cref="System.UInt32"/> with the offset, the data is stored. /// </param> /// <param name="type"> /// A <see cref="System.UInt16"/> the ID of the type, which is rendered /// </param> /// <param name="count"> /// A <see cref="System.UInt32"/> with the count of the values which are /// rendered. /// </param> /// <returns> /// A <see cref="ByteVector"/> with the rendered data. /// </returns> public ByteVector Render(bool is_bigendian, uint offset, out ushort type, out uint count) { type = (ushort)IFDEntryType.Undefined; ByteVector data = new ByteVector(); data.Add(COMMENT_UNICODE_CODE); data.Add(ByteVector.FromString(Value, StringType.UTF8)); count = (uint)data.Count; return(data); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { StringType encoding = CorrectEncoding(TextEncoding, version); var v = new ByteVector { (byte)encoding, ByteVector.FromString(Language, StringType.Latin1), ByteVector.FromString(description, encoding), ByteVector.TextDelimiter(encoding), ByteVector.FromString(text, encoding) }; return(v); }
/// <summary> /// Renders the current instance as a raw DivX tag. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered tag. /// </returns> public ByteVector Render() { ByteVector data = new ByteVector(); data.Add(ByteVector.FromString(title, StringType.Latin1).Resize(32, 0x20)); data.Add(ByteVector.FromString(artist, StringType.Latin1).Resize(28, 0x20)); data.Add(ByteVector.FromString(year, StringType.Latin1).Resize(4, 0x20)); data.Add(ByteVector.FromString(comment, StringType.Latin1).Resize(48, 0x20)); data.Add(ByteVector.FromString(genre, StringType.Latin1).Resize(3, 0x20)); data.Add(extra_data); data.Add(FileIdentifier); return(data); }
protected override ByteVector RenderFields(byte version) { if (version < 4) { throw new NotImplementedException(); } ByteVector data = new ByteVector(); data.Add(ByteVector.FromString(identification, StringType.Latin1)); data.Add(ByteVector.TextDelimiter(StringType.Latin1)); for (byte i = 0; i < 9; i++) { if (!channels [i].IsSet) { continue; } data.Add(i); unchecked { data.Add(ByteVector.FromUShort( (ushort)channels [i] .VolumeAdjustmentIndex)); } byte bits = 0; for (byte j = 0; j < 64; j++) { if ((channels [i].PeakVolumeIndex & (1UL << j)) != 0) { bits = (byte)(j + 1); } } data.Add(bits); if (bits > 0) { data.Add(ByteVector.FromULong( channels [i].PeakVolumeIndex) .Mid(8 - BitsToBytes(bits))); } } return(data); }
private void SetUfidText(string owner, string text) { UniqueFileIdentifierFrame frame = UniqueFileIdentifierFrame.Get(this, owner, true); if (!string.IsNullOrEmpty(text)) { ByteVector identifier = ByteVector.FromString(text, StringType.UTF8); frame.Identifier = identifier; } else { RemoveFrame(frame); } }
/// <summary> /// Renders the current instance as a raw DivX tag. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered tag. /// </returns> public ByteVector Render() { var data = new ByteVector { ByteVector.FromString(title, StringType.Latin1).Resize(32, 0x20), ByteVector.FromString(artist, StringType.Latin1).Resize(28, 0x20), ByteVector.FromString(year, StringType.Latin1).Resize(4, 0x20), ByteVector.FromString(comment, StringType.Latin1).Resize(48, 0x20), ByteVector.FromString(genre, StringType.Latin1).Resize(3, 0x20), extra_data, FileIdentifier }; return(data); }
/// <summary> /// Renders the current instance as a raw Xiph comment, /// optionally adding a framing bit. /// </summary> /// <param name="addFramingBit"> /// If <see langword="true" />, a framing bit will be added to /// the end of the content. /// </param> /// <returns> /// A <see cref="ByteVector"/> object containing the rendered /// version of the current instance. /// </returns> public ByteVector Render(bool addFramingBit) { ByteVector data = new ByteVector(); // Add the vendor ID length and the vendor ID. It's // important to use the length of the data(String::UTF8) // rather than the lenght of the the string since this // is UTF8 text and there may be more characters in the // data than in the UTF16 string. ByteVector vendor_data = ByteVector.FromString( vendor_id, StringType.UTF8); data.Add(ByteVector.FromUInt((uint)vendor_data.Count, false)); data.Add(vendor_data); // Add the number of fields. data.Add(ByteVector.FromUInt(FieldCount, false)); foreach (KeyValuePair <string, string[]> entry in field_list) { // And now iterate over the values of the // current list. foreach (string value in entry.Value) { ByteVector field_data = ByteVector.FromString( entry.Key, StringType.UTF8); field_data.Add((byte)'='); field_data.Add(ByteVector.FromString( value, StringType.UTF8)); data.Add(ByteVector.FromUInt((uint) field_data.Count, false)); data.Add(field_data); } } // Append the "framing bit". if (addFramingBit) { data.Add((byte)1); } return(data); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> /// <exception cref="NotImplementedException"> /// <paramref name="version" /> is less than 3. ID3v2.2 does /// not support this frame. /// </exception> protected override ByteVector RenderFields(byte version) { if (version < 3) { throw new NotImplementedException(); } ByteVector v = new ByteVector(); v.Add(ByteVector.FromString(owner, StringType.Latin1)); v.Add(ByteVector.TextDelimiter(StringType.Latin1)); v.Add(data); return(v); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> /// <exception cref="NotImplementedException"> /// <paramref name="version" /> is less than 3. ID3v2.2 does /// not support this frame. /// </exception> protected override ByteVector RenderFields(byte version) { if (version < 3) { throw new NotImplementedException(); } var v = new ByteVector { ByteVector.FromString(Owner, StringType.Latin1), ByteVector.TextDelimiter(StringType.Latin1), PrivateData }; return(v); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { if (raw_data != null && raw_version == version) { return(raw_data); } StringType encoding = CorrectEncoding(TextEncoding, version); ByteVector data = new ByteVector(); data.Add((byte)encoding); if (version == 2) { switch (MimeType) { case "image/png": data.Add("PNG"); break; case "image/jpeg": data.Add("JPG"); break; default: data.Add("XXX"); break; } } else { data.Add(ByteVector.FromString(MimeType, StringType.Latin1)); data.Add(ByteVector.TextDelimiter( StringType.Latin1)); } data.Add((byte)type); data.Add(ByteVector.FromString(Description, encoding)); data.Add(ByteVector.TextDelimiter(encoding)); data.Add(this.data); return(data); }
public ByteVector Render() { uint flags = (uint)((ReadOnly)?1:0) | ((uint)Type << 1); if (IsEmpty) { return(new ByteVector()); } ByteVector result = null; if (type == ItemType.Binary) { if (text == null && data != null) { result = data; } } if (result == null && text != null) { result = new ByteVector(); for (int i = 0; i < text.Length; i++) { if (i != 0) { result.Add((byte)0); } result.Add(ByteVector.FromString(text[i], StringType.UTF8)); } } if (result == null || result.Count == 0) { return(new ByteVector()); } ByteVector output = new ByteVector(); output.Add(ByteVector.FromUInt((uint)result.Count, false)); output.Add(ByteVector.FromUInt(flags, false)); output.Add(ByteVector.FromString(key, StringType.UTF8)); output.Add((byte)0); output.Add(result); size_on_disk = output.Count; return(output); }
protected override ByteVector RenderFields(byte version) { StringType encoding = CorrectEncoding(TextEncoding, version); ByteVector delim = ByteVector.TextDelimiter(encoding); ByteVector v = new ByteVector(); v.Add((byte)encoding); v.Add(ByteVector.FromString(Language, StringType.Latin1)); v.Add((byte)timestamp_format); v.Add((byte)lyrics_type); v.Add(ByteVector.FromString(description, encoding)); v.Add(delim); foreach (SynchedText t in text) { v.Add(ByteVector.FromString(t.Text, encoding)); v.Add(delim); v.Add(ByteVector.FromUInt((uint)t.Time)); } return(v); }
/// <summary> /// Creates a <see cref="ByteVector"/> for the Exif segment of this file /// </summary> /// <returns> /// A <see cref="ByteVector"/> with the whole Exif segment, if exif tags /// exists, otherwise null. /// </returns> ByteVector RenderExifSegment() { // Check, if IFD0 is contained IFDTag exif = ImageTag.Exif; if (exif == null) { return(null); } // first IFD starts at 8 uint first_ifd_offset = 8; // Render IFD0 // FIXME: store endianess and use it here var renderer = new IFDRenderer(true, exif.Structure, first_ifd_offset); ByteVector exif_data = renderer.Render(); uint segment_size = (uint)(first_ifd_offset + exif_data.Count + 2 + 6); // do not render data segments, which cannot fit into the possible segment size if (segment_size > ushort.MaxValue) { throw new Exception("Exif Segment is too big to render"); } // Create whole segment var data = new ByteVector(new byte[] { 0xFF, (byte)Marker.APP1 }) { ByteVector.FromUShort((ushort)segment_size), "Exif\0\0", ByteVector.FromString("MM", StringType.Latin1), ByteVector.FromUShort(42), ByteVector.FromUInt(first_ifd_offset), // Add ifd data itself exif_data }; return(data); }
public ByteVector Render() { ByteVector data = new ByteVector(); data.Add(ByteVector.FromUInt((uint)Type)); ByteVector mime_data = ByteVector.FromString(MimeType, StringType.Latin1); data.Add(ByteVector.FromUInt((uint)mime_data.Count)); data.Add(mime_data); ByteVector decription_data = ByteVector.FromString(Description, StringType.UTF8); data.Add(ByteVector.FromUInt((uint)decription_data.Count)); data.Add(decription_data); data.Add(ByteVector.FromUInt((uint)Width)); data.Add(ByteVector.FromUInt((uint)Height)); data.Add(ByteVector.FromUInt((uint)ColorDepth)); data.Add(ByteVector.FromUInt((uint)IndexedColors)); data.Add(ByteVector.FromUInt((uint)Data.Count)); data.Add(Data); return(data); }
private void SetTags(Mpeg4.AppleTag tag) { tag.Title = "TEST title"; tag.Performers = new string[] { "TEST performer 1", "TEST performer 2" }; tag.Comment = "TEST comment"; tag.Copyright = "TEST copyright"; tag.Genres = new string [] { "TEST genre 1", "TEST genre 2" }; tag.Year = 1999; Mpeg4.AppleTag atag = (Mpeg4.AppleTag)tag; Assert.IsNotNull(atag); Mpeg4.AppleDataBox newbox1 = new Mpeg4.AppleDataBox( ByteVector.FromString("TEST Long Description", StringType.UTF8), (int)Mpeg4.AppleDataBox.FlagType.ContainsText); Mpeg4.AppleDataBox newbox2 = new Mpeg4.AppleDataBox( ByteVector.FromString("TEST TV Show", StringType.UTF8), (int)Mpeg4.AppleDataBox.FlagType.ContainsText); atag.SetData(BOXTYPE_LDES, new Mpeg4.AppleDataBox[] { newbox1 }); atag.SetData(BOXTYPE_TVSH, new Mpeg4.AppleDataBox[] { newbox2 }); }
private ByteVector RenderCOMSegment() { JpegCommentTag com_tag = GetTag(TagTypes.JpegComment) as JpegCommentTag; if (com_tag == null) { return(null); } ByteVector com_data = ByteVector.FromString(com_tag.Value + "\0", StringType.Latin1); uint segment_size = (uint)(2 + com_data.Count); if (segment_size > ushort.MaxValue) { throw new Exception("Comment Segment is too big to render"); } ByteVector data = new ByteVector(new byte[] { 0xFF, (byte)Marker.COM }); data.Add(ByteVector.FromUShort((ushort)segment_size)); data.Add(com_data); return(data); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { var encoding = CorrectEncoding(TextEncoding, version); var delim = ByteVector.TextDelimiter(encoding); var v = new ByteVector { (byte)encoding, ByteVector.FromString(Language, StringType.Latin1), (byte)Format, (byte)Type, ByteVector.FromString(Description, encoding), delim }; foreach (SynchedText t in text) { v.Add(ByteVector.FromString(t.Text, encoding)); v.Add(delim); v.Add(ByteVector.FromUInt((uint)t.Time)); } return(v); }
/// <summary> /// Sets the text for a specified box type. /// </summary> /// <param name="type"> /// A <see cref="ByteVector" /> object containing the type to /// add to the new instance. /// </param> /// <param name="text"> /// A <see cref="string[]" /> containing text to store. /// </param> public void SetText(ByteVector type, string [] text) { // Remove empty data and return. if (text == null) { ilst_box.RemoveChild(FixId(type)); return; } // Create a list... ByteVectorCollection l = new ByteVectorCollection(); // and populate it with the ByteVectorized strings. foreach (string value in text) { l.Add(ByteVector.FromString(value, StringType.UTF8)); } // Send our final byte vectors to SetData SetData(type, l, (uint) AppleDataBox.FlagType.ContainsText); }
protected override ByteVector RenderFields(byte version) { StringType encoding = CorrectEncoding(this.encoding, version); ByteVector v = new ByteVector(); v.Add((byte)encoding); if (MimeType != null) { v.Add(ByteVector.FromString(MimeType, StringType.Latin1)); } v.Add(ByteVector.TextDelimiter(StringType.Latin1)); if (FileName != null) { v.Add(ByteVector.FromString(FileName, encoding)); } v.Add(ByteVector.TextDelimiter(encoding)); if (Description != null) { v.Add(ByteVector.FromString(Description, encoding)); } v.Add(ByteVector.TextDelimiter(encoding)); v.Add(data); return(v); }
/// <summary> /// Renders the values in the current instance into field /// data for a specified version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is to be encoded in. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered field data. /// </returns> protected override ByteVector RenderFields(byte version) { if (file != null) { Load(); } if (raw_data != null && raw_version == version) { return(raw_data); } StringType encoding = CorrectEncoding(TextEncoding, version); ByteVector data = new ByteVector(); if (header.FrameId == FrameType.APIC) { // Make an ID3v2 Attached Picture (APIC) data.Add((byte)encoding); if (version == 2) { string ext = Picture.GetExtensionFromMime(MimeType); data.Add(ext != null && ext.Length == 3 ? ext.ToUpper() : "XXX"); } else { data.Add(ByteVector.FromString(MimeType, StringType.Latin1)); data.Add(ByteVector.TextDelimiter(StringType.Latin1)); } data.Add((byte)type); data.Add(ByteVector.FromString(Description, encoding)); data.Add(ByteVector.TextDelimiter(encoding)); } else if (header.FrameId == FrameType.GEOB) { // Make an ID3v2 General Encapsulated Object (GEOB) data.Add((byte)encoding); if (MimeType != null) { data.Add(ByteVector.FromString(MimeType, StringType.Latin1)); } data.Add(ByteVector.TextDelimiter(StringType.Latin1)); if (filename != null) { data.Add(ByteVector.FromString(filename, encoding)); } data.Add(ByteVector.TextDelimiter(encoding)); if (Description != null) { data.Add(ByteVector.FromString(Description, encoding)); } data.Add(ByteVector.TextDelimiter(encoding)); } else { throw new InvalidOperationException("Bad Frame type"); } data.Add(this.data); return(data); }
public void Mid() { Assert.AreEqual(ByteVector.FromString("KLMNOPQRSTUVWXYZ", StringType.UTF8), TestVector.Mid(10)); Assert.AreEqual(ByteVector.FromString("PQRSTU", StringType.UTF8), TestVector.Mid(15, 6)); }
protected override ByteVector RenderFields(byte version) { if (raw_data != null && raw_version == version) { return(raw_data); } StringType encoding = CorrectEncoding(TextEncoding, version); ByteVector v = new ByteVector((byte)encoding); string [] text = text_fields; bool txxx = FrameId == FrameType.TXXX; if (version > 3 || txxx) { if (txxx) { if (text.Length == 0) { text = new string [] { null, null } } ; else if (text.Length == 1) { text = new string [] { text [0], null } } ; } for (int i = 0; i < text.Length; i++) { // Since the field list is null // delimited, if this is not the first // element in the list, append the // appropriate delimiter for this // encoding. if (i != 0) { v.Add(ByteVector.TextDelimiter( encoding)); } if (text [i] != null) { v.Add(ByteVector.FromString( text [i], encoding)); } } } else if (FrameId == FrameType.TCON) { byte id; bool prev_value_indexed = true; StringBuilder data = new StringBuilder(); foreach (string s in text) { if (!prev_value_indexed) { data.Append("/").Append(s); continue; } if (prev_value_indexed = byte.TryParse(s, out id)) { data.AppendFormat( CultureInfo.InvariantCulture, "({0})", id); } else { data.Append(s); } } v.Add(ByteVector.FromString(data.ToString(), encoding)); } else { v.Add(ByteVector.FromString( string.Join("/", text), encoding)); } return(v); }
/// <summary> /// Converts a <see cref="string" /> object to raw ID3v1 text /// data. /// </summary> /// <param name="text"> /// A <see cref="string" /> object to convert. /// </param> /// <returns> /// A <see cref="ByteVector"/> containing the raw ID3v1 text /// data. /// </returns> public virtual ByteVector Render(string text) { return(ByteVector.FromString(text, StringType.Latin1)); }