media-command-guide/capture-ai-reframe.js

23 lines
2.1 KiB
JavaScript
Raw Normal View History

const { chromium } = require('playwright');
const OUT='/home/zgaetano/media-command-guide/screenshots';
const COOKIE='s:d16cd74687c1f5e4322b9d24657efe7da055c019d97fb2e0.nHwwxY6iik6jiySDiKS6aUxacWRQy3T+dCiMTN8Fu8s';
const ASSET=process.argv[2]||'9b648563-2159-43af-9b02-40ae04821714';
const pause=p=>p.evaluate(()=>document.querySelectorAll('video').forEach(v=>{try{v.pause()}catch(e){}}));
const clickText=(p,re)=>p.evaluate(s=>{const r=new RegExp(s);const el=[...document.querySelectorAll('button,[role=tab],a,div,span')].filter(e=>e.offsetHeight>0&&e.children.length<4).find(e=>r.test(e.innerText.trim()));if(el){el.click();return el.innerText.trim().slice(0,40)}return null},re.source);
(async()=>{
const b=await chromium.launch({args:['--no-sandbox','--autoplay-policy=no-user-gesture-required']});
const c=await b.newContext({viewport:{width:1600,height:1000}});
await c.addCookies([{name:'dragonflight.sid',value:COOKIE,domain:'mediacmdr.com',path:'/',httpOnly:true,secure:true}]);
const p=await c.newPage();
await p.goto('https://mediacmdr.com/analysis.html?asset='+ASSET,{waitUntil:'networkidle'});await p.waitForTimeout(6000);await pause(p);
await p.screenshot({path:`${OUT}/42-ai-analysis-overview.png`});
console.log('overview:',(await p.evaluate(()=>document.body.innerText.replace(/\n+/g,' | ').slice(0,700))));
const tabs=[['editorial',/^Story & Editorial/],['clips',/^Clips & Moments/],['faces',/^People & Faces/],['visual',/^In Picture/],['ask',/^Ask AI/]];
for(const [n,re] of tabs){const k=await clickText(p,re);await p.waitForTimeout(3500);await pause(p);await p.screenshot({path:`${OUT}/42-ai-${n}.png`});
console.log(n,k,'::',(await p.evaluate(()=>document.body.innerText.replace(/\n+/g,' | ').slice(0,400))));}
await p.goto('https://mediacmdr.com/reframe.html?asset='+ASSET,{waitUntil:'networkidle'});await p.waitForTimeout(7000);await pause(p);
await p.screenshot({path:`${OUT}/41-reframe.png`});
await p.screenshot({path:`${OUT}/41b-reframe-full.png`,fullPage:true});
console.log('reframe:',(await p.evaluate(()=>document.body.innerText.replace(/\n+/g,' | ').slice(0,1500))));
await b.close();})();