// «Fotogramma» from the viewer (spec §4.6, §4.10, tappa E3; composed from the dialogs of mockup 13 and mockup 02): the // video of @marta.demo that the demo has a frame of, the player at 1,25 s, the dialog «Fotogrammi» in «Questo istante» // with its preview, the scrubber, the time field and «Fotogramma a …». Nothing is downloaded or copied. const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const until = async (test, tries = 100) => { for (let i = 0; i < tries && !test(); i++) await sleep(100); return test(); }; const json = (path) => fetch(path, { headers: { Accept: 'application/json' } }).then((r) => r.json()); // The video with a frame copy: the newest of @marta.demo's videos whose viewer lists a «fotogramma» row. const marta = (await json('/api/accounts')).accounts.find((a) => a.username === 'marta.demo'); const videos = []; for (let cursor = null, i = 0; i < 20; i++) { const page = await json(`/api/library?accounts=${marta.id}&mode=files&limit=600${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`); videos.push(...page.tiles.filter((x) => x.cover && x.cover.kind === 'video')); if (!(cursor = page.older)) break; } let found = null; for (let i = 0; i < videos.length && !found; i += 16) { const entries = await Promise.all(videos.slice(i, i + 16).map((x) => json(`/api/entries/${x.id}`))); found = entries.find((e) => e.media.some((m) => (m.copies || []).some((c) => c.variant === 'frame'))); } const { navigate } = await import('/js/core/shell.js'); await navigate(`/libreria?account=${found.account.id}&dal=${found.publishedDay}&al=${found.publishedDay}`); const tile = () => document.querySelector(`.mosaico .tess[data-entry="${found.id}"]`); await until(tile); tile().click(); await until(() => document.querySelector('.vis .azione-fotogramma') && document.querySelector('.vis video')?.readyState >= 1); const video = document.querySelector('.vis video'); video.pause(); video.currentTime = 1.25; await until(() => !video.seeking && Math.abs(video.currentTime - 1.25) < 0.01, 50); document.querySelector('.vis .azione-fotogramma').click(); const dialog = () => document.querySelector('.dialogo.fotogrammi'); await until(() => { const img = dialog()?.querySelector('.anteprima-fotogramma img'); return img && img.complete && img.naturalWidth > 0 && /Fotogramma a/.test(dialog().querySelector('.istante-mostrato')?.textContent || ''); }); await until(() => dialog().querySelector('.riepilogo-fotogrammi .riepilogo-copia')); await sleep(400); document.activeElement?.blur(); return [dialog().querySelector('.istante-mostrato')?.textContent, dialog().querySelector('.riepilogo-fotogrammi')?.textContent];