feat: add song upload for MP3 and WAV files

Add an Upload page where the user picks an MP3 or WAV file. The new
SongImportService copies it into %LOCALAPPDATA%\Radiosender\Music under
a unique name, reads the duration with NAudio and title/artist from tags
with TagLibSharp (falling back to the file name), and saves the song
with Source = Upload. Wrong extensions, unreadable files, garbage data
and files without audio are rejected; the copied file is deleted again
so nothing is left behind. The page shows the result in a Snackbar.

The music folder is injected so the service is testable without UI.
Tests cover a generated WAV, duplicate names, wrong extension, garbage
files, empty audio and missing files.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-23 10:24:15 +01:00
1 parent 89b7959404
commit 7c95aba30a
7 files changed
+297

No files matched your search

@@ -0,0 +1,27 @@
using Radiosender.Services;
namespace Radiosender.Controllers;
public record UploadResult(bool Success, string Message);
public class UploadController(SongImportService importService)
{
public static string FileDialogFilter { get; } = "Audio files (*.mp3;*.wav)|*.mp3;*.wav";
public UploadResult Upload(string filePath)
{
try
{
var song = importService.Import(filePath);
return new UploadResult(true, $"\"{song.Title}\" ({(int)song.Duration.TotalMinutes}:{song.Duration.Seconds:00}) was added to the library.");
}
catch (SongImportException e)
{
return new UploadResult(false, e.Message);
}
catch (Exception e)
{
return new UploadResult(false, $"The song could not be saved: {e.Message}");
}
}
}