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 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 131 additions & 3 deletions src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,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 @@ -1078,7 +1198,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 @@ -1109,6 +1233,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 @@ -1634,10 +1762,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 @@ -289,6 +289,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
6 changes: 6 additions & 0 deletions src/TaglibSharp/Id3v2/FrameTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@ 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 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.
}
}