mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
@@ -0,0 +1,124 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Builds minimal, structurally valid WAV files used as test input for the artwork scanning and embedded cover extraction tests.
|
||||
/// The files are produced into a temporary directory at test runtime, because a WAV is a binary container whose embedded pictures can only be written by the tagging library itself.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class TestAudioFileFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a minimal, untagged PCM WAV file.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the WAV is written.</param>
|
||||
/// <param name="durationMs">The duration of the audio of the file, in milliseconds.</param>
|
||||
public static void CreateWav(string path, int durationMs = 200)
|
||||
{
|
||||
WriteFile(path, BuildWav(durationMs));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a PCM WAV file that carries the provided image as its embedded front cover.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the WAV is written.</param>
|
||||
/// <param name="imageBytes">The bytes of the embedded cover image.</param>
|
||||
/// <param name="mimeType">The MIME type of the embedded cover image, defaulting to JPEG.</param>
|
||||
/// <param name="durationMs">The duration of the audio of the file, in milliseconds.</param>
|
||||
public static void CreateWavWithEmbeddedCover(string path, byte[] imageBytes, string? mimeType = "image/jpeg", int durationMs = 200)
|
||||
{
|
||||
CreateTaggedWav(path, tagFile =>
|
||||
{
|
||||
tagFile.Tag.Pictures =
|
||||
[
|
||||
new TagLib.Picture
|
||||
{
|
||||
MimeType = mimeType!,
|
||||
Type = TagLib.PictureType.FrontCover,
|
||||
Data = [.. imageBytes]
|
||||
}
|
||||
];
|
||||
}, durationMs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a PCM WAV file whose embedded tags are configured by the provided callback.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the WAV is written.</param>
|
||||
/// <param name="configureTags">The callback that configures the tags of the file.</param>
|
||||
/// <param name="durationMs">The duration of the audio of the file, in milliseconds.</param>
|
||||
public static void CreateTaggedWav(string path, Action<TagLib.File> configureTags, int durationMs = 200)
|
||||
{
|
||||
WriteFile(path, BuildWav(durationMs));
|
||||
using (TagLib.File tagFile = TagLib.File.Create(path))
|
||||
{
|
||||
configureTags(tagFile);
|
||||
tagFile.Save();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file whose content is not a recognizable audio container, so that the resilience of the embedded cover extraction can be exercised.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the file is written.</param>
|
||||
public static void CreateUnsupportedFile(string path)
|
||||
{
|
||||
WriteFile(path, Encoding.UTF8.GetBytes("This is not an audio file."));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the provided bytes at <paramref name="path"/>, creating the containing directory when it does not exist yet.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the bytes are written.</param>
|
||||
/// <param name="contents">The bytes of the file.</param>
|
||||
private static void WriteFile(string path, byte[] contents)
|
||||
{
|
||||
string? directory = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllBytes(path, contents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the bytes of a minimal, valid PCM WAV file with a single silent audio channel.
|
||||
/// </summary>
|
||||
/// <param name="durationMs">The duration of the audio of the file, in milliseconds.</param>
|
||||
/// <returns>The bytes of the WAV file.</returns>
|
||||
private static byte[] BuildWav(int durationMs)
|
||||
{
|
||||
const int SAMPLE_RATE = 44100;
|
||||
const short CHANNELS = 1;
|
||||
const short BITS_PER_SAMPLE = 16;
|
||||
|
||||
int bytesPerSample = BITS_PER_SAMPLE / 8;
|
||||
int dataSize = SAMPLE_RATE * CHANNELS * bytesPerSample * durationMs / 1000;
|
||||
|
||||
using (MemoryStream memoryStream = new())
|
||||
{
|
||||
using (BinaryWriter writer = new(memoryStream))
|
||||
{
|
||||
writer.Write(Encoding.ASCII.GetBytes("RIFF"));
|
||||
writer.Write(36 + dataSize);
|
||||
writer.Write(Encoding.ASCII.GetBytes("WAVE"));
|
||||
writer.Write(Encoding.ASCII.GetBytes("fmt "));
|
||||
writer.Write(16);
|
||||
writer.Write((short)1);
|
||||
writer.Write(CHANNELS);
|
||||
writer.Write(SAMPLE_RATE);
|
||||
writer.Write(SAMPLE_RATE * CHANNELS * bytesPerSample);
|
||||
writer.Write((short)(CHANNELS * bytesPerSample));
|
||||
writer.Write(BITS_PER_SAMPLE);
|
||||
writer.Write(Encoding.ASCII.GetBytes("data"));
|
||||
writer.Write(dataSize);
|
||||
writer.Write(new byte[dataSize]);
|
||||
}
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.LocalMusicArtwork.Fixtures.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Creates image files of the formats a local music library stores next to its tracks, so that artwork scanning can be exercised against real files.
|
||||
/// Each file carries the magic bytes of its format, mirroring the images a music library keeps in the folders of its artists and albums.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class TestImageFileFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a JPEG image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreateJpeg(string path)
|
||||
{
|
||||
WriteFile(path, [0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xFF, 0xD9]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a PNG image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreatePng(string path)
|
||||
{
|
||||
WriteFile(path, [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a WebP image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreateWebp(string path)
|
||||
{
|
||||
WriteFile(path, [.. Encoding.ASCII.GetBytes("RIFF"), 0x00, 0x00, 0x00, 0x00, .. Encoding.ASCII.GetBytes("WEBP")]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a BMP image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreateBmp(string path)
|
||||
{
|
||||
WriteFile(path, [0x42, 0x4D, 0x00, 0x00, 0x00, 0x00]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a GIF image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreateGif(string path)
|
||||
{
|
||||
WriteFile(path, [.. Encoding.ASCII.GetBytes("GIF89a")]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a TIFF image file at the provided path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the image is written.</param>
|
||||
public static void CreateTiff(string path)
|
||||
{
|
||||
WriteFile(path, [0x49, 0x49, 0x2A, 0x00]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a file whose content is not an image, so that the exclusion of non image files can be exercised.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the file is written.</param>
|
||||
public static void CreateTextFile(string path)
|
||||
{
|
||||
WriteFile(path, Encoding.UTF8.GetBytes("This is not an image."));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the provided bytes at <paramref name="path"/>, creating the containing directory when it does not exist yet.
|
||||
/// </summary>
|
||||
/// <param name="path">The path where the bytes are written.</param>
|
||||
/// <param name="contents">The bytes of the file.</param>
|
||||
private static void WriteFile(string path, byte[] contents)
|
||||
{
|
||||
string? directory = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllBytes(path, contents);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user