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

feat(id3): support apple MVNM/MVIN frames #15

Open
wants to merge 1 commit into
base: master
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
48 changes: 48 additions & 0 deletions src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,54 @@ public void TestUserTextInformationFrame ()
});
}

[Test]
public void TestMovementNameFrame ()
{
ByteVector id = "MVNM";
var frame = new TextInformationFrame (id) {
Text = val_mult
};

FrameTest (frame, 2,
delegate (Frame f, StringType e) {
(f as TextInformationFrame).TextEncoding = e;
},
(d, v) => new TextInformationFrame (d, v),

delegate (Frame f, string m) {
var g = (f as TextInformationFrame);
Assert.AreEqual (id, g.FrameId, m);
Assert.AreEqual (val_mult.Length, g.Text.Length, m);
for (int i = 0; i < val_mult.Length; i++) {
Assert.AreEqual (val_mult[i], g.Text[i], m);
}
});
}

[Test]
public void TestMovementNumberFrame ()
{
ByteVector id = "MVIN";
var frame = new TextInformationFrame (id) {
Text = val_mult
};

FrameTest (frame, 2,
delegate (Frame f, StringType e) {
(f as TextInformationFrame).TextEncoding = e;
},
(d, v) => new TextInformationFrame (d, v),

delegate (Frame f, string m) {
var g = (f as TextInformationFrame);
Assert.AreEqual (id, g.FrameId, m);
Assert.AreEqual (val_mult.Length, g.Text.Length, m);
for (int i = 0; i < val_mult.Length; i++) {
Assert.AreEqual (val_mult[i], g.Text[i], m);
}
});
}

[Test]
public void TestUniqueFileIdentifierFrame ()
{
Expand Down
5 changes: 4 additions & 1 deletion src/TaglibSharp/Id3v2/FrameFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ public static Frame CreateFrame (ByteVector data, File file, ref int offset, byt
if (header.FrameId == FrameType.TXXX)
return new UserTextInformationFrame (data, position, header, version);

if (header.FrameId[0] == (byte)'T')
// Apple proprietary MVNM (Movement Name), MVIN (Movement Number) are in fact text frames.
if (header.FrameId[0] == (byte)'T' ||
header.FrameId == "MVNM" ||
header.FrameId == "MVIN")
return new TextInformationFrame (data, position, header, version);

// Involved People List (frames 4.4 in 2.3. in 2.4 this is a TIPL frame)
Expand Down
8 changes: 5 additions & 3 deletions src/TaglibSharp/Id3v2/FrameHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public struct FrameHeader
/// </param>
/// <remarks>
/// If the data size is smaller than the size of a full
/// header, the data is just treated as a frame identifier
/// header, the data is just treated as a frame identifier
/// and the remaining values are zeroed.
/// </remarks>
/// <exception cref="ArgumentNullException">
Expand Down Expand Up @@ -381,7 +381,7 @@ static ReadOnlyByteVector ConvertId (ByteVector id, byte version, bool toVersion
}

static readonly ReadOnlyByteVector[,] version2_frames =
new ReadOnlyByteVector[59, 2] {
new ReadOnlyByteVector[61, 2] {
{ "BUF", "RBUF" },
{ "CNT", "PCNT" },
{ "COM", "COMM" },
Expand Down Expand Up @@ -440,7 +440,9 @@ static ReadOnlyByteVector ConvertId (ByteVector id, byte version, bool toVersion
{ "WCP", "WCOP" },
{ "WPB", "WPUB" },
{ "WXX", "WXXX" },
{ "XRV", "RVA2" }
{ "XRV", "RVA2" },
{ "MVN", "MVNM" },
{ "MVI", "MVIN" }
};

static readonly ReadOnlyByteVector[,] version3_frames =
Expand Down
2 changes: 2 additions & 0 deletions src/TaglibSharp/Id3v2/FrameTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,7 @@ 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 MVNM = "MVNM"; // Movement Name
public static readonly ReadOnlyByteVector MVIN = "MVIN"; // Movement Number/Count
}
}
4 changes: 3 additions & 1 deletion src/TaglibSharp/Id3v2/Frames/TextIdentificationFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,9 @@ protected void ParseRawData ()
FrameId == FrameType.TPE1 ||
FrameId == FrameType.TPE2 ||
FrameId == FrameType.TPE3 ||
FrameId == FrameType.TPE4) {
FrameId == FrameType.TPE4 ||
FrameId == FrameType.MVNM ||
FrameId == FrameType.MVIN) {
field_list.AddRange (value.Split ('/'));
} else if (FrameId == FrameType.TCON) {
while (value.Length > 1 && value[0] == '(') {
Expand Down
Loading