Skip to content

Commit

Permalink
#14: Add track number to available placeholders [add unit test for cu…
Browse files Browse the repository at this point in the history
…stom metadata field]
  • Loading branch information
Aldaviva committed Oct 6, 2023
1 parent 6e1835e commit d032f65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Test/Business/NowPlayingToFileManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,15 @@ public void uncaughtException() {
actual!.song.Should().BeSameAs(song);
}

[Fact]
public void queryCustomMetadataFieldFromWinamp() {
A.CallTo(() => winampController.fetchMetadataFieldValue("CustomField")).Returns("CustomValue");

A.CallTo(() => settings.textTemplate).Returns("{{CustomField}}");
settings.settingsUpdated += Raise.WithEmpty();

File.ReadAllText(textFilename).Should().Be("CustomValue");
A.CallTo(() => winampController.fetchMetadataFieldValue("CustomField")).MustHaveHappenedOnceExactly();
}

}
7 changes: 4 additions & 3 deletions WinampNowPlayingToFile/Facade/WinampControllerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ public void stop() {

public object fetchMetadataFieldValue(string metadataFieldName) {
metadataFieldName = metadataFieldName.ToLowerInvariant();
string songFilename = winamp.CurrentSong.Filename;

try {
if (metadataFieldName == "filebasename") {
return Path.GetFileName(winamp.CurrentSong.Filename);
return Path.GetFileName(songFilename);
} else if (metadataFieldName == "filebasenamewithoutextension") {
return Path.GetFileNameWithoutExtension(winamp.CurrentSong.Filename);
return Path.GetFileNameWithoutExtension(songFilename);
}
} catch (ArgumentException) {
return string.Empty;
}

string value = getMetadata(winamp.CurrentSong.Filename, metadataFieldName);
string value = getMetadata(songFilename, metadataFieldName);

return metadataFieldName switch {
"length" when long.TryParse(value, out long length) => TimeSpan.FromMilliseconds(length),
Expand Down

0 comments on commit d032f65

Please sign in to comment.