From a522fa6942d74074b9f1fcaffe864aba7386ee2f Mon Sep 17 00:00:00 2001
From: 42Geese <0E5EB1FB2C894978ADAD6308@gmail.com>
Date: Sun, 9 Apr 2023 20:51:55 -0400
Subject: [PATCH 1/2] Audio Id3v2 Add Support For The Release Date
---
.../TaggingFormats/Id3V2Test.cs | 34 ++++++++++++++-
src/TaglibSharp/Id3v2/FrameTypes.cs | 1 +
src/TaglibSharp/Id3v2/Tag.cs | 42 +++++++++++++++++++
3 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
index 8b2ea676..3808c001 100644
--- a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
+++ b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
@@ -18,6 +18,8 @@ public class Id3V2Test
static readonly string[] val_gnre = {"Rap",
"Jazz", "Non-Genre", "Blues"};
+ static readonly System.DateTime val_date = new System.DateTime (2022, 10, 20, 16, 45, 23, 0, 0);
+
[Test]
public void TestTitle ()
{
@@ -996,6 +998,34 @@ public void TestISRC ()
}
}
+ [Test]
+ public void TestReleaseDate ()
+ {
+ Tag tag = new Tag ();
+ for (byte version = 4; version <= 4; version++) {
+ tag.Version = version;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
+ Assert.IsNull (t.ReleaseDate, "Initial (Null): " + m);
+ }, 4);
+
+ tag.ReleaseDate = val_date;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
+ Assert.AreEqual (val_date, t.ReleaseDate.Value, "Value Set (!Null): " + m);
+ }, 4);
+
+ tag.ReleaseDate = null;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
+ Assert.IsNull (t.ReleaseDate, "Value Cleared (Null): " + m);
+ }, 4);
+ }
+ }
+
[Test]
public void TestLength ()
{
@@ -1634,10 +1664,10 @@ public void TestInvolvedPersonsFrame ()
delegate void TagTestFunc (Tag tag, string msg);
- void TagTestWithSave (ref Tag tag, TagTestFunc testFunc)
+ void TagTestWithSave (ref Tag tag, TagTestFunc testFunc, byte minVersion = 2)
{
testFunc (tag, "Before Save");
- for (byte version = 2; version <= 4; version++) {
+ for (byte version = minVersion; version <= 4; version++) {
tag.Version = version;
tag = new Tag (tag.Render ());
testFunc (tag, "After Save, Version: " + version);
diff --git a/src/TaglibSharp/Id3v2/FrameTypes.cs b/src/TaglibSharp/Id3v2/FrameTypes.cs
index 2fda85de..c4fa082c 100644
--- a/src/TaglibSharp/Id3v2/FrameTypes.cs
+++ b/src/TaglibSharp/Id3v2/FrameTypes.cs
@@ -101,5 +101,6 @@ static class FrameType
public static readonly ReadOnlyByteVector WPUB = "WPUB";
public static readonly ReadOnlyByteVector WXXX = "WXXX";
public static readonly ReadOnlyByteVector ETCO = "ETCO";
+ public static readonly ReadOnlyByteVector TDRL = "TDRL"; // Release Time Frame
}
}
diff --git a/src/TaglibSharp/Id3v2/Tag.cs b/src/TaglibSharp/Id3v2/Tag.cs
index 1c3676ff..4de95832 100644
--- a/src/TaglibSharp/Id3v2/Tag.cs
+++ b/src/TaglibSharp/Id3v2/Tag.cs
@@ -2279,6 +2279,48 @@ public override string ISRC {
set { SetTextFrame (FrameType.TSRC, value); }
}
+ ///
+ /// Gets and sets the date at which the song has been released.
+ ///
+ ///
+ /// A nullable object containing the
+ /// date at which the song has been released, or if no value present.
+ ///
+ ///
+ /// This property is implemented using the "TDRL" field.
+ /// This is a ID3v2.4 type tag.
+ ///
+ public DateTime? ReleaseDate {
+ get {
+ string value = GetTextAsString (FrameType.TDRL);
+
+ if (String.IsNullOrWhiteSpace(value)) {
+ return null;
+ } else if (DateTime.TryParseExact (value.Replace ('T', ' '), "yyyy-MM-dd HH:mm:ss", null, DateTimeStyles.None, out DateTime exactDate)) {
+ return exactDate;
+ } else if (DateTime.TryParse(value, out DateTime parsedDate)) {
+ return parsedDate;
+ }
+
+ return null;
+ }
+ set {
+ string date = null;
+
+ if (value != null) {
+ date = $"{value:yyyy-MM-dd HH:mm:ss}";
+ date = date.Replace (' ', 'T');
+ }
+
+ if (date == null) {
+ RemoveFrames(FrameType.TDRL);
+ } else {
+ SetTextFrame(FrameType.TDRL, date);
+ }
+ }
+ }
+
///
/// Gets and sets the length of the media represented
/// by the current instance.
From f01d080d50737200df9cb5ae5c248bf0f835c461 Mon Sep 17 00:00:00 2001
From: 42Geese <129562715+42Geese@users.noreply.github.com>
Date: Fri, 9 Jun 2023 21:20:50 -0400
Subject: [PATCH 2/2] Audio Id3v2 Add Support For EncodedBy (#4)
---
.../TaggingFormats/Id3V2Test.cs | 29 +++++++++++++++++++
src/TaglibSharp/Id3v2/FrameTypes.cs | 1 +
src/TaglibSharp/Id3v2/Tag.cs | 14 +++++++++
3 files changed, 44 insertions(+)
diff --git a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
index 8b2ea676..d3394761 100644
--- a/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
+++ b/src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
@@ -968,6 +968,35 @@ public void TestPublisher ()
}
}
+
+ [Test]
+ public void TestEncodedBy ()
+ {
+ Tag tag = new Tag ();
+ for (byte version = 2; version <= 4; version++) {
+ tag.Version = version;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
+ Assert.IsNull (t.EncodedBy, "Initial (Null): " + m);
+ });
+
+ tag.EncodedBy = val_sing;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
+ Assert.AreEqual (val_sing, t.EncodedBy, "Value Set (!Null): " + m);
+ });
+
+ tag.EncodedBy = string.Empty;
+
+ TagTestWithSave (ref tag, delegate (Tag t, string m) {
+ Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
+ Assert.IsNull (t.EncodedBy, "Value Cleared (Null): " + m);
+ });
+ }
+ }
+
[Test]
public void TestISRC ()
{
diff --git a/src/TaglibSharp/Id3v2/FrameTypes.cs b/src/TaglibSharp/Id3v2/FrameTypes.cs
index 2fda85de..36b86c07 100644
--- a/src/TaglibSharp/Id3v2/FrameTypes.cs
+++ b/src/TaglibSharp/Id3v2/FrameTypes.cs
@@ -101,5 +101,6 @@ static class FrameType
public static readonly ReadOnlyByteVector WPUB = "WPUB";
public static readonly ReadOnlyByteVector WXXX = "WXXX";
public static readonly ReadOnlyByteVector ETCO = "ETCO";
+ public static readonly ReadOnlyByteVector TENC = "TENC"; // Encoded By Frame.
}
}
diff --git a/src/TaglibSharp/Id3v2/Tag.cs b/src/TaglibSharp/Id3v2/Tag.cs
index 1c3676ff..d38a9ae5 100644
--- a/src/TaglibSharp/Id3v2/Tag.cs
+++ b/src/TaglibSharp/Id3v2/Tag.cs
@@ -2265,6 +2265,20 @@ public override string Publisher {
set { SetTextFrame (FrameType.TPUB, value); }
}
+ ///
+ /// Gets and sets the TENC (Encoded by) of the song.
+ ///
+ ///
+ /// A object containing the TENC of the song.
+ ///
+ ///
+ /// This property is implemented using the "TENC" field.
+ ///
+ public string EncodedBy {
+ get { return GetTextAsString (FrameType.TENC); }
+ set { SetTextFrame (FrameType.TENC, value); }
+ }
+
///
/// Gets and sets the ISRC (International Standard Recording Code) of the song.
///