Skip to content

Commit a3b5676

Browse files
morganaloriLORICARROLLA016\lcarroll
andauthored
Audio Id3v2 add support for the Tag Length (#284)
* Id3v2 - add support for the Tag Length * AddLendthTagId3v2 fix test formatting * audioId3v2 - fix comment for length Co-authored-by: LORICARROLLA016\lcarroll <[email protected]>
1 parent ab49830 commit a3b5676

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,34 @@ public void TestISRC ()
996996
}
997997
}
998998

999+
[Test]
1000+
public void TestLength ()
1001+
{
1002+
Tag tag = new Tag ();
1003+
for (byte version = 2; version <= 4; version++) {
1004+
tag.Version = version;
1005+
1006+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1007+
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
1008+
Assert.IsNull (t.Length, "Initial (Null): " + m);
1009+
});
1010+
1011+
tag.Length = val_sing;
1012+
1013+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1014+
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
1015+
Assert.AreEqual (val_sing, t.Length, "Value Set (!Null): " + m);
1016+
});
1017+
1018+
tag.Length = string.Empty;
1019+
1020+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1021+
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
1022+
Assert.IsNull (t.Length, "Value Cleared (Null): " + m);
1023+
});
1024+
}
1025+
}
1026+
9991027
[Test]
10001028
public void TestRemixedBy ()
10011029
{
@@ -1049,6 +1077,7 @@ public void TestClear ()
10491077
InitialKey = "K",
10501078
Publisher = "L",
10511079
ISRC = "M",
1080+
Length = "L",
10521081
RemixedBy = "N"
10531082
};
10541083

@@ -1078,6 +1107,7 @@ public void TestClear ()
10781107
Assert.IsNull (tag.InitialKey, "InitialKey");
10791108
Assert.IsNull (tag.Publisher, "Publisher");
10801109
Assert.IsNull (tag.ISRC, "ISRC");
1110+
Assert.IsNull (tag.Length, "Length");
10811111
Assert.IsNull (tag.RemixedBy, "RemixedBy");
10821112
}
10831113

src/TaglibSharp/CombinedTag.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,45 @@ public override string ISRC {
19801980
}
19811981
}
19821982

1983+
/// <summary>
1984+
/// Gets and sets the length of the media
1985+
/// represented by the current instance.
1986+
/// </summary>
1987+
/// <value>
1988+
/// A <see cref="string" /> object containing the
1989+
/// length of the media represented by the current
1990+
/// instance or <see langword="null" /> if no value present.
1991+
/// </value>
1992+
/// <remarks>
1993+
/// <para>When getting the value, the child tags are looped
1994+
/// through in order and the first non-<see langword="null" />
1995+
/// value is returned.</para>
1996+
/// <para>When setting the value, it is stored in each child
1997+
/// tag.</para>
1998+
/// </remarks>
1999+
/// <seealso cref="Tag.Length" />
2000+
public override string Length {
2001+
get {
2002+
foreach (Tag tag in tags) {
2003+
if (tag == null)
2004+
continue;
2005+
2006+
string value = tag.Length;
2007+
2008+
if (value != null)
2009+
return value;
2010+
}
2011+
2012+
return null;
2013+
}
2014+
2015+
set {
2016+
foreach (Tag tag in tags)
2017+
if (tag != null)
2018+
tag.Length = value;
2019+
}
2020+
}
2021+
19832022
/// <summary>
19842023
/// Gets whether or not the current instance is empty.
19852024
/// </summary>

src/TaglibSharp/Id3v2/FrameTypes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static class FrameType
6565
public static readonly ReadOnlyByteVector TIT3 = "TIT3";
6666
public static readonly ReadOnlyByteVector TIME = "TIME";
6767
public static readonly ReadOnlyByteVector TKEY = "TKEY";
68+
public static readonly ReadOnlyByteVector TLEN = "TLEN"; // audio length
6869
public static readonly ReadOnlyByteVector TMCL = "TMCL";
6970
public static readonly ReadOnlyByteVector TOLY = "TOLY";
7071
public static readonly ReadOnlyByteVector TOPE = "TOPE";

src/TaglibSharp/Id3v2/Tag.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,25 @@ public override string ISRC {
22792279
set { SetTextFrame (FrameType.TSRC, value); }
22802280
}
22812281

2282+
/// <summary>
2283+
/// Gets and sets the length of the media represented
2284+
/// by the current instance.
2285+
/// </summary>
2286+
/// <value>
2287+
/// A <see cref="string" /> object containing the length of
2288+
/// the media represented by the current instance or <see
2289+
/// langword="null" /> if no value is present.
2290+
/// </value>
2291+
/// <remarks>
2292+
/// <para>This field represents the label or length of the album the
2293+
/// media belongs to. </para>
2294+
/// <para>For example, "00:15:00".</para>
2295+
/// </remarks>
2296+
public override string Length {
2297+
get { return GetTextAsString (FrameType.TLEN); }
2298+
set { SetTextFrame (FrameType.TLEN, value); }
2299+
}
2300+
22822301
/// <summary>
22832302
/// Gets and sets a collection of pictures associated with
22842303
/// the media represented by the current instance.

src/TaglibSharp/Tag.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,25 @@ public virtual string ISRC {
10591059
set { }
10601060
}
10611061

1062+
/// <summary>
1063+
/// Gets and sets the Length of the media represented
1064+
/// by the current instance.
1065+
/// </summary>
1066+
/// <value>
1067+
/// A <see cref="string" /> object containing the length of
1068+
/// the media represented by the current instance or <see
1069+
/// langword="null" /> if no value is present.
1070+
/// </value>
1071+
/// <remarks>
1072+
/// <para>This field represents the label or length of the album the
1073+
/// media belongs to. </para>
1074+
/// <para>For example, "00:15:00".</para>
1075+
/// </remarks>
1076+
public virtual string Length {
1077+
get { return null; }
1078+
set { }
1079+
}
1080+
10621081
/// <summary>
10631082
/// Gets and sets a collection of pictures associated with
10641083
/// the media represented by the current instance.

0 commit comments

Comments
 (0)