Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Podcast Properties to ID3V2 Tag #323

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 190 additions & 3 deletions src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -576,6 +578,126 @@ public void TestPictures ()
}
}

[Test]
public void TestPocastFlag ()
{
Tag tag = new Tag ();

// This property isn't supported in version 2.
for (byte version = 3; version <= 4; version++) {
tag.Version = version;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsFalse (t.PodcastFlag, "Initial (False): " + m);
}, 3);

tag.PodcastFlag = true;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
Assert.IsTrue (t.PodcastFlag, "Value Set (!False): " + m);
}, 3);

tag.PodcastFlag = false;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Assert.IsFalse (t.PodcastFlag, "Value Cleared (False): " + m);
}, 3);
}
}

[Test]
public void TestPodcastIdentifier ()
{
var tag = new Tag ();

// This property isn't supported in version 2.
for (byte version = 3; version <= 4; version++) {
tag.Version = version;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.PodcastIdentifier, "Initial (Null): " + m);
}, 3);

tag.PodcastIdentifier = val_sing;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
Assert.AreEqual (val_sing, t.PodcastIdentifier, "Value Set (!Null): " + m);
}, 3);

tag.PodcastIdentifier = string.Empty;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Assert.IsNull (t.PodcastIdentifier, "Value Cleared (Null): " + m);
}, 3);
}
}

[Test]
public void TestPodcastFeed ()
{
var tag = new Tag ();

// This property isn't supported in version 2.
for (byte version = 3; version <= 4; version++) {
tag.Version = version;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.PodcastFeed, "Initial (Null): " + m);
}, 3);

tag.PodcastFeed = val_sing;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
Assert.AreEqual (val_sing, t.PodcastFeed, "Value Set (!Null): " + m);
}, 3);

tag.PodcastFeed = string.Empty;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Assert.IsNull (t.PodcastFeed, "Value Cleared (Null): " + m);
}, 3);
}
}

[Test]
public void TestPodcastDescription ()
{
var tag = new Tag ();

// This property isn't supported in version 2.
for (byte version = 3; version <= 4; version++) {
tag.Version = version;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.PodcastDescription, "Initial (Null): " + m);
}, 3);

tag.PodcastDescription = val_sing;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsFalse (t.IsEmpty, "Value Set (!IsEmpty): " + m);
Assert.AreEqual (val_sing, t.PodcastDescription, "Value Set (!Null): " + m);
}, 3);

tag.PodcastDescription = string.Empty;

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Assert.IsNull (t.PodcastDescription, "Value Cleared (Null): " + m);
}, 3);
}
}

[Test]
public void TestIsCompilation ()
{
Expand Down Expand Up @@ -1024,6 +1146,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 ()
{
Expand Down Expand Up @@ -1052,6 +1203,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 ()
{
Expand Down Expand Up @@ -1134,7 +1313,11 @@ public void TestClear ()
Publisher = "L",
ISRC = "M",
Length = "L",
RemixedBy = "N"
RemixedBy = "N",
PodcastFlag = true,
PodcastDescription = "description here",
PodcastFeed = "https://example.org/feed.rss",
PodcastIdentifier = "unique id"
};


Expand Down Expand Up @@ -1165,6 +1348,10 @@ public void TestClear ()
Assert.IsNull (tag.ISRC, "ISRC");
Assert.IsNull (tag.Length, "Length");
Assert.IsNull (tag.RemixedBy, "RemixedBy");
Assert.IsFalse (tag.PodcastFlag, "PodcastFlag");
Assert.IsNull (tag.PodcastDescription, "PodcastDescription");
Assert.IsNull (tag.PodcastFeed, "PodcastFeed");
Assert.IsNull (tag.PodcastIdentifier, "PodcastIdentifier");
}

[Test]
Expand Down Expand Up @@ -1738,10 +1925,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);
Expand Down
4 changes: 4 additions & 0 deletions src/TaglibSharp/Id3v2/FrameFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ public static Frame CreateFrame (ByteVector data, File file, ref int offset, byt
// Table of Contents (ID3v2 Chapter Frame Addendum)
if (header.FrameId == FrameType.CTOC)
return new TableOfContentsFrame (data, position, header, version);

// Podcast Flag Frame
if (header.FrameId == FrameType.PCST)
return new PodcastFlagFrame(data, position, header, version);

return new UnknownFrame (data, position, header, version);
}
Expand Down
8 changes: 8 additions & 0 deletions src/TaglibSharp/Id3v2/FrameTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ 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
public static readonly ReadOnlyByteVector TENC = "TENC"; // Encoded By Frame.
public static readonly ReadOnlyByteVector PCST = "PCST"; // Podcast Flag Frame.
public static readonly ReadOnlyByteVector TDES = "TDES"; // Podcast Description Frame.
public static readonly ReadOnlyByteVector TGID = "TGID"; // Podcast Identifier Frame.
public static readonly ReadOnlyByteVector WFED = "WFED"; // Podcast Feed Url Frame.
public static readonly ReadOnlyByteVector TCAT = "TCAT"; // Podcast Category Frame.
public static readonly ReadOnlyByteVector TKWD = "TKWD"; // Podcast Keywords Frame.
public static readonly ReadOnlyByteVector MVNM = "MVNM"; // Movement Name
public static readonly ReadOnlyByteVector MVIN = "MVIN"; // Movement Number/Count
}
Expand Down
Loading
Loading