feat: add Openverse audio search and import

Add an Openverse page that searches free audio through the anonymous
Openverse API, previews a result by streaming its URL with MediaPlayer
and imports it into the library.

OpenverseClient uses HttpClient with a timeout and a generic User-Agent.
It downloads only the result's https URL, limits files to 50 MB, never
overwrites an existing file and deletes partial files on failure.
Timeouts, HTTP 429 and other errors become readable messages. Imported
songs get Source = Openverse plus license and attribution from the API.
Results without a duration cannot be imported, because songs need one.

Refs #5

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

No files matched your search

@@ -0,0 +1,40 @@
using System.IO;
using Radiosender.Models;
using Radiosender.Services;
namespace Radiosender.Controllers;
public class OpenverseController(OpenverseClient client, SongRepository songs)
{
public Task<IReadOnlyList<OpenverseTrack>> SearchAsync(string query, CancellationToken cancellationToken = default) =>
client.SearchAsync(query, cancellationToken);
/// <summary>Downloads the track and stores it as a song with its license and attribution.</summary>
public async Task<Song> ImportAsync(OpenverseTrack track, CancellationToken cancellationToken = default)
{
if (track.Duration is not { } duration)
throw new OpenverseException("This result has no duration and cannot be imported.");
var path = await client.DownloadAsync(track, cancellationToken);
var song = new Song
{
Title = track.Title,
Artist = string.IsNullOrWhiteSpace(track.Creator) ? "Unknown" : track.Creator,
Duration = duration,
FilePath = path,
Source = SongSource.Openverse,
License = track.LicenseName,
Attribution = track.Attribution,
};
try
{
songs.Add(song);
}
catch
{
File.Delete(path); // no orphaned file without a database entry
throw;
}
return song;
}
}