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:
1 parent
89b7959404
commit
fc461b74cb
7 files changed
+620
No files matched your search
@@ -0,0 +1,36 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Radiosender.Models;
|
||||
|
||||
/// <summary>One audio result of the Openverse search API (fields as documented at api.openverse.org/v1).</summary>
|
||||
public class OpenverseTrack
|
||||
{
|
||||
public string Title { get; init; } = "";
|
||||
public string? Creator { get; init; }
|
||||
public string Url { get; init; } = "";
|
||||
[JsonPropertyName("filetype")]
|
||||
public string? FileType { get; init; }
|
||||
public string License { get; init; } = "";
|
||||
public string? LicenseVersion { get; init; }
|
||||
public string? Attribution { get; init; }
|
||||
|
||||
/// <summary>Length in milliseconds; Openverse leaves it empty for some results.</summary>
|
||||
[JsonPropertyName("duration")]
|
||||
public int? DurationMs { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
public TimeSpan? Duration => DurationMs > 0 ? TimeSpan.FromMilliseconds(DurationMs.Value) : null;
|
||||
|
||||
/// <summary>Songs need a duration for scheduling, so results without one cannot be imported.</summary>
|
||||
public bool CanImport => Duration is not null;
|
||||
|
||||
public string DurationText => Duration?.ToString(@"m\:ss") ?? "unknown";
|
||||
|
||||
/// <summary>Readable license name, for example "CC BY 4.0", "CC0 1.0" or "Public Domain Mark 1.0".</summary>
|
||||
public string LicenseName => License.ToLowerInvariant() switch
|
||||
{
|
||||
"cc0" => $"CC0 {LicenseVersion}".Trim(),
|
||||
"pdm" => $"Public Domain Mark {LicenseVersion}".Trim(),
|
||||
_ => $"CC {License.ToUpperInvariant()} {LicenseVersion}".Trim(),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user