diff --git a/src/Febe.Web/wwwroot/css/febe.css b/src/Febe.Web/wwwroot/css/febe.css index b39c594..db8cdc5 100644 --- a/src/Febe.Web/wwwroot/css/febe.css +++ b/src/Febe.Web/wwwroot/css/febe.css @@ -1258,6 +1258,12 @@ input[type=range].cursore.scorri-fotogramma{width:100%} .scheda-conversione .riga-conteggi{margin-top:0} .scheda-conversione .avviso{margin:10px 0 0} +/* ---------- video fermi (§4.10, tappa E4) ---------- */ +.dialogo.cerca-fermi{width:560px} +.riepilogo-fermi{margin-bottom:12px} +.riepilogo-fermi .avviso{margin-top:8px} +.vis .scheda dd.riga-fermo .analizza-di-nuovo{flex:none} + /* ---------- animazioni: solo in risposta a un gesto, e mai con le animazioni ridotte ---------- */ @keyframes febe-compare{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}} .dialogo,.menu,.breve{animation:febe-compare .14s ease-out} diff --git a/src/Febe.Web/wwwroot/js/pages/account.js b/src/Febe.Web/wwwroot/js/pages/account.js index 90ddfdc..0a477ee 100644 --- a/src/Febe.Web/wwwroot/js/pages/account.js +++ b/src/Febe.Web/wwwroot/js/pages/account.js @@ -21,6 +21,7 @@ import { kindName, orderEditor, orderOrDefault } from './download-order.js'; import { openViewer } from './viewer.js'; import { copiesApi, copiesLabel, copiesMenu, copyDialog, destinationDialog, exportButton, exportMenu, separator } from './export-dialogs.js'; import { framesDialog } from './frames.js'; +import { stillVideosDialog } from './still-videos.js'; const KINDS = [ { key: 'post', api: 'posts', stat: 'posts', label: 'scheda.tipi.posts' }, @@ -217,6 +218,7 @@ async function contentsTab(page, route, detail) { selection: mosaic.files ? { mediaIds: [...mosaic.selected] } : { entryIds: mosaic.selectedEntries().ids }, hasDestination, }), + stillSelected: () => stillVideosDialog(mosaic.files ? { mediaIds: [...mosaic.selected] } : { entryIds: mosaic.selectedEntries().ids }), deleteSelected: async () => { const { ids, files } = mosaic.selectedEntries(); const removed = await confirmDelete(ids, mosaic.files ? { files: mosaic.selected.size, total: files } : null); @@ -276,6 +278,8 @@ async function contentsTab(page, route, detail) { const onChange = later(() => mosaic && mosaic.refresh().catch(() => {}), 500); const onMarks = later(() => mosaic && mosaic.refreshMarks().catch(() => {}), 600); page.onLibrary((change) => { + // An analysis (tappa E4) changes nothing here: the filter «Video fermi» is of the Libreria only. + if (change.reason === 'fermi') return; if (!change.accountId || change.accountId === detail.account.id) { onChange(); if (change.reason === 'export') onMarks(); diff --git a/src/Febe.Web/wwwroot/js/pages/dashboard-export.js b/src/Febe.Web/wwwroot/js/pages/dashboard-export.js index 4045da6..0ba77d1 100644 --- a/src/Febe.Web/wwwroot/js/pages/dashboard-export.js +++ b/src/Febe.Web/wwwroot/js/pages/dashboard-export.js @@ -4,11 +4,14 @@ // seconds otherwise (decision D20), as the import does. A pause is an amber notice here, never the red strip. // Tappa E3: the card «Conversione della libreria» (shown once it is on or has rows) and, in the resoconto, the files // copied as they are per account and the «Note» (what a conversion could not keep, a file copied as it is). +// Tappa E4: the card «Video fermi» while «Cerca i video fermi» works (progress, why it waits, «Interrompi») and, until +// Febe closes, what the last one found. import { api, withCarried } from '../core/api.js'; import { h, icon, fill, later } from '../core/dom.js'; import { t, at, bytes, capitalize, number } from '../core/text.js'; import { confirmDialog, dialog, label, showError, toast } from '../core/ui.js'; +import { STILL_LIBRARY, endText, readStillVideos, stopStillVideos } from './still-videos.js'; const STATE_LOOK = { running: ['accento', 'play'], @@ -26,12 +29,14 @@ export async function mountExport(page) { const current = h('section.blocco.copia-in-corso'); const pending = h('section.blocco', { hidden: true }); const conversion = h('section.blocco.conversione-libreria', { hidden: true }); + const stills = h('section.blocco.ricerca-fermi', { hidden: true }); const recent = h('section.blocco'); - fill(page.body, h('div.attivita.esportazione-dashboard', current, pending, conversion, recent)); + fill(page.body, h('div.attivita.esportazione-dashboard', current, pending, stills, conversion, recent)); let overview = null; let runs = []; let progress = null; + let stillJob = null; let wasRunning = null; let timer = 0; let ticks = 0; @@ -79,7 +84,7 @@ export async function mountExport(page) { poll(); return; } - timer = setTimeout(poll, progress && progress.running ? 1000 : 5000); + timer = setTimeout(poll, (progress && progress.running) || (stillJob && stillJob.running) ? 1000 : 5000); } async function read() { @@ -89,11 +94,19 @@ export async function mountExport(page) { if (error.name === 'AbortError') return; progress = null; } + try { + stillJob = await readStillVideos({ signal: page.signal }); + } catch (error) { + if (error.name === 'AbortError') return; + stillJob = null; + } drawCurrent(); + drawStills(); const running = Boolean(progress && progress.running); ticks += 1; // The jobs and the folders follow the copy: when it starts or ends, and every few seconds while it works. - if (running !== wasRunning || !running || ticks % 5 === 0) await loadSide(); + const quick = running || Boolean(stillJob && stillJob.running); + if (running !== wasRunning || !quick || ticks % 5 === 0) await loadSide(); wasRunning = running; } @@ -216,6 +229,48 @@ export async function mountExport(page) { again(); } + // ------------------------------------------------------------------------------------------- video fermi + function drawStills() { + const job = stillJob; + stills.hidden = !job || !(job.running || job.total); + if (stills.hidden) { + stills.replaceChildren(); + return; + } + const head = h('div.testa-blocco', h('h2', t('esportazione.fermi.dashboard.titolo'))); + if (!job.running) { + fill(stills, head, h('div.pannello.scheda-conversione', h('div.riga-conteggi', + h('span', endText(job)), + job.still ? h('a.btn.nudo.piccolo', { href: withCarried(STILL_LIBRARY) }, t('esportazione.fermi.mostra')) : null))); + return; + } + // Redrawn every second: the button keeps the focus of the keyboard. + const focused = stills.contains(document.activeElement); + const percent = job.total ? Math.round((job.done / job.total) * 100) : 0; + const count = [t('esportazione.fermi.dashboard.avanzamento', { fatti: job.done, n: job.total })]; + if (job.still) count.push(t('esportazione.fermi.dashboard.fermi', { n: job.still })); + fill(stills, head, h('div.pannello.avanzamento-import.avanzamento-copia.avanzamento-fermi', + h('h2.sez', t('esportazione.fermi.dashboard.barra')), + h('div.misura.grande-misura', { role: 'progressbar', 'aria-valuemin': '0', 'aria-valuemax': '100', 'aria-valuenow': String(percent), 'aria-label': t('esportazione.fermi.dashboard.barra') }, + h('i', { style: { width: `${percent}%` } })), + h('p.conteggio.dati', count.join(' · ')), + job.waiting ? h('p.avviso.ambra.fase-copia', icon('hourglass', 's'), h('span', job.waiting)) : null, + h('p.aiuto.piccolo.file-corrente', !job.waiting && job.currentMediaId != null ? t('esportazione.fermi.dashboard.analizzo') : ''), + h('div.riga-azione', h('button.btn', { type: 'button', disabled: job.stopped, onclick: interruptStills }, icon('x', 's'), t('esportazione.fermi.dashboard.interrompi'))))); + const button = focused && stills.querySelector('button:not([disabled])'); + if (button) button.focus(); + } + + async function interruptStills(e) { + e.currentTarget.disabled = true; + try { + await stopStillVideos(); + } catch (error) { + showError(error); + } + again(); + } + // ------------------------------------------------------------------------------------------- library conversion function drawConversion() { const c = overview && overview.libraryConversion; diff --git a/src/Febe.Web/wwwroot/js/pages/frames.js b/src/Febe.Web/wwwroot/js/pages/frames.js index 1c93f2b..1aa2ae7 100644 --- a/src/Febe.Web/wwwroot/js/pages/frames.js +++ b/src/Febe.Web/wwwroot/js/pages/frames.js @@ -5,8 +5,10 @@ // perdita; PNG by default, JPG says «con perdita»); and where they go: «Scarica» (one image, or a zip) or «Nella // cartella delle copie» (an export job to the folder of each account, only when one exists). «Il fotogramma non ha // l'audio» is always said. The dialog never writes a file itself: the server does, through its usual addresses. +// Tappa E4: «Salva il fotogramma» of a still video is this dialog without the three ways (the analysis has chosen the +// frame: the sharpest it looked at). -import { api, withCarried } from '../core/api.js'; +import { api, download, withCarried } from '../core/api.js'; import { h, icon, fill, later, uid } from '../core/dom.js'; import { t, number, bytes } from '../core/text.js'; import { dialog, radio, segmented, showError, toast } from '../core/ui.js'; @@ -54,13 +56,15 @@ function parseSeconds(text) { /** * Opens «Fotogrammi…». From the viewer: { mediaId, atMs, hasDestination } (one video, at the player's time). From a * selection: { selection: { mediaIds } | { entryIds } | { query, mode }, hasDestination }. hasDestination: a folder of - * the copies exists for the files, so «Nella cartella delle copie» can be chosen. Resolves when the dialog closes. + * the copies exists for the files, so «Nella cartella delle copie» can be chosen. still: { label } with mediaId opens + * «Salva il fotogramma» of a still video (tappa E4): the frame at the label, chosen by the analysis. Resolves when the + * dialog closes. */ -export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDestination = false }) { +export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDestination = false, still = null }) { const single = mediaId != null; const chosen = single ? { mediaIds: [mediaId] } : selection; const state = { - mode: 'istante', + mode: still ? 'fermo' : 'istante', atMs: Math.max(0, Math.round(atMs || 0)), every: '2', count: '6', @@ -70,7 +74,7 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe }; return dialog({ - title: t(single ? 'esportazione.fotogrammi.titolo' : 'esportazione.fotogrammi.titoloSelezione'), + title: still ? t('esportazione.fermi.salva') : t(single ? 'esportazione.fotogrammi.titolo' : 'esportazione.fotogrammi.titoloSelezione'), className: 'fotogrammi', build: (close) => { const body = h('div.contenuto', h('p.aiuto', t('esportazione.fotogrammi.apro'))); @@ -175,13 +179,16 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe /** The request of the frames chosen, or null while a field is not valid. */ function request() { const base = { mode: state.mode, format: state.format }; + if (still) return base; if (state.mode === 'istante') return parseInstant(timeField.value) == null ? null : { ...base, atMs: state.atMs }; if (state.mode === 'ogni') return everyMs() == null ? null : { ...base, everyMs: everyMs() }; return countValue() == null ? null : { ...base, count: countValue() }; } function drawMode() { - if (state.mode === 'istante') { + if (still) { + fill(modeBox, preview, h('p.aiuto.istante-mostrato', t('esportazione.fermi.salvaQuale', { istante: still.label }))); + } else if (state.mode === 'istante') { fill(modeBox, single ? preview : null, single ? scrubber : null, @@ -214,8 +221,24 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe return withCarried(`/api/media/${mediaId}/frame?at=${Math.max(0, Math.round(ms))}&max=${max}`); } + /** «Salva il fotogramma»: one picture, the frame that will be saved. An image tells no reason, a question does. */ + function drawStillPreview() { + const url = withCarried(`/api/media/${mediaId}/still/frame?max=480`); + const img = h('img', { src: url, alt: t('esportazione.fermi.salvaAnteprima') }); + img.addEventListener('error', async () => { + let message = t('esportazione.fotogrammi.nonDisponibile'); + try { + await api(url, { raw: true }); + } catch (error) { + message = error.message; + } + if (!closed) fill(preview, h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', message))); + }); + fill(preview, img); + } + async function drawPreviews() { - if (!single) return; + if (!single || still) return; const wanted = request(); const mine = ++stripToken; if (!wanted) return; @@ -275,11 +298,11 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe loadPlan(); }; const outputs = h('div.scelte', { role: 'radiogroup', 'aria-label': t('esportazione.fotogrammi.uscita') }, - radio({ name: outputName, value: 'scarica', checked: true, onchange: pickOutput, labelNode: h('span', h('b', t('esportazione.fotogrammi.scarica')), h('small', t('esportazione.fotogrammi.scaricaAiuto'))) }), + radio({ name: outputName, value: 'scarica', checked: true, onchange: pickOutput, labelNode: h('span', h('b', t('esportazione.fotogrammi.scarica')), h('small', t(still ? 'esportazione.fermi.salvaScaricaAiuto' : 'esportazione.fotogrammi.scaricaAiuto'))) }), (() => { const r = radio({ name: outputName, value: 'cartella', checked: false, onchange: pickOutput, - labelNode: h('span', h('b', t('esportazione.fotogrammi.cartella')), h('small', t(hasDestination ? 'esportazione.fotogrammi.cartellaAiuto' : 'esportazione.fotogrammi.nessunaCartella'))), + labelNode: h('span', h('b', t('esportazione.fotogrammi.cartella')), h('small', t(!hasDestination ? 'esportazione.fotogrammi.nessunaCartella' : still ? 'esportazione.fermi.salvaCartellaAiuto' : 'esportazione.fotogrammi.cartellaAiuto'))), }); if (!hasDestination) { r.input.disabled = true; @@ -299,6 +322,13 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe summary.replaceChildren(); return; } + if (still && state.output === 'scarica') { + // One frame, always the one shown: nothing to count. + plan = { kind: 'scarica', frames: 1, summary: t('esportazione.fermi.salvaRiepilogo') }; + drawSummary(); + drawStart(); + return; + } fill(summary, h('p.aiuto', t('esportazione.fotogrammi.conto'))); try { const result = state.output === 'cartella' @@ -334,7 +364,7 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe h('p.riepilogo-copia', parts.flatMap((x, i) => (i ? [' · ', x] : [x]))), rows.length ? h('ul.destinazioni-copia.pannello', rows) : null, p.overCap ? h('div.avviso.ambra', icon('triangle-alert', 's'), h('span', t('esportazione.fotogrammi.oltre'))) : null, - !p.frames && !p.overCap ? h('p.aiuto', t(p.hasDestination === false ? 'esportazione.copia.nessunaCartella' : 'esportazione.fotogrammi.nienteCartella')) : null); + !p.frames && !p.overCap ? h('p.aiuto', t(p.hasDestination === false ? 'esportazione.copia.nessunaCartella' : still ? 'esportazione.fermi.salvaNiente' : 'esportazione.fotogrammi.nienteCartella')) : null); } else { fill(summary, h('p.riepilogo-copia', h('b', p.summary)), @@ -372,6 +402,10 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe const job = await api('/api/export/start', { method: 'POST', body: { ...chosen, frames } }); toast(job.message, '', job.runIds.length ? { label: t('esportazione.copia.vediAvanzamento'), href: '/dashboard/esportazione' } : null); close(job); + } else if (still) { + await download(`/api/media/${mediaId}/still/frame?format=${state.format}&download=1`, null, 'fotogramma.png'); + toast(t('esportazione.fotogrammi.scaricati', { n: 1 })); + close(frames); } else { const ready = await api('/api/frames/download-token', { method: 'POST', body: { ...chosen, frames } }); const a = h('a', { href: withCarried(ready.url), download: '' }); @@ -393,8 +427,8 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe function drawAll() { fill(body, h('section.parte-dialogo', - h('h3', t('esportazione.fotogrammi.quali')), - modes, modeBox), + h('h3', t(still ? 'esportazione.fermi.salvaAnteprima' : 'esportazione.fotogrammi.quali')), + still ? null : modes, modeBox), h('section.parte-dialogo', h('h3', t('esportazione.fotogrammi.formato')), formats, lossyNote, @@ -404,10 +438,11 @@ export function framesDialog({ mediaId = null, atMs = 0, selection = null, hasDe outputs, summary)); drawMode(); changed(); + if (still) drawStillPreview(); } async function begin() { - if (!single) { + if (!single || still) { drawAll(); return; } diff --git a/src/Febe.Web/wwwroot/js/pages/library.js b/src/Febe.Web/wwwroot/js/pages/library.js index faaae67..44a7815 100644 --- a/src/Febe.Web/wwwroot/js/pages/library.js +++ b/src/Febe.Web/wwwroot/js/pages/library.js @@ -7,6 +7,8 @@ // in…»), «Copia in…» in the selection bar and the «Copie» filter, these two only once a folder of the copies exists. // Tappa E3: «Fotogrammi…» in the selection bar (always: the photos are skipped and the dialog says so), and the // confirmation of «Elimina» counts the converted files of the library that go with the entries. +// Tappa E4: the chip «Video fermi» after «Video», and «Cerca i video fermi» in the selection bar (one video at a time, +// on request only; the progress and «Interrompi» are in Dashboard → Esportazione). import { api, download, withCarried } from '../core/api.js'; import { caps } from '../core/context.js'; @@ -20,11 +22,14 @@ import { welcome } from './welcome.js'; import { openViewer } from './viewer.js'; import { copiesApi, copiesLabel, copiesMenu, copyDialog, exportButton as exportMenuButton, exportMenu } from './export-dialogs.js'; import { framesDialog } from './frames.js'; +import { stillVideosDialog } from './still-videos.js'; const KINDS = [ { key: 'tutto', api: 'all', label: 'libreria.tipi.all' }, { key: 'foto', api: 'photos', label: 'libreria.tipi.photos' }, { key: 'video', api: 'videos', label: 'libreria.tipi.videos' }, + // Tappa E4 (§16 domanda 40): the entries with a video analysed as «Fermo»; Libreria only, not the account tabs. + { key: 'fermi', api: 'stillvideos', label: 'libreria.tipi.stillVideos' }, { key: 'storie', api: 'stories', label: 'libreria.tipi.stories' }, { key: 'evidenza', api: 'highlights', label: 'libreria.tipi.highlights' }, { key: 'taggati', api: 'tagged', label: 'libreria.tipi.tagged' }, @@ -306,7 +311,7 @@ export default { page.saveBar(null); return; } - page.saveBar(selectionBar(mosaic, selected, { cancel: () => setSelecting(false), exportSelected, deleteSelected, copySelected: hasDestinations ? copySelected : null, framesSelected })); + page.saveBar(selectionBar(mosaic, selected, { cancel: () => setSelecting(false), exportSelected, deleteSelected, copySelected: hasDestinations ? copySelected : null, framesSelected, stillSelected })); } function setSelecting(on) { @@ -333,6 +338,10 @@ export default { return framesDialog({ selection: mosaic.files ? { mediaIds: [...mosaic.selected] } : { entryIds: mosaic.selectedEntries().ids }, hasDestination: hasDestinations }); } + function stillSelected() { + return stillVideosDialog(mosaic.files ? { mediaIds: [...mosaic.selected] } : { entryIds: mosaic.selectedEntries().ids }); + } + async function exportSelected() { try { await download('/api/entries/export', { ids: mosaic.selectedEntries().ids }, 'febe-elementi.csv'); @@ -438,6 +447,8 @@ export default { // Copies done or a folder changed: the counts may stay the same, the marks of the tiles do not. const onExportChange = later(() => mosaic && mosaic.refreshMarks().catch(() => {}), 600); page.onLibrary((change) => { + // An analysis (tappa E4) changes only what «Video fermi» shows. + if (change && change.reason === 'fermi' && state.tipo !== 'fermi') return; onLibraryChange(); if (change && change.reason === 'export') onExportChange(); }); @@ -454,11 +465,12 @@ export default { /** * The bar of the selection (Libreria and account view): how many are chosen, «Esporta l'elenco», «Copia in…» (only - * with copySelected, when a folder of the copies exists), «Fotogrammi…» (with framesSelected) and «Elimina». With - * «Tutte le foto» it counts the files and says how many entries they belong to: the CSV list and «Elimina» work on - * those, «Copia in…» and «Fotogrammi…» on the chosen files. + * with copySelected, when a folder of the copies exists), «Fotogrammi…» (with framesSelected), «Cerca i video fermi» + * (with stillSelected, tappa E4) and «Elimina». With «Tutte le foto» it counts the files and says how many entries they + * belong to: the CSV list and «Elimina» work on those, «Copia in…», «Fotogrammi…» and «Cerca i video fermi» on the + * chosen files. */ -export function selectionBar(mosaic, selected, { cancel, exportSelected, deleteSelected, copySelected = null, framesSelected = null }) { +export function selectionBar(mosaic, selected, { cancel, exportSelected, deleteSelected, copySelected = null, framesSelected = null, stillSelected = null }) { const n = selected.size; const entries = mosaic.selectedEntries().ids.length; let note = t('selezione.nessuno'); @@ -471,6 +483,7 @@ export function selectionBar(mosaic, selected, { cancel, exportSelected, deleteS h('button.btn', { type: 'button', disabled: !n, onclick: exportSelected }, icon('file-down'), t('selezione.esporta')), copySelected ? h('button.btn', { type: 'button', disabled: !n, onclick: copySelected }, icon('copy'), t('esportazione.selezione.copia')) : null, framesSelected ? h('button.btn.fotogrammi-selezione', { type: 'button', disabled: !n, onclick: framesSelected }, icon('image'), t('esportazione.selezione.fotogrammi')) : null, + stillSelected ? h('button.btn.fermi-selezione', { type: 'button', disabled: !n, onclick: stillSelected }, icon('search'), t('esportazione.selezione.fermi')) : null, h('button.btn.pericolo', { type: 'button', disabled: !n, onclick: deleteSelected }, icon('trash-2'), t('selezione.elimina', { n: entries })))); } diff --git a/src/Febe.Web/wwwroot/js/pages/still-videos.js b/src/Febe.Web/wwwroot/js/pages/still-videos.js new file mode 100644 index 0000000..1b4b8d4 --- /dev/null +++ b/src/Febe.Web/wwwroot/js/pages/still-videos.js @@ -0,0 +1,155 @@ +// Video fermi (spec §4.10, §10.3, tappa E4): what the viewer says of an analysed video, the confirmation of «Cerca i +// video fermi» of a selection (from the dialogs of mockup 13) and the following of its job. The analysis is only ever +// asked for: «È un video fermo?» in the viewer, or «Cerca i video fermi» for a selection. The job works on the server, one +// video at a time, never during an engine session; its progress and «Interrompi» are in Dashboard → Esportazione, and +// the page that started it says when it ends. + +import { api } from '../core/api.js'; +import { h, icon, fill } from '../core/dom.js'; +import { t } from '../core/text.js'; +import { dialog, showError, toast } from '../core/ui.js'; + +/** How often a job is asked how far it is (milliseconds). */ +const FOLLOW = 1500; + +/** Where the progress of the job is. */ +const PROGRESS_PAGE = '/dashboard/esportazione'; + +/** The library filtered by «Video fermi» (§16 domanda 40). */ +export const STILL_LIBRARY = '/libreria?tipo=fermi'; + +/** A video that can be analysed: in the library, readable, and with frames Febe can take. */ +export function canAnalyse(media) { + return Boolean(media && media.kind === 'video' && media.available && !media.damaged && media.framesAvailable !== false); +} + +/** The words of an analysis in the panel «File» of the viewer. */ +export function stillText(still) { + const codes = String(still.note || '').split(' ').map((code) => code.split(':')[0]).filter(Boolean); + if (still.outcome === 'still') { + return t('esportazione.fermi.fermo') + + (codes.includes('SmallMotion') ? t('esportazione.fermi.piccolaParte') : '') + + (still.frameLabel ? t('esportazione.fermi.istante', { istante: still.frameLabel }) : ''); + } + if (still.outcome === 'moving') return t('esportazione.fermi.inMovimento'); + const reasons = t('esportazione.fermi.motivi'); + const reason = codes.map((code) => reasons[code]).find(Boolean); + return reason ? t('esportazione.fermi.nonAnalizzabilePerche', { motivo: reason }) : t('esportazione.fermi.nonAnalizzabile'); +} + +// ------------------------------------------------------------------------------------------------- the job + +let following = 0; +let atWork = false; + +/** + * Reads the job «Cerca i video fermi». While it works it is followed wherever the page goes, and its end is said once + * («Analizzati 28 video: 3 fermi, 24 in movimento, 1 non analizzabile»). + */ +export async function readStillVideos(options = {}) { + const job = await api('/api/still-videos/progress', options); + noteJob(job); + return job; +} + +function noteJob(job) { + const ended = atWork && !job.running; + atWork = job.running; + clearTimeout(following); + if (job.running) following = setTimeout(follow, FOLLOW); + if (ended && job.total) sayEnd(job); +} + +async function follow() { + try { + await readStillVideos(); + } catch { + // Febe does not answer for a moment: asked again, at a slower pace. + following = setTimeout(follow, FOLLOW * 4); + } +} + +/** What a job that is over found. */ +export function endText(job) { + if (!job.stopped) return `${job.summary}.`; + return job.done ? t('esportazione.fermi.interrotta', { riepilogo: job.summary }) : t('esportazione.fermi.interrottaSubito'); +} + +function sayEnd(job) { + toast(endText(job), '', job.still ? { label: t('esportazione.fermi.mostra'), href: STILL_LIBRARY } : null); +} + +/** «Interrompi»: the video at work is left, the outcomes already found stay. */ +export async function stopStillVideos() { + const job = await api('/api/still-videos/stop', { method: 'POST' }); + noteJob(job); + return job; +} + +// ------------------------------------------------------------------------------------------------- the confirmation + +/** + * «Cerca i video fermi» of a selection ({ mediaIds } or { entryIds }): how many videos there are to analyse, how many + * are already, the photos that are skipped, and the button that starts the job. Resolves when the dialog closes. + */ +export function stillVideosDialog(selection) { + return dialog({ + title: t('esportazione.fermi.cercaTitolo'), + className: 'cerca-fermi', + build: (close) => { + const summary = h('div.riepilogo-fermi', { 'aria-live': 'polite' }, h('p.aiuto', t('esportazione.fermi.conto'))); + const start = h('button.btn.primo', { type: 'button', disabled: true, onclick: () => go() }); + const cancel = h('button.btn.nudo', { type: 'button', autofocus: true, onclick: () => close(undefined) }, t('comune.annulla')); + let plan = null; + let closed = false; + let busy = false; + + function draw() { + fill(start, icon('search'), t('esportazione.fermi.analizza', { n: plan ? plan.toAnalyse : 0 })); + start.disabled = busy || !plan || !plan.toAnalyse; + } + + async function go() { + if (busy || !plan) return; + busy = true; + draw(); + try { + const job = await api('/api/still-videos/start', { method: 'POST', body: selection }); + if (job.running) toast(t('esportazione.fermi.avviata', { n: plan.toAnalyse }), '', { label: t('esportazione.copia.vediAvanzamento'), href: PROGRESS_PAGE }); + else toast(t('esportazione.fermi.niente')); + noteJob(job); + close(job); + } catch (error) { + busy = false; + draw(); + showError(error); + } + } + + async function count() { + try { + plan = await api('/api/still-videos/plan', { method: 'POST', body: selection }); + } catch (error) { + if (!closed) fill(summary, h('div.avviso.rosso', icon('octagon-alert', 's'), h('span', error.message))); + return; + } + if (closed) return; + fill(summary, + h('p.riepilogo-copia', h('b', plan.summary)), + plan.toAnalyse ? null : h('p.aiuto', t(plan.videos ? 'esportazione.fermi.niente' : 'esportazione.fermi.nienteVideo')), + plan.toAnalyse && plan.waiting ? h('div.avviso.ambra', icon('hourglass', 's'), h('span', plan.waiting)) : null); + draw(); + } + + draw(); + count(); + return { + body: h('div.contenuto', summary, h('p.aiuto', t('esportazione.fermi.cercaAiuto')), h('p.aiuto', t('esportazione.fermi.cercaRiapertura'))), + footer: h('footer', h('div.destra', cancel, start)), + onClose: () => { + closed = true; + }, + }; + }, + }); +} diff --git a/src/Febe.Web/wwwroot/js/pages/viewer.js b/src/Febe.Web/wwwroot/js/pages/viewer.js index b66946f..9ad44c1 100644 --- a/src/Febe.Web/wwwroot/js/pages/viewer.js +++ b/src/Febe.Web/wwwroot/js/pages/viewer.js @@ -4,6 +4,8 @@ // Alberto's own browser, never in Febe's), «Elimina dalla libreria». Tappa E3: «Fotogramma» on a video whose frames // can be taken (the dialog «Fotogrammi…» opens at the player's time), the copy rows with their form («· intero», «· JPG», // «· fotogramma a 0:01 · PNG») and the converted files of the library next to the original («Convertito in PNG»). +// Tappa E4: «È un video fermo?» on a video never analysed, the chip and the row «Video fermo» of one that is, and «Salva +// il fotogramma» of a still video (here only, §16 domanda 46). import { api, withCarried } from '../core/api.js'; import { caps, serverNow } from '../core/context.js'; @@ -14,6 +16,7 @@ import { avatar, label, showError, toast } from '../core/ui.js'; import { confirmDelete } from './library.js'; import { copyAgain, copyDialog } from './export-dialogs.js'; import { formatLabel, framesDialog } from './frames.js'; +import { canAnalyse, stillText } from './still-videos.js'; const KIND_ICON = { post: 'image', story: 'circle-dashed', highlight: 'star', tagged: 'square-user', profile: 'circle-user' }; @@ -32,6 +35,9 @@ export function openViewer({ tile, source, origin, onDeleted }) { let token = 0; // The copies whose «Copia di nuovo» started a job: their button stays «In copia…» until the job ends (spec §4.10). const copying = new Set(); + // The videos being analysed («È un video fermo?», tappa E4): the answer may come once another file is on screen. + const analysing = new Set(); + let closed = false; const where = h('span.dove'); const closeButton = h('button.tondino', { type: 'button', 'aria-label': t('vis.chiudi'), title: t('vis.chiudi'), onclick: close }, icon('x')); @@ -82,9 +88,11 @@ export function openViewer({ tile, source, origin, onDeleted }) { } function close() { + closed = true; document.removeEventListener('keydown', onKey, true); stopWatching(); onCopiesChanged.cancel(); + onAnalysed.cancel(); for (const v of box.querySelectorAll('video')) v.pause(); if (document.fullscreenElement) document.exitFullscreen().catch(() => {}); box.remove(); @@ -245,7 +253,8 @@ export function openViewer({ tile, source, origin, onDeleted }) { fill(panelTop, h('div.chi-vis', avatar(a.username, 'm', a.avatar), h('div', h('b', `@${a.username}`), a.displayName ? h('span', a.displayName) : null), a.isFollowed ? label(t('vis.seguito'), 'accento', 'user-check') : null), - h('div.etichette', label(typeLabel, '', KIND_ICON[entry.kind] || 'image'), a.isPrivate ? label(t('vis.privato'), '', 'lock') : null), + h('div.etichette', label(typeLabel, '', KIND_ICON[entry.kind] || 'image'), a.isPrivate ? label(t('vis.privato'), '', 'lock') : null, + isStill(media) ? label(t('esportazione.fermi.etichetta'), 'accento', 'image') : null), h('div.quando', h('b', published), h('span', t('vis.pubblicato', { quando: ago(entry.publishedAt, serverNow(), today, entry.publishedDay) }))), h('section', h('h3', t('vis.didascalia')), entry.caption ? h('p.didascalia', entry.caption) : h('p.didascalia.muto', t('vis.senzaDidascalia'))), h('section', h('h3', t('vis.file')), h('dl', @@ -253,6 +262,7 @@ export function openViewer({ tile, source, origin, onDeleted }) { media && media.width && media.height ? row(t('vis.dimensioni'), t('vis.pixel', { l: number(media.width), a: number(media.height) })) : null, media && media.bytes ? row(t('vis.peso'), bytes(media.bytes)) : null, media && media.duration ? row(t('vis.durata'), duration(media.duration)) : null, + media ? stillRow(media) : null, media ? row(t('vis.cartella'), media.folder) : null, row(t('vis.codice'), entry.code || entry.instagramId), entry.author ? row(t('vis.autore'), `@${entry.author}`) : null, @@ -288,6 +298,16 @@ export function openViewer({ tile, source, origin, onDeleted }) { actions.push(h('button.btn.azione-fotogramma', { type: 'button', onclick: () => openFrames(media) }, icon('image'), t('esportazione.vis.fotogrammaAzione'))); } } + // Tappa E4: «È un video fermo?» on request only, then «Salva il fotogramma» of a video that is. + if (canAnalyse(media)) { + if (isStill(media)) { + actions.push(h('button.btn.azione-salva-fotogramma', { type: 'button', onclick: () => openStillFrame(media) }, icon('image'), t('esportazione.fermi.salva'))); + } else if (!media.still) { + const busy = analysing.has(media.id); + actions.push(h('button.btn.azione-video-fermo', { type: 'button', disabled: busy, onclick: () => analyse(media) }, + icon(busy ? 'hourglass' : 'search'), t(busy ? 'esportazione.fermi.inCorso' : 'esportazione.fermi.chiedi'))); + } + } if (entry.state !== 'deleted') { actions.push(h('button.btn.nudo.pericolo', { type: 'button', onclick: remove }, icon('trash-2'), t('vis.elimina'))); } @@ -348,6 +368,82 @@ export function openViewer({ tile, source, origin, onDeleted }) { return [h('dt', t('esportazione.vis.conversione')), h('dd.riga-copia.riga-conversione', h('span', text), action, c.notes ? h('span.nota-copia', c.notes) : null)]; } + // ------------------------------------------------------------------------------------------- video fermi (tappa E4) + function isStill(media) { + return Boolean(media && media.still && media.still.outcome === 'still'); + } + + /** + * What the analysis said of the video: «Un'immagine sola per tutto il video: basta un fotogramma», «No: l'immagine + * cambia» or «Non analizzabile» and why. «Analizza di nuovo» where another answer is possible. + */ + function stillRow(media) { + const still = media.still; + if (media.kind !== 'video' || !still) return null; + const busy = analysing.has(media.id); + const again = canAnalyse(media) && (still.outcome === 'notAnalyzable' || !still.current) + ? h('button.btn.nudo.piccolo.analizza-di-nuovo', { type: 'button', disabled: busy, onclick: () => analyse(media) }, + icon('rotate-cw', 's'), t(busy ? 'esportazione.fermi.inCorso' : 'esportazione.fermi.analizzaDiNuovo')) + : null; + return [h('dt', t('esportazione.fermi.riga')), h('dd.riga-copia.riga-fermo', h('span', stillText(still)), again, + still.current ? null : h('span.nota-copia', t('esportazione.fermi.vecchia')))]; + } + + /** «È un video fermo?»: at most 30 seconds, also during an engine session; the video on screen goes on playing. */ + async function analyse(media) { + if (analysing.has(media.id)) return; + analysing.add(media.id); + drawPanel(); + let still = null; + let problem = null; + try { + still = await api(`/api/media/${media.id}/still`, { method: 'POST' }); + } catch (error) { + problem = error; + } + analysing.delete(media.id); + if (closed) return; + if (still) setStill(media.id, still); + const current = entry.media[fileIndex]; + if (!current || current.id !== media.id) return; + const lostFocus = document.activeElement === document.body; + drawPanel(); + // The button that asked is gone: the keyboard goes on from what took its place. + const following = lostFocus && box.querySelector('.azione-salva-fotogramma, .azione-video-fermo, .analizza-di-nuovo, .azione-fotogramma'); + if (following) following.focus(); + if (problem) showError(problem); + else toast(t(`esportazione.fermi.risposte.${still.outcome}`)); + } + + function setStill(mediaId, still) { + const media = entry.media.find((m) => m.id === mediaId); + if (media) media.still = still; + } + + /** «Salva il fotogramma»: the sharpest frame the analysis looked at; the video waits while the dialog is open. */ + function openStillFrame(media) { + const video = stage.querySelector('video'); + if (video) video.pause(); + framesDialog({ mediaId: media.id, still: { label: media.still.frameLabel || '' }, hasDestination: Boolean(entry.canCopy) }); + } + + /** Analyses made elsewhere (a selection, another window): only the panel follows, never the video on screen. */ + async function readAnalyses() { + if (!entry) return; + const id = entry.id; + let fresh; + try { + fresh = await api(`/api/entries/${id}`); + } catch { + return; + } + if (closed || !entry || entry.id !== id) return; + const stills = (media) => JSON.stringify(media.map((m) => [m.id, m.still || null])); + if (stills(fresh.media) === stills(entry.media)) return; + for (const m of fresh.media) setStill(m.id, m.still || null); + drawPanel(); + } + async function showConversion(conversionId) { try { const result = await api('/api/conversions/show-in-folder', { method: 'POST', body: { conversionId } }); @@ -402,8 +498,10 @@ export function openViewer({ tile, source, origin, onDeleted }) { const current = entry.media[fileIndex]; load(entry.id, fileIndex, current ? current.id : null); }, 400); + const onAnalysed = later(readAnalyses, 400); const stopWatching = onLibrary((change) => { if (change.reason === 'export') onCopiesChanged(); + if (change.reason === 'fermi' && (!entry || !change.accountId || change.accountId === entry.account.id)) onAnalysed(); }); document.addEventListener('keydown', onKey, true); diff --git a/src/Febe.Web/wwwroot/testi/it.json b/src/Febe.Web/wwwroot/testi/it.json index 9a06c5f..fd96281 100644 --- a/src/Febe.Web/wwwroot/testi/it.json +++ b/src/Febe.Web/wwwroot/testi/it.json @@ -90,6 +90,7 @@ "all": "Tutto", "photos": "Foto", "videos": "Video", + "stillVideos": "Video fermi", "stories": "Storie", "highlights": "In evidenza", "tagged": "Taggati" @@ -1288,7 +1289,61 @@ }, "selezione": { "copia": "Copia in…", - "fotogrammi": "Fotogrammi…" + "fotogrammi": "Fotogrammi…", + "fermi": "Cerca i video fermi" + }, + "fermi": { + "etichetta": "Video fermo", + "riga": "Video fermo", + "fermo": "Un'immagine sola per tutto il video: basta un fotogramma", + "istante": " · fotogramma a {istante}", + "piccolaParte": " · una piccola parte si muove", + "inMovimento": "No: l'immagine cambia", + "nonAnalizzabile": "Non analizzabile", + "nonAnalizzabilePerche": "Non analizzabile: {motivo}", + "motivi": { + "FrameNotAvailable": "fotogramma non disponibile per questo video", + "DurationUnknown": "la durata del video non si conosce", + "Unreadable": "il video non si legge", + "TooSlow": "l'analisi richiedeva troppo tempo", + "AllDark": "il video è tutto nero", + "SingleColor": "il video è tutto di un solo colore" + }, + "vecchia": "analizzato da una versione di Febe di prima", + "analizzaDiNuovo": "Analizza di nuovo", + "chiedi": "È un video fermo?", + "inCorso": "Analisi in corso…", + "risposte": { + "still": "Video fermo: basta un fotogramma.", + "moving": "Non è un video fermo: l'immagine cambia.", + "notAnalyzable": "Video non analizzabile." + }, + "salva": "Salva il fotogramma", + "salvaAnteprima": "Il fotogramma che si salva", + "salvaQuale": "Il fotogramma più nitido fra quelli guardati dall'analisi, a {istante}.", + "salvaScaricaAiuto": "Il fotogramma si scarica com'è, con «_fotogramma» nel nome.", + "salvaCartellaAiuto": "Nella cartella delle copie dell'account, accanto alle copie, con «_fotogramma» nel nome. Il video intero si copia comunque con «Copia in…».", + "salvaRiepilogo": "1 fotogramma", + "salvaNiente": "Niente da copiare: l'account non si esporta, o il video non è fermo per l'ultima analisi.", + "cercaTitolo": "Cerca i video fermi", + "conto": "Conto i video…", + "cercaAiuto": "Un video alla volta, mai durante una sessione del motore né mentre lavorano importazione, copie o ricostruzione. L'avanzamento è nella Dashboard, scheda Esportazione, con «Interrompi».", + "cercaRiapertura": "Se chiudi Febe a metà, la ricerca non riprende da sola: rilanciala, e i video già analizzati si saltano.", + "analizza": "Analizza 1 video|Analizza {n} video", + "niente": "Niente da analizzare: i video scelti sono già analizzati o non sono in libreria.", + "nienteVideo": "Niente da analizzare: fra gli elementi scelti non ci sono video.", + "avviata": "Ricerca dei video fermi avviata: 1 video da analizzare.|Ricerca dei video fermi avviata: {n} video da analizzare.", + "mostra": "Mostra i video fermi", + "interrotta": "Ricerca interrotta. {riepilogo}.", + "interrottaSubito": "Ricerca interrotta: nessun video analizzato.", + "dashboard": { + "titolo": "Video fermi", + "barra": "Ricerca dei video fermi", + "avanzamento": "{fatti} di 1 video analizzato|{fatti} di {n} video analizzati", + "fermi": "1 fermo|{n} fermi", + "analizzo": "Analizzo un video…", + "interrompi": "Interrompi" + } }, "fotogrammi": { "titolo": "Fotogrammi", diff --git a/tests/Febe.Tests/Web/InterfaceTests.cs b/tests/Febe.Tests/Web/InterfaceTests.cs index 83eb933..6974e7c 100644 --- a/tests/Febe.Tests/Web/InterfaceTests.cs +++ b/tests/Febe.Tests/Web/InterfaceTests.cs @@ -475,7 +475,7 @@ public sealed class InterfaceTests (() => { window.__hold('kind=stories'); const chips = document.querySelectorAll('.strumenti .filtri button'); - chips[3].click(); + chips[4].click(); chips[1].click(); return true; })()