«Riconosci» parte da una cartella (ExportService.RecognizeAsync) come lavoro di Alberto: sposta una copia automatica, non gira con importazione, ricostruzione o «Copia in…», aspetta fuori dalle sessioni ed è riprendibile. Registra un lavoro di tipo «Riconosci» su ogni file dovuto alla cartella che non è «Copiato» e sui fotogrammi che hanno già una riga lì. Per ogni file la copia guarda il percorso dello schema e «nome (2)» … «nome (50)», nella forma chiesta adesso e come originale, ciascuna con la sua identità; prima i percorsi, poi lunghezza e SHA-256, con la conversione rifatta solo se un file c'è. Un file uguale diventa «Adottato»: la riga «Non riuscito» diventa la copia, l'orfana si ricollega, la «Superato» con gli stessi byte torna «Copiato». Un «Tolto» resta «Tolto» anche se il file è tornato identico (risposta 51 b). L'adozione per percorso è estratta da WriteAsync (TryAdoptAsync) e serve a entrambi. Non scrive né toglie file, neppure i .part di altri; una cartella che non risponde mette in pausa senza segnare nulla; scrive solo l'evento esportazione-riconosci. Il resoconto conta «Non c'è nella cartella» e «Nel percorso c'è un altro file», e solo il secondo è un problema. Un «Riconosci» in pausa non chiede spazio libero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
314 lines
17 KiB
C#
314 lines
17 KiB
C#
using Febe.Core.Codecs.Containers;
|
|
using Febe.Core.Codecs.Images;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Engine;
|
|
using Febe.Core.Library.Conversion;
|
|
using Febe.Core.Storage;
|
|
|
|
namespace Febe.Core.Export;
|
|
|
|
/// <summary>
|
|
/// Texts of the copies to external folders for Alberto (spec §4.10, §10.4): sentence case, dots for thousands, the same
|
|
/// names everywhere. Notes are stored in <c>export_item.note</c> as English codes (<see cref="Notes"/>) and shown with
|
|
/// <see cref="Note"/>.
|
|
/// </summary>
|
|
public static class ExportText
|
|
{
|
|
/// <summary>The codes of <c>export_item.note</c>.</summary>
|
|
public static class Notes
|
|
{
|
|
public const string SourceMissing = "SourceMissing";
|
|
public const string AccountRemoved = "AccountRemoved";
|
|
public const string Removed = "Removed";
|
|
public const string Superseded = "Superseded";
|
|
public const string CopiedForAnotherAccount = "CopiedForAnotherAccount";
|
|
public const string SourceChanged = "SourceChanged";
|
|
public const string TooLargeForFileSystem = "TooLargeForFileSystem";
|
|
public const string NameTaken = "NameTaken";
|
|
public const string PathTaken = "PathTaken";
|
|
public const string NotExported = "NotExported";
|
|
|
|
// Tappa E3 (D19): an item's note is a list of codes separated by spaces, «Code» or «Code:Arg».
|
|
public const string AsIsHeif = ImageConversionLosses.AsIsHeif;
|
|
public const string AsIsAvif = ImageConversionLosses.AsIsAvif;
|
|
public const string AsIsRaw = ImageConversionLosses.AsIsRaw;
|
|
public const string AsIsAnimated = ImageConversionLosses.AsIsAnimated;
|
|
public const string AsIsNotDecodable = ImageConversionLosses.AsIsNotDecodable;
|
|
public const string AsIsDeepColor = ImageConversionLosses.AsIsDeepColor;
|
|
public const string AsIsCmyk = ImageConversionLosses.AsIsCmyk;
|
|
public const string AsIsTooLarge = ImageConversionLosses.AsIsTooLarge;
|
|
public const string AsIsNotRemuxable = MediaConversionResult.AsIsNotRemuxable;
|
|
public const string FrameNotAvailable = "FrameNotAvailable";
|
|
|
|
// Tappa E4: «Salva il fotogramma» of a file that changed meanwhile, and is not a still video as far as Febe knows.
|
|
public const string NotStill = "NotStill";
|
|
public const string TransparencyWhite = ImageConversionLosses.TransparencyWhite;
|
|
public const string CopiedInAnotherFormat = "CopiedInAnotherFormat";
|
|
public const string LostTracks = Mp4Remuxer.LostTracks;
|
|
public const string LostVideoMetadata = Mp4Remuxer.LostVideoMetadata;
|
|
|
|
// Tappa E5. A path too long for the destination: «Non riuscito» like any other, retried by every recovery round
|
|
// (answer 50 of 4 December 2026: no class of failures that never retry by themselves).
|
|
public const string PathTooLong = "PathTooLong";
|
|
|
|
// «Riconosci le copie già presenti» (tappa E5, D13): nothing at the paths looked at, or another file there.
|
|
public const string NotFound = "NotFound";
|
|
public const string Different = "Different";
|
|
}
|
|
|
|
/// <summary>Name of the state of a file of a job.</summary>
|
|
public static string State(ExportItemState state) => state switch
|
|
{
|
|
ExportItemState.Pending => "In attesa",
|
|
ExportItemState.Copied => "Copiato",
|
|
ExportItemState.Adopted => "Adottato",
|
|
ExportItemState.AlreadyCopied => "Già copiato",
|
|
ExportItemState.Skipped => "Saltato",
|
|
ExportItemState.Missing => "File non presente in libreria",
|
|
ExportItemState.Failed => "Non riuscito",
|
|
_ => state.ToString(),
|
|
};
|
|
|
|
/// <summary>Name of the state of a copy.</summary>
|
|
public static string CopyState(ExportCopyState state) => state switch
|
|
{
|
|
ExportCopyState.Copied => "Copiato",
|
|
ExportCopyState.Removed => "Tolto",
|
|
ExportCopyState.Superseded => "Superato",
|
|
ExportCopyState.Failed => "Non riuscito",
|
|
_ => state.ToString(),
|
|
};
|
|
|
|
/// <summary>
|
|
/// The Italian text of a note: its codes (separated by spaces, D19 of tappa E3) each in Italian, joined with « · »;
|
|
/// null for none; an unknown code is shown as it is.
|
|
/// </summary>
|
|
public static string? Note(string? note)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(note))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var codes = note.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
return string.Join(" · ", codes.Select(One));
|
|
}
|
|
|
|
/// <summary>The codes as one note (D19 of tappa E3): the non-empty ones, without repeats, separated by spaces; null for none.</summary>
|
|
public static string? JoinNotes(IEnumerable<string?> codes)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(codes);
|
|
var list = codes.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c!.Trim()).Distinct(StringComparer.Ordinal).ToList();
|
|
return list.Count == 0 ? null : string.Join(' ', list);
|
|
}
|
|
|
|
/// <summary>The reason of «non si porta in MP4», from the code of <see cref="RemuxRefusal"/>.</summary>
|
|
private static string RemuxReason(string reason) => reason switch
|
|
{
|
|
nameof(RemuxRefusal.NotAVideo) => "Febe non lo riconosce come video",
|
|
nameof(RemuxRefusal.ContainerNotRemuxable) => "contenitore",
|
|
nameof(RemuxRefusal.VideoCodec) => "codec video",
|
|
nameof(RemuxRefusal.AudioCodec) => "codec audio",
|
|
nameof(RemuxRefusal.MissingConfiguration) => "configurazione del codec mancante",
|
|
nameof(RemuxRefusal.EncodedTrack) => "tracce codificate",
|
|
nameof(RemuxRefusal.EditList) => "elenco di modifiche",
|
|
nameof(RemuxRefusal.NoSamples) => "nessun fotogramma",
|
|
nameof(RemuxRefusal.Unreadable) => "file rovinato",
|
|
_ => reason,
|
|
};
|
|
|
|
private static string One(string code)
|
|
{
|
|
var colon = code.IndexOf(':', StringComparison.Ordinal);
|
|
var name = colon < 0 ? code : code[..colon];
|
|
var arg = colon < 0 ? null : code[(colon + 1)..];
|
|
const string AsIsVideo = "Video copiato com'è: non si porta in MP4 senza ricodificarlo";
|
|
return name switch
|
|
{
|
|
Notes.AsIsNotRemuxable => arg is { Length: > 0 } ? $"{AsIsVideo} ({RemuxReason(arg)})" : AsIsVideo,
|
|
Notes.LostTracks => arg is { Length: > 0 } ? $"Tracce tolte: {arg}" : "Tracce tolte",
|
|
_ when arg is null => Note1(code) ?? code,
|
|
_ => code,
|
|
};
|
|
}
|
|
|
|
private static string? Note1(string code) => code switch
|
|
{
|
|
Notes.SourceMissing => "File non presente in libreria",
|
|
Notes.AccountRemoved => "L'account è stato rimosso",
|
|
Notes.Removed => "Tolto dalla destinazione: non si ricopia da solo («Copia di nuovo»)",
|
|
Notes.Superseded => "Superato da un file nuovo della libreria: non si ricopia da solo",
|
|
Notes.CopiedForAnotherAccount => "Già copiato per un altro account («Una copia sola»)",
|
|
Notes.SourceChanged => "Il file della libreria è cambiato durante la copia",
|
|
Notes.TooLargeForFileSystem => "Più grande di 4 GB: il disco FAT32 non lo accetta",
|
|
Notes.NameTaken => "Nome già occupato da un altro file: copiato con un nome libero",
|
|
Notes.PathTaken => "Percorso preso nel frattempo: riprova",
|
|
Notes.NotExported => "Non si copia qui: «Esporta questo account» è spento, o il file va in un'altra cartella",
|
|
Notes.AsIsHeif => "HEIC copiato com'è",
|
|
Notes.AsIsAvif => "AVIF copiato com'è",
|
|
Notes.AsIsRaw => "Raw copiato com'è",
|
|
Notes.AsIsAnimated => "Immagine animata copiata com'è: convertita perderebbe i fotogrammi dopo il primo",
|
|
Notes.AsIsNotDecodable => "Copiato com'è: Febe non riesce a leggere l'immagine",
|
|
Notes.AsIsDeepColor => "Copiato com'è: più di 8 bit per colore",
|
|
Notes.AsIsCmyk => "Copiato com'è: immagine CMYK",
|
|
Notes.AsIsTooLarge => "Copiato com'è: troppo grande per il formato scelto",
|
|
Notes.FrameNotAvailable => "Fotogramma non disponibile per questo video",
|
|
Notes.NotStill => "Il video è cambiato: il file di adesso non è un video fermo, o non è stato analizzato",
|
|
Notes.TransparencyWhite => "La trasparenza è diventata bianco",
|
|
Notes.CopiedInAnotherFormat => "Già copiato in un altro formato",
|
|
Notes.PathTooLong => "Percorso troppo lungo per la cartella",
|
|
Notes.NotFound => "Non c'è nella cartella",
|
|
Notes.Different => "Nel percorso c'è un altro file",
|
|
ImageConversionLosses.LostTexts => "Non tenuti: testi",
|
|
ImageConversionLosses.LostColorChunks => "Non tenuti: dati del colore",
|
|
ImageConversionLosses.LostIcc => "Non tenuto: profilo ICC",
|
|
ImageConversionLosses.LostIccTooLarge => "Non tenuto: profilo ICC troppo grande",
|
|
ImageConversionLosses.LostExifTooLarge => "Non tenuto: EXIF troppo grande per JPG",
|
|
ImageConversionLosses.LostXmpTooLarge => "Non tenuto: XMP troppo grande",
|
|
ImageConversionLosses.LostExifUnreadable => "Non tenuto: EXIF rovinato",
|
|
ImageConversionLosses.LostIptc => "Non tenuti: IPTC",
|
|
ImageConversionLosses.LostOtherSegments => "Non tenuti: altri blocchi",
|
|
ImageConversionLosses.LostCommentTooLarge => "Non tenuto: commento troppo lungo",
|
|
ImageConversionLosses.LostExtendedXmp => "Non tenuto: XMP esteso",
|
|
Notes.LostVideoMetadata => "Non tenuti: metadati del video",
|
|
_ => null,
|
|
};
|
|
|
|
/// <summary>«1 file copiato», «1.204 file copiati».</summary>
|
|
public static string Count(int count, string one, string many) => count == 1 ? "1 " + one : ItalianText.Number(count) + " " + many;
|
|
|
|
/// <summary>
|
|
/// The event written when a job ends: «Copia in Disco USB finita: 120 file copiati, 30 già copiati.»; for an automatic
|
|
/// run (tappa E5) «Copia automatica in Disco USB finita: …».
|
|
/// </summary>
|
|
public static string CompletionMessage(ExportRunSummary summary, ExportDestination destination, bool automatic = false)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(summary);
|
|
ArgumentNullException.ThrowIfNull(destination);
|
|
int Of(ExportItemState s) => summary.ByState.GetValueOrDefault(s);
|
|
var parts = new List<string> { Count(Of(ExportItemState.Copied) + Of(ExportItemState.Adopted), "file copiato", "file copiati") };
|
|
if (Of(ExportItemState.AlreadyCopied) > 0)
|
|
{
|
|
parts.Add(Count(Of(ExportItemState.AlreadyCopied), "già copiato", "già copiati"));
|
|
}
|
|
|
|
if (Of(ExportItemState.Skipped) > 0)
|
|
{
|
|
parts.Add(Count(Of(ExportItemState.Skipped), "saltato", "saltati"));
|
|
}
|
|
|
|
if (Of(ExportItemState.Missing) > 0)
|
|
{
|
|
parts.Add(Count(Of(ExportItemState.Missing), "non presente in libreria", "non presenti in libreria"));
|
|
}
|
|
|
|
if (Of(ExportItemState.Failed) > 0)
|
|
{
|
|
parts.Add(Count(Of(ExportItemState.Failed), "non riuscito", "non riusciti"));
|
|
}
|
|
|
|
return $"{(automatic ? "Copia automatica" : "Copia")} in {ExportDestinations.Label(destination)} finita: {string.Join(", ", parts)}.";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether the end of an automatic run is worth an event (answer 54 of 4 December 2026): only when it copied or
|
|
/// adopted something, or something did not succeed. A run that only found files already copied leaves no trace.
|
|
/// </summary>
|
|
public static bool AutomaticRunIsWorthAnEvent(ExportRunSummary summary)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(summary);
|
|
return summary.ByState.GetValueOrDefault(ExportItemState.Copied)
|
|
+ summary.ByState.GetValueOrDefault(ExportItemState.Adopted)
|
|
+ summary.ByState.GetValueOrDefault(ExportItemState.Failed) > 0;
|
|
}
|
|
|
|
/// <summary>The code of the event of «Riconosci le copie già presenti» (tappa E5, D13): its only event.</summary>
|
|
public const string RecognizeEventCode = "esportazione-riconosci";
|
|
|
|
/// <summary>
|
|
/// The event written when «Riconosci le copie già presenti» ends: «Riconosciute 12 copie già presenti in Disco USB.»,
|
|
/// with the files that did not succeed when there are any.
|
|
/// </summary>
|
|
public static string RecognizeMessage(ExportRunSummary summary, ExportDestination destination)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(summary);
|
|
ArgumentNullException.ThrowIfNull(destination);
|
|
var adopted = summary.ByState.GetValueOrDefault(ExportItemState.Adopted);
|
|
var failed = summary.ByState.GetValueOrDefault(ExportItemState.Failed);
|
|
var label = ExportDestinations.Label(destination);
|
|
var text = adopted switch
|
|
{
|
|
0 => $"Nessuna copia già presente da riconoscere in {label}",
|
|
1 => $"Riconosciuta 1 copia già presente in {label}",
|
|
_ => $"Riconosciute {ItalianText.Number(adopted)} copie già presenti in {label}",
|
|
};
|
|
return failed > 0 ? $"{text}; {Count(failed, "non riuscito", "non riusciti")}." : text + ".";
|
|
}
|
|
|
|
/// <summary>The severity of the event of «Riconosci»: a warning with failures, information when nothing was recognised.</summary>
|
|
public static EventSeverity RecognizeSeverity(ExportRunSummary summary)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(summary);
|
|
return summary.ByState.GetValueOrDefault(ExportItemState.Failed) > 0 ? EventSeverity.Warning
|
|
: summary.ByState.GetValueOrDefault(ExportItemState.Adopted) > 0 ? EventSeverity.Success
|
|
: EventSeverity.Info;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Why an automatic run was cancelled (tappa E5, answer 52): its destination was switched off, retired, or lost its
|
|
/// account meanwhile. The copies made stay.
|
|
/// </summary>
|
|
public const string AutomaticTurnedOff = "«Automatica» è stata spenta: i file rimasti non si copiano da soli.";
|
|
|
|
/// <summary>
|
|
/// The answer to «Interrompi» of an automatic copy (answer 53): what was copied stays, and the automatic copies wait
|
|
/// until <paramref name="until"/> («Riprendi ora» before).
|
|
/// </summary>
|
|
public static string AutomaticInterrupted(DateTimeOffset until, TimeZoneInfo zone) =>
|
|
$"Copia automatica interrotta: quello che è stato copiato resta; riprende da sola alle {ItalianText.Clock(until, zone)}.";
|
|
|
|
/// <summary>
|
|
/// A paused destination still without room for the next file of its paused job (tappa E5, D11): the pause stays.
|
|
/// </summary>
|
|
public static string NoSpaceForNext(ExportDestination destination, long free, long bytes) =>
|
|
$"Su {ExportDestinations.Label(destination)} restano {ItalianText.Bytes(free)}: per il prossimo file ({ItalianText.Bytes(bytes)}) serve più spazio, "
|
|
+ $"con un margine di {ItalianText.Bytes(ExportSpace.Margin)}. Libera spazio, poi riprendi.";
|
|
|
|
/// <summary>The event of «Controlla le copie».</summary>
|
|
public static string CheckMessage(int checkedCopies, int removed, ExportDestination destination)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(destination);
|
|
var text = $"Controllate {ItalianText.Number(checkedCopies)} copie in {ExportDestinations.Label(destination)}: ";
|
|
return text + (removed == 0 ? "ci sono tutte." : $"{Count(removed, "non c'è più (tolta)", "non ci sono più (tolte)")}.");
|
|
}
|
|
|
|
/// <summary>The space is not enough for the next file (decision D16).</summary>
|
|
public static string NoSpace(ExportDestination destination, long free, string file, long bytes) =>
|
|
$"Su {ExportDestinations.Label(destination)} restano {ItalianText.Bytes(free)}: per copiare {file} ({ItalianText.Bytes(bytes)}) serve più spazio, "
|
|
+ $"con un margine di {ItalianText.Bytes(ExportSpace.Margin)}. Libera spazio, poi riprendi.";
|
|
|
|
/// <summary>The disk said it is full.</summary>
|
|
public static string DiskFull(ExportDestination destination) =>
|
|
$"Su {ExportDestinations.Label(destination)} non c'è più spazio: libera spazio, poi riprendi.";
|
|
|
|
/// <summary>A file over the FAT32 limit.</summary>
|
|
public static string TooLarge(long bytes) =>
|
|
$"Il file pesa {ItalianText.Bytes(bytes)}: su un disco FAT32 un file non può superare 4 GB.";
|
|
|
|
/// <summary>The destination was retired while a job used it.</summary>
|
|
public const string RetiredDestination = "La cartella è stata tolta.";
|
|
|
|
/// <summary>An error for Alberto, without paths of secrets: the message of a file error, or a generic sentence.</summary>
|
|
public static string ErrorText(Exception ex)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(ex);
|
|
return ex switch
|
|
{
|
|
ExportFolderException folder => folder.Message,
|
|
IOException io => $"Errore di lettura o scrittura: {io.Message}",
|
|
UnauthorizedAccessException => "Febe non ha il permesso di scrivere nella cartella: controlla i permessi.",
|
|
_ => $"Errore inatteso ({ex.GetType().Name}): riprova; se si ripete, segnalalo.",
|
|
};
|
|
}
|
|
}
|