Files
Febe/src/Febe.Core/Export/ExportRunSettings.cs
T
Alby96andClaude Opus 5.5 51150fb611 E4: API dei video fermi e «Salva il fotogramma»
«È un video fermo?» dal visualizzatore (POST /api/media/{id}/still, con
400/404/409/503 e niente salvato negli errori) e l'esito su ogni video
dell'elemento (media[].still), perché l'interfaccia di WP6 lo mostri.

«Salva il fotogramma» salva il fotogramma scelto dall'analisi (il più
nitido, mai uno scuro, risposta 45): «Scarica» da
/api/media/{id}/still/frame con il nome …_fotogramma.png, e «Nella
cartella delle copie» con frames.mode "fermo" attraverso pianificatore,
impostazioni del lavoro e copiatore (FrameMode.Still, suffisso
_fotogramma, stessa identità delle copie dei fotogrammi di E3). Vale per
un video solo (risposta 46); un video non fermo o mai analizzato si
conta come notStill e non si copia.

«Cerca i video fermi» per una selezione: conferma con i conteggi,
avvio, avanzamento e «Interrompi» (/api/still-videos/*). Tutti i DTO nel
FebeJsonContext; i comandi passano dal controllo dell'Origin. Il servizio
registra con ILogger e FebeApp lo chiude all'arresto prima dell'archivio.
LEGGIMI di Febe.Web aggiornato; prove dell'API su video costruiti.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:29:06 +01:00

91 lines
4.0 KiB
C#

using System.Globalization;
using Febe.Core.Storage;
namespace Febe.Core.Export;
/// <summary>
/// Settings of one export job (like <c>ImportRunSettings</c>): a row of the <c>setting</c> table each, so the schema
/// stays as E1 left it. Cleared when the job completes, is cancelled or deleted.
/// </summary>
internal static class ExportRunSettings
{
public static string CopyAgainKey(long runId) => string.Create(CultureInfo.InvariantCulture, $"esportazione.lavoro.{runId}.copia-di-nuovo");
/// <summary>
/// How the frames of a frames job were asked (tappa E3): <c>Istante</c>, <c>Ogni</c> or <c>Numero:N</c>; <c>Fermo</c>
/// for «Salva il fotogramma» of a still video (tappa E4).
/// </summary>
public static string FramesKey(long runId) => string.Create(CultureInfo.InvariantCulture, $"esportazione.lavoro.{runId}.fotogrammi");
/// <summary>«Copia di nuovo» of one copy row: only its exact identity is looked up (decision D11 of tappa E3).</summary>
public static string ExactKey(long runId) => string.Create(CultureInfo.InvariantCulture, $"esportazione.lavoro.{runId}.esatta");
/// <summary>The frames request of a job, or null for a job of whole or converted files.</summary>
public static async Task<(FrameMode Mode, int Count)?> GetFramesAsync(ISettingsStore store, long runId, CancellationToken ct)
{
var text = (await store.GetAsync(FramesKey(runId), ct).ConfigureAwait(false))?.Trim();
if (text is null)
{
return null;
}
if (string.Equals(text, "Istante", StringComparison.Ordinal))
{
return (FrameMode.At, 1);
}
if (string.Equals(text, "Ogni", StringComparison.Ordinal))
{
return (FrameMode.Every, 0);
}
if (string.Equals(text, "Fermo", StringComparison.Ordinal))
{
return (FrameMode.Still, 1);
}
return text.StartsWith("Numero:", StringComparison.Ordinal)
&& int.TryParse(text.AsSpan("Numero:".Length), NumberStyles.None, CultureInfo.InvariantCulture, out var count) && count > 0
? (FrameMode.Count, count)
: null;
}
public static Task SetFramesAsync(ISettingsStore store, long runId, FrameMode mode, int count, CancellationToken ct) =>
store.SetAsync(
FramesKey(runId),
mode switch
{
FrameMode.At => "Istante",
FrameMode.Every => "Ogni",
FrameMode.Still => "Fermo",
_ => string.Create(CultureInfo.InvariantCulture, $"Numero:{count}"),
},
ct);
public static async Task<bool> GetExactAsync(ISettingsStore store, long runId, CancellationToken ct) =>
string.Equals((await store.GetAsync(ExactKey(runId), ct).ConfigureAwait(false))?.Trim(), "1", StringComparison.Ordinal);
public static Task SetExactAsync(ISettingsStore store, long runId, CancellationToken ct) => store.SetAsync(ExactKey(runId), "1", ct);
/// <summary>«Copia di nuovo anche i tolti o superati» was chosen for this job (decision D9).</summary>
public static async Task<bool> GetCopyAgainAsync(ISettingsStore store, long runId, CancellationToken ct)
{
var text = await store.GetAsync(CopyAgainKey(runId), ct).ConfigureAwait(false);
return string.Equals(text?.Trim(), "1", StringComparison.Ordinal);
}
public static Task SetCopyAgainAsync(ISettingsStore store, long runId, bool value, CancellationToken ct) =>
store.SetAsync(CopyAgainKey(runId), value ? "1" : null, ct);
/// <summary>Every key of the job, in one transaction (a run id can be used again after <c>DeleteRunAsync</c>).</summary>
public static Task ClearAsync(ISettingsStore store, long runId, CancellationToken ct) =>
store.SetManyAsync(
new Dictionary<string, string?>
{
[CopyAgainKey(runId)] = null,
[FramesKey(runId)] = null,
[ExactKey(runId)] = null,
},
ct);
}