Adding music took two navigation items that each did half the job. The new Import page has both sources as tabs and one shared list of what was added in this session, with the reason for every failure and a link to the library. From computer: drop several MP3 or WAV files or pick them with a multi-select dialog. Files are imported one by one on a background thread with a progress bar, and a failing file does not stop the rest. Openverse: search and download show a progress ring with a status text. Results that are already in the library or have no duration are marked in their row and cannot be imported; a double-click imports. To detect duplicates, songs now store the Openverse result id. The repository adds the column to existing databases and a unique index keeps one song per Openverse result. Refs #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
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 Id { get; init; } = "";
|
|
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(),
|
|
};
|
|
}
|