Skip to content

Commit c72e6d3

Browse files
authored
Merge branch 'main' into AddPodcastTagsToId3v2
2 parents f1b2a86 + d31280c commit c72e6d3

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Diff for: src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs

+59
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class Id3V2Test
1818
static readonly string[] val_gnre = {"Rap",
1919
"Jazz", "Non-Genre", "Blues"};
2020

21+
static readonly System.DateTime val_date = new System.DateTime (2022, 10, 20, 16, 45, 23, 0, 0);
22+
2123
[Test]
2224
public void TestTitle ()
2325
{
@@ -1088,6 +1090,35 @@ public void TestPublisher ()
10881090
}
10891091
}
10901092

1093+
1094+
[Test]
1095+
public void TestEncodedBy ()
1096+
{
1097+
Tag tag = new Tag ();
1098+
for (byte version = 2; version <= 4; version++) {
1099+
tag.Version = version;
1100+
1101+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1102+
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
1103+
Assert.IsNull (t.EncodedBy, "Initial (Null): " + m);
1104+
});
1105+
1106+
tag.EncodedBy = val_sing;
1107+
1108+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1109+
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
1110+
Assert.AreEqual (val_sing, t.EncodedBy, "Value Set (!Null): " + m);
1111+
});
1112+
1113+
tag.EncodedBy = string.Empty;
1114+
1115+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1116+
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
1117+
Assert.IsNull (t.EncodedBy, "Value Cleared (Null): " + m);
1118+
});
1119+
}
1120+
}
1121+
10911122
[Test]
10921123
public void TestISRC ()
10931124
{
@@ -1116,6 +1147,34 @@ public void TestISRC ()
11161147
}
11171148
}
11181149

1150+
[Test]
1151+
public void TestReleaseDate ()
1152+
{
1153+
Tag tag = new Tag ();
1154+
for (byte version = 4; version <= 4; version++) {
1155+
tag.Version = version;
1156+
1157+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1158+
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
1159+
Assert.IsNull (t.ReleaseDate, "Initial (Null): " + m);
1160+
}, 4);
1161+
1162+
tag.ReleaseDate = val_date;
1163+
1164+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1165+
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
1166+
Assert.AreEqual (val_date, t.ReleaseDate.Value, "Value Set (!Null): " + m);
1167+
}, 4);
1168+
1169+
tag.ReleaseDate = null;
1170+
1171+
TagTestWithSave (ref tag, delegate (Tag t, string m) {
1172+
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
1173+
Assert.IsNull (t.ReleaseDate, "Value Cleared (Null): " + m);
1174+
}, 4);
1175+
}
1176+
}
1177+
11191178
[Test]
11201179
public void TestLength ()
11211180
{

Diff for: src/TaglibSharp/Id3v2/FrameTypes.cs

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ static class FrameType
101101
public static readonly ReadOnlyByteVector WPUB = "WPUB";
102102
public static readonly ReadOnlyByteVector WXXX = "WXXX";
103103
public static readonly ReadOnlyByteVector ETCO = "ETCO";
104+
public static readonly ReadOnlyByteVector TDRL = "TDRL"; // Release Time Frame
105+
public static readonly ReadOnlyByteVector TENC = "TENC"; // Encoded By Frame.
104106
public static readonly ReadOnlyByteVector PCST = "PCST"; // Podcast Flag Frame.
105107
public static readonly ReadOnlyByteVector TDES = "TDES"; // Podcast Description Frame.
106108
public static readonly ReadOnlyByteVector TGID = "TGID"; // Podcast Identifier Frame.

Diff for: src/TaglibSharp/Id3v2/Tag.cs

+56
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,20 @@ public override string Publisher {
22652265
set { SetTextFrame (FrameType.TPUB, value); }
22662266
}
22672267

2268+
/// <summary>
2269+
/// Gets and sets the TENC (Encoded by) of the song.
2270+
/// </summary>
2271+
/// <value>
2272+
/// A <see cref="string" /> object containing the TENC of the song.
2273+
/// </value>
2274+
/// <remarks>
2275+
/// This property is implemented using the "TENC" field.
2276+
/// </remarks>
2277+
public string EncodedBy {
2278+
get { return GetTextAsString (FrameType.TENC); }
2279+
set { SetTextFrame (FrameType.TENC, value); }
2280+
}
2281+
22682282
/// <summary>
22692283
/// Gets and sets the ISRC (International Standard Recording Code) of the song.
22702284
/// </summary>
@@ -2279,6 +2293,48 @@ public override string ISRC {
22792293
set { SetTextFrame (FrameType.TSRC, value); }
22802294
}
22812295

2296+
/// <summary>
2297+
/// Gets and sets the date at which the song has been released.
2298+
/// </summary>
2299+
/// <value>
2300+
/// A nullable <see cref="DateTime" /> object containing the
2301+
/// date at which the song has been released, or <see
2302+
/// langword="null" /> if no value present.
2303+
/// </value>
2304+
/// <remarks>
2305+
/// <para>This property is implemented using the "TDRL" field.</para>
2306+
/// <para>This is a ID3v2.4 type tag.</para>
2307+
/// </remarks>
2308+
public DateTime? ReleaseDate {
2309+
get {
2310+
string value = GetTextAsString (FrameType.TDRL);
2311+
2312+
if (String.IsNullOrWhiteSpace(value)) {
2313+
return null;
2314+
} else if (DateTime.TryParseExact (value.Replace ('T', ' '), "yyyy-MM-dd HH:mm:ss", null, DateTimeStyles.None, out DateTime exactDate)) {
2315+
return exactDate;
2316+
} else if (DateTime.TryParse(value, out DateTime parsedDate)) {
2317+
return parsedDate;
2318+
}
2319+
2320+
return null;
2321+
}
2322+
set {
2323+
string date = null;
2324+
2325+
if (value != null) {
2326+
date = $"{value:yyyy-MM-dd HH:mm:ss}";
2327+
date = date.Replace (' ', 'T');
2328+
}
2329+
2330+
if (date == null) {
2331+
RemoveFrames(FrameType.TDRL);
2332+
} else {
2333+
SetTextFrame(FrameType.TDRL, date);
2334+
}
2335+
}
2336+
}
2337+
22822338
/// <summary>
22832339
/// Gets and sets the length of the media represented
22842340
/// by the current instance.

0 commit comments

Comments
 (0)