public static TextInformationFrame Get(Tag tag, ByteVector ident, StringType encoding, bool create) { if (tag == null) { throw new ArgumentNullException("tag"); } if (ident == null) { throw new ArgumentNullException("ident"); } if (ident.Count != 4) { throw new ArgumentException("Identifier must be four bytes long.", "ident"); } foreach (TextInformationFrame frame in tag.GetFrames <TextInformationFrame>(ident)) { return(frame); } if (!create) { return(null); } TextInformationFrame new_frame = new TextInformationFrame(ident, encoding); tag.AddFrame(new_frame); return(new_frame); }
public override Frame Clone() { TextInformationFrame frame = (this is UserTextInformationFrame)?new UserTextInformationFrame(null, encoding):new TextInformationFrame(FrameId, encoding); frame.text_fields = (string[])text_fields.Clone(); if (raw_data != null) { frame.raw_data = new ByteVector(raw_data); } frame.raw_version = raw_version; return(frame); }
public string GetTextAsString(ByteVector ident) { Frame frame; if (ident[0] == 'W') { frame = UrlLinkFrame.Get(this, ident, false); } else { frame = TextInformationFrame.Get(this, ident, false); } string result = frame == null?null:frame.ToString(); return(string.IsNullOrEmpty(result)?null:result); }
public override ByteVector Render(byte version) { if (version != 3 || FrameId != FrameType.TDRC) { return(base.Render(version)); } string text = ToString(); if (text.Length < 10 || text [4] != '-' || text [7] != '-') { return(base.Render(version)); } ByteVector output = new ByteVector(); TextInformationFrame f; f = new TextInformationFrame(FrameType.TYER, encoding); f.Text = new string [] { text.Substring(0, 4) }; output.Add(f.Render(version)); f = new TextInformationFrame(FrameType.TDAT, encoding); f.Text = new string [] { text.Substring(5, 2) + text.Substring(8, 2) }; output.Add(f.Render(version)); if (text.Length < 16 || text [10] != 'T' || text [13] != ':') { return(output); } f = new TextInformationFrame(FrameType.TIME, encoding); f.Text = new string [] { text.Substring(11, 2) + text.Substring(14, 2) }; output.Add(f.Render(version)); return(output); }
public void SetTextFrame(ByteVector ident, params string[] text) { if (ident == null) { throw new ArgumentNullException("ident"); } if (ident.Count != 4) { throw new ArgumentException("Identifier must be four bytes long.", "ident"); } bool empty = true; if (text != null) { for (int i = 0; empty && i < text.Length; i++) { if (!string.IsNullOrEmpty(text[i])) { empty = false; } } } if (empty) { RemoveFrames(ident); return; } if (ident[0] == 'W') { UrlLinkFrame urlFrame = UrlLinkFrame.Get(this, ident, true); urlFrame.Text = text; urlFrame.TextEncoding = DefaultEncoding; return; } TextInformationFrame frame = TextInformationFrame.Get(this, ident, true); frame.Text = text; frame.TextEncoding = DefaultEncoding; }
public override Frame Clone () { TextInformationFrame frame = new TextInformationFrame ( FrameId, encoding); frame.text_fields = (string[]) text_fields.Clone (); if (raw_data != null) frame.raw_data = new ByteVector (raw_data); frame.raw_version = raw_version; return frame; }
/// <summary> /// Gets a <see cref="TextInformationFrame" /> object of a /// specified type from a specified tag, optionally creating /// and adding one with a specified encoding if none is /// found. /// </summary> /// <param name="tag"> /// A <see cref="Tag" /> object to search for the specified /// tag in. /// </param> /// <param name="ident"> /// A <see cref="ByteVector" /> object containing the frame /// identifer to search for. /// </param> /// <param name="encoding"> /// A <see cref="StringType" /> value specifying the encoding /// to use if a new frame is created. /// </param> /// <param name="create"> /// A <see cref="bool" /> value specifying whether or not to /// create a new frame if an existing frame was not found. /// </param> /// <returns> /// A <see cref="TextInformationFrame" /> object containing /// the frame found in or added to <paramref name="tag" /> or /// <see langref="null" /> if no value was found <paramref /// name="create" /> is <see langref="false" />. /// </returns> /// <remarks> /// To create a frame without having to specify the encoding, /// use <see cref="Get(Tag,ByteVector,bool)" />. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="tag" /> or <paramref name="type" /> is /// <see langref="null" />. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="type" /> is not exactly four bytes long. /// </exception> public static TextInformationFrame Get (Tag tag, ByteVector ident, StringType encoding, bool create) { if (tag == null) throw new ArgumentNullException ("tag"); if (ident == null) throw new ArgumentNullException ("ident"); if (ident.Count != 4) throw new ArgumentException ( "Identifier must be four bytes long.", "ident"); foreach (TextInformationFrame frame in tag.GetFrames<TextInformationFrame> (ident)) return frame; if (!create) return null; TextInformationFrame new_frame = new TextInformationFrame (ident, encoding); tag.AddFrame (new_frame); return new_frame; }
public override ByteVector Render (byte version) { if (version != 3 || FrameId != FrameType.TDRC) return base.Render (version); string text = ToString (); if (text.Length < 10 || text [4] != '-' || text [7] != '-') return base.Render (version); ByteVector output = new ByteVector (); TextInformationFrame f; f = new TextInformationFrame (FrameType.TYER, encoding); f.Text = new string [] {text.Substring (0, 4)}; output.Add (f.Render (version)); f = new TextInformationFrame (FrameType.TDAT, encoding); f.Text = new string [] { text.Substring (5, 2) + text.Substring (8, 2) }; output.Add (f.Render (version)); if (text.Length < 16 || text [10] != 'T' || text [13] != ':') return output; f = new TextInformationFrame (FrameType.TIME, encoding); f.Text = new string [] { text.Substring (11, 2) + text.Substring (14, 2) }; output.Add (f.Render (version)); return output; }
public void TestTextInformationFrame () { ByteVector id = "TPE2"; TextInformationFrame frame = new TextInformationFrame (id); frame.Text = val_mult; FrameTest (frame, 2, delegate (Frame f, StringType e) { (f as TextInformationFrame).TextEncoding = e; }, delegate (ByteVector d, byte v) { return new TextInformationFrame (d, v); }, delegate (Frame f, string m) { TextInformationFrame g = (f as TextInformationFrame); Assert.AreEqual (id, g.FrameId, m); Assert.AreEqual (val_mult.Length, g.Text.Length, m); for (int i = 0; i < val_mult.Length; i ++) { Assert.AreEqual (val_mult [i], g.Text [i], m); } }); }
public static TextInformationFrame Get(TagLib.Id3v2.Tag tag, ByteVector ident, StringType encoding, bool create) { if (tag == null) { throw new ArgumentNullException("tag"); } if (ident == null) { throw new ArgumentNullException("ident"); } if (ident.Count != 4) { throw new ArgumentException("Identifier must be four bytes long.", "ident"); } IEnumerator<TextInformationFrame> enumerator = tag.GetFrames<TextInformationFrame>(ident).GetEnumerator(); try { while (enumerator.MoveNext()) { return enumerator.Current; } } finally { if (enumerator == null) { } enumerator.Dispose(); } if (!create) { return null; } TextInformationFrame frame = new TextInformationFrame(ident, encoding); tag.AddFrame(frame); return frame; }
public override ByteVector Render(byte version) { if ((version != 3) || (base.FrameId != FrameType.TDRC)) { return base.Render(version); } string str = this.ToString(); if (((str.Length < 10) || (str[4] != '-')) || (str[7] != '-')) { return base.Render(version); } ByteVector vector = new ByteVector(); TextInformationFrame frame = new TextInformationFrame(FrameType.TYER, this.encoding); frame.Text = new string[] { str.Substring(0, 4) }; vector.Add(frame.Render(version)); frame = new TextInformationFrame(FrameType.TDAT, this.encoding); frame.Text = new string[] { str.Substring(5, 2) + str.Substring(8, 2) }; vector.Add(frame.Render(version)); if (((str.Length >= 0x10) && (str[10] == 'T')) && (str[13] == ':')) { frame = new TextInformationFrame(FrameType.TIME, this.encoding); frame.Text = new string[] { str.Substring(11, 2) + str.Substring(14, 2) }; vector.Add(frame.Render(version)); } return vector; }
private string[] GetTextAsArray(ByteVector ident) { TextInformationFrame frame = TextInformationFrame.Get(this, ident, false); return(frame == null?new string[0]:frame.Text); }
protected void Parse(ByteVector data) { if (data == null) { throw new ArgumentNullException("data"); } bool fullTagUnsynch = (header.MajorVersion < 4) && ((header.Flags & HeaderFlags.Unsynchronisation) != 0); if (fullTagUnsynch) { SynchData.ResynchByteVector(data); } int frame_data_position = 0; int frame_data_length = data.Count; if ((header.Flags & HeaderFlags.ExtendedHeader) != 0) { extended_header = new ExtendedHeader(data, header.MajorVersion); if (extended_header.Size <= data.Count) { frame_data_position += (int)extended_header.Size; frame_data_length -= (int)extended_header.Size; } } TextInformationFrame tdrc = null; TextInformationFrame tyer = null; TextInformationFrame tdat = null; TextInformationFrame time = null; while (frame_data_position < frame_data_length - FrameHeader.Size(header.MajorVersion)) { if (data[frame_data_position] == 0) { break; } Frame frame = null; try { frame = FrameFactory.CreateFrame(data, ref frame_data_position, header.MajorVersion, fullTagUnsynch); } catch (NotImplementedException) { continue; } catch (CorruptFileException) { continue; } if (frame == null) { break; } if (frame.Size == 0) { continue; } AddFrame(frame); if (header.MajorVersion == 4) { continue; } if (tdrc == null && frame.FrameId.Equals(FrameType.TDRC)) { tdrc = frame as TextInformationFrame; } else if (tyer == null && frame.FrameId.Equals(FrameType.TYER)) { tyer = frame as TextInformationFrame; } else if (tdat == null && frame.FrameId.Equals(FrameType.TDAT)) { tdat = frame as TextInformationFrame; } else if (time == null && frame.FrameId.Equals(FrameType.TIME)) { time = frame as TextInformationFrame; } } if (tdrc == null || tdat == null || tdrc.ToString().Length > 4) { return; } string year = tdrc.ToString(); if (year.Length != 4) { return; } StringBuilder tdrc_text = new StringBuilder(); tdrc_text.Append(year); if (tdat != null) { string tdat_text = tdat.ToString(); if (tdat_text.Length == 4) { tdrc_text.Append("-").Append(tdat_text, 0, 2).Append("-").Append(tdat_text, 2, 2); if (time != null) { string time_text = time.ToString(); if (time_text.Length == 4) { tdrc_text.Append("T").Append(time_text, 0, 2).Append(":").Append(time_text, 2, 2); } RemoveFrames(FrameType.TIME); } } RemoveFrames(FrameType.TDAT); } tdrc.Text = new string[] { tdrc_text.ToString() }; }