// The dialog «Fotogrammi» from the viewer in «N in tutto» (spec §4.10, tappa E3): 8 frames, the strip of the first six // previews with «e altri 2», JPG with its note «con perdita: qualità 92», output «Nella cartella delle copie» with the // row of the folder. Same video as fotogrammi-visualizzatore.js. 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()); 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); document.querySelector('.vis video').pause(); document.querySelector('.vis .azione-fotogramma').click(); const dialog = () => document.querySelector('.dialogo.fotogrammi'); await until(() => dialog()?.querySelector('.modo-fotogrammi')); dialog().querySelector('.modo-fotogrammi').previousElementSibling.querySelector('[data-value=numero]').click(); const count = dialog().querySelector('input[type=number]'); count.value = '8'; count.dispatchEvent(new Event('input', { bubbles: true })); [...dialog().querySelectorAll('[role=radio][data-value=jpg]')].pop().click(); dialog().querySelector('input[type=radio][value=cartella]').click(); await until(() => { const images = [...dialog().querySelectorAll('.striscia-fotogrammi img')]; return images.length === 6 && images.every((i) => i.complete && i.naturalWidth > 0) && /Copia/.test(dialog().querySelector('footer .btn.primo').textContent); }, 150); await sleep(500); document.activeElement?.blur(); return [dialog().querySelector('.altri-fotogrammi')?.textContent, dialog().querySelector('.riepilogo-fotogrammi').textContent];