Skip to content

Commit

Permalink
WMA : Read and write class 1 and 6 fields (e.g. WM/MediaClassPrimaryI…
Browse files Browse the repository at this point in the history
…D or ASFLeakyBucketPairs) as base-64-encoded strings stored in Track.AdditionalFields
  • Loading branch information
Zeugma440 committed May 7, 2023
1 parent 08ed95b commit f6fcf0e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
41 changes: 37 additions & 4 deletions ATL.test/IO/MetaData/WMA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void TagIO_RW_WMA_Empty()
theTag.TrackTotal = 1;
theTag.DiscNumber = 2;
theTag.Composer = "Me";
theTag.Popularity = 2.0f/5;
theTag.Popularity = 2.0f / 5;
theTag.Copyright = "父";
theTag.Conductor = "John Johnson Jr.";

Expand Down Expand Up @@ -329,9 +329,8 @@ public void TagIO_RW_WMA_Existing()
public void TagIO_RW_WMA_Unsupported_Empty()
{
// Source : tag-free file
String testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile);
AudioDataManager theFile = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

string testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile);
AudioDataManager theFile = new AudioDataManager(AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

// Check that it is indeed tag-free
Assert.IsTrue(theFile.ReadFromFile());
Expand Down Expand Up @@ -446,6 +445,40 @@ public void TagIO_RW_WMA_Unsupported_Empty()
if (Settings.DeleteAfterSuccess) File.Delete(testFileLocation);
}

[TestMethod]
public void TagIO_RW_WMA_Unsupported_Classes_1_6()
{
// Source : file with classes 1 and 6 fields (MediaClassPrimaryID, LeakyBucketPairs)
string testFileLocation = TestUtils.CopyAsTempTestFile("WMA/classes1&6.wma");
AudioDataManager theFile = new AudioDataManager(AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

string mediaClassPrimaryIdValue64 = "vH1g0SPj4kuGoUikKihEHg==";
string leakyValue64 = "AADAXQAAEY8kADB1AAB3mhwAyK8AAP/+EQCQ4gAAtz0NAADCAQBpEgUAgKkDAEbIAAAwVwUAzAAAACChBwCPAAAAkCMLAGIAAABAQg8ARwAAAMBcFQAzAAAAIAsgACIAAABAS0wADgAAAICWmAAHAAAA";

Assert.IsTrue(theFile.ReadFromFile(true, true));
Assert.IsNotNull(theFile.NativeTag);
Assert.IsTrue(theFile.NativeTag.Exists);

Assert.AreEqual(mediaClassPrimaryIdValue64, theFile.NativeTag.AdditionalFields["WM/MediaClassPrimaryID"]);
Assert.AreEqual(leakyValue64, theFile.NativeTag.AdditionalFields["ASFLeakyBucketPairs"]);

TagHolder theTag = new TagHolder();
theTag.Conductor = "John Jackman";

// Add the new tag and check that it has been indeed added with all the correct information
Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TagType.NATIVE));

Assert.IsTrue(theFile.ReadFromFile(true, true));
Assert.IsNotNull(theFile.NativeTag);
Assert.IsTrue(theFile.NativeTag.Exists);

Assert.AreEqual(mediaClassPrimaryIdValue64, theFile.NativeTag.AdditionalFields["WM/MediaClassPrimaryID"]);
Assert.AreEqual(leakyValue64, theFile.NativeTag.AdditionalFields["ASFLeakyBucketPairs"]);

// Get rid of the working copy
if (Settings.DeleteAfterSuccess) File.Delete(testFileLocation);
}

[TestMethod]
public void TagIO_R_WMA_Rating()
{
Expand Down
Binary file added ATL.test/Resources/WMA/classes1&6.wma
Binary file not shown.
10 changes: 5 additions & 5 deletions ATL/AudioData/IO/WMA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void readTagField(BufferedBinaryReader source, string zoneCode, string fi
}
else
{
source.Seek(fieldDataSize, SeekOrigin.Current);
fieldValue = Utils.Latin1Encoding.GetString(Utils.EncodeTo64(source.ReadBytes(fieldDataSize)));
}
}
else if (2 == fieldDataType) // 16-bit Boolean (metadata); 32-bit Boolean (extended header)
Expand All @@ -511,7 +511,7 @@ public void readTagField(BufferedBinaryReader source, string zoneCode, string fi
}
else if (6 == fieldDataType) // 128-bit GUID; unused for now
{
source.Seek(fieldDataSize, SeekOrigin.Current);
fieldValue = Utils.Latin1Encoding.GetString(Utils.EncodeTo64(source.ReadBytes(fieldDataSize)));
}

if (setMeta) SetMetaField(fieldName.Trim(), fieldValue, readTagParams.ReadAllMetaFrames, zoneCode, 0, streamNumber, decodeLanguage(source, languageIndex));
Expand Down Expand Up @@ -930,9 +930,9 @@ private void writeTextFrame(BinaryWriter writer, string frameCode, string text,
{
writer.Write(Encoding.Unicode.GetBytes(text + '\0'));
}
else if (1 == frameClass) // Byte array
else if (1 == frameClass) // Non-picture byte array
{
// Only used for embedded pictures
writer.Write(Utils.DecodeFrom64(Utils.Latin1Encoding.GetBytes(text)));
}
else if (2 == frameClass) // 32-bit boolean; 16-bit boolean if in extended header
{
Expand All @@ -953,7 +953,7 @@ private void writeTextFrame(BinaryWriter writer, string frameCode, string text,
}
else if (6 == frameClass) // 128-bit GUID
{
// Unused for now
writer.Write(Utils.DecodeFrom64(Utils.Latin1Encoding.GetBytes(text)));
}

// Go back to frame size locations to write their actual size
Expand Down

0 comments on commit f6fcf0e

Please sign in to comment.