Skip to content

Commit

Permalink
Merge branch 'main' into AddReleaseDateToTag
Browse files Browse the repository at this point in the history
  • Loading branch information
decriptor authored Aug 31, 2024
2 parents 71adfd6 + 74687bf commit cde4009
Show file tree
Hide file tree
Showing 23 changed files with 743 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/TaglibSharp.Tests/FileFormats/M4aFormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void bgo_676934 ()
[Test]
public void bgo_701689 ()
{
// This file contains a musicbrainz track id "883821fc-9bbc-4e04-be79-b4b12c4c4a4e"
// This file contains a musicbrainz recording id "883821fc-9bbc-4e04-be79-b4b12c4c4a4e"
// This case also handles bgo #701690 as a proper value for the tag must be returned
var file = TagLib.File.Create (TestPath.Samples + "bgo_701689.m4a");
Assert.AreEqual ("883821fc-9bbc-4e04-be79-b4b12c4c4a4e", file.Tag.MusicBrainzTrackId, "#1");
Assert.AreEqual ("883821fc-9bbc-4e04-be79-b4b12c4c4a4e", file.Tag.MusicBrainzRecordingId, "#1");
}

[Test]
Expand Down
52 changes: 51 additions & 1 deletion src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,56 @@ public void TestMusicBrainzTrackID ()
});
}

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

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

tag.MusicBrainzRecordingId = val_sing;

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

tag.MusicBrainzRecordingId = string.Empty;

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

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

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

tag.MusicBrainzWorkId = val_sing;

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

tag.MusicBrainzWorkId = string.Empty;

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

[Test]
public void TestMusicBrainzDiscID ()
{
Expand Down Expand Up @@ -842,4 +892,4 @@ void TagTestWithSave (ref Tag tag, TagTestFunc testFunc)
testFunc (tag, "After Save");
}
}
}
}
50 changes: 50 additions & 0 deletions src/TaglibSharp.Tests/TaggingFormats/AsfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,56 @@ public void TestMusicBrainzTrackID ()
});
}

[Test]
public void TestMusicBrainzRecordingID ()
{
var file = CreateFile (out var abst);

TagTestWithSave (ref file, abst, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.MusicBrainzRecordingId, "Initial (Null): " + m);
});

file.Tag.MusicBrainzRecordingId = val_sing;

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

file.Tag.MusicBrainzRecordingId = string.Empty;

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

[Test]
public void TestMusicBrainzWorkID ()
{
var file = CreateFile (out var abst);

TagTestWithSave (ref file, abst, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.MusicBrainzWorkId, "Initial (Null): " + m);
});

file.Tag.MusicBrainzWorkId = val_sing;

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

file.Tag.MusicBrainzWorkId = string.Empty;

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

[Test]
public void TestMusicBrainzDiscID ()
{
Expand Down
104 changes: 104 additions & 0 deletions src/TaglibSharp.Tests/TaggingFormats/Id3V2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,62 @@ public void TestMusicBrainzTrackID ()
}
}

[Test]
public void TestMusicBrainzRecordingID ()
{
var 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.MusicBrainzRecordingId, "Initial (Null): " + m);
});

tag.MusicBrainzRecordingId = val_sing;

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

tag.MusicBrainzRecordingId = string.Empty;

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

[Test]
public void TestMusicBrainzWorkID ()
{
var 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.MusicBrainzWorkId, "Initial (Null): " + m);
});

tag.MusicBrainzWorkId = val_sing;

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

tag.MusicBrainzWorkId = string.Empty;

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

[Test]
public void TestMusicBrainzDiscID ()
{
Expand Down Expand Up @@ -1558,6 +1614,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
50 changes: 50 additions & 0 deletions src/TaglibSharp.Tests/TaggingFormats/Mpeg4Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,56 @@ public void TestMusicBrainzTrackID ()
});
}

[Test]
public void TestMusicBrainzRecordingID ()
{
var file = CreateFile (out var abst);

TagTestWithSave (ref file, abst, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.MusicBrainzRecordingId, "Initial (Null): " + m);
});

file.Tag.MusicBrainzRecordingId = val_sing;

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

file.Tag.MusicBrainzRecordingId = string.Empty;

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

[Test]
public void TestMusicBrainzWorkID ()
{
var file = CreateFile (out var abst);

TagTestWithSave (ref file, abst, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Initial (IsEmpty): " + m);
Assert.IsNull (t.MusicBrainzWorkId, "Initial (Null): " + m);
});

file.Tag.MusicBrainzWorkId = val_sing;

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

file.Tag.MusicBrainzWorkId = string.Empty;

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

[Test]
public void TestMusicBrainzDiscID ()
{
Expand Down
50 changes: 50 additions & 0 deletions src/TaglibSharp.Tests/TaggingFormats/XiphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,56 @@ public void TestMusicBrainzTrackID ()
});
}

[Test]
public void TestMusicBrainzRecordingID ()
{
var tag = new XiphComment ();

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

tag.MusicBrainzRecordingId = val_sing;

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

tag.MusicBrainzRecordingId = string.Empty;

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

[Test]
public void TestMusicBrainzWorkID ()
{
var tag = new XiphComment ();

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

tag.MusicBrainzWorkId = val_sing;

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

tag.MusicBrainzWorkId = string.Empty;

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

[Test]
public void TestMusicBrainzDiscID ()
{
Expand Down
15 changes: 11 additions & 4 deletions src/TaglibSharp/Ape/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,17 @@ protected void Parse (ByteVector data, int offset)

Size = pos + 1 + (int)value_length - offset;

if (Type == ItemType.Binary)
this.data = new ReadOnlyByteVector (data.Mid (pos + 1, (int)value_length));
else
text = data.Mid (pos + 1, (int)value_length).ToStrings (StringType.UTF8, 0);
// Store both the binary and string representation, because APE v1. tags don't use the flags.
// Because of this the parser can't differentiate between string and binary.
// In this case sting is assumed (because flags == 0).
//
// If we write both string and binary data, the application can still access the binary data by setting the Type to binary.

// Binary representation
this.data = new ReadOnlyByteVector (data.Mid (pos + 1, (int)value_length));

// String representation
text = data.Mid (pos + 1, (int)value_length).ToStrings (StringType.UTF8, 0);
}

#endregion
Expand Down
Loading

0 comments on commit cde4009

Please sign in to comment.