OverviewFilesCommitsIssuesDocsReleasesPeers

stremio-vsembed / node_helper / flixlab_tv_probe.mjs

36 lines · javascript ref:
// flixlab_tv_probe.mjs — does flixlab's TV watch route need /s/e in the hash?
// Compares the URL shapes our resolver builds vs the one the user reported.
// Usage: xvfb-run -a node node_helper/flixlab_tv_probe.mjs <watchUrl>
import { chromium } from 'patchright';
const log = (...a) => console.error('[tv]', ...a);
const MEDIA = /\.m3u8(\?|$)|\/playlist|\/master/i;
const NOISE = /youtube|googlevideo|ytimg|chaturbate|mmcdn|canAutoplay/i;
const WATCH = process.argv[2];
if (!WATCH) { console.error('usage: <watchUrl>'); process.exit(1); }

const ctx = await chromium.launchPersistentContext('/tmp/vc_profile_tv', {
  headless: false, args: ['--no-sandbox'], viewport: { width: 1280, height: 720 }, locale: 'en-US',
});
ctx.on('page', p => setTimeout(() => { if (!p.isClosed() && !/flixlab/.test(p.url())) p.close().catch(() => {}); }, 500));
const media = new Map();
ctx.on('request', r => { const u = r.url(); if (MEDIA.test(u) && !NOISE.test(u)) media.set(u, 1); });
const page = ctx.pages()[0] || await ctx.newPage();
log('goto', WATCH);
await page.goto(WATCH, { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(e => log('warn', e.message));
await page.waitForTimeout(5000);
log('url after load:', page.url());
log('page text:', await page.evaluate(() => ((document.body && document.body.innerText) || '').replace(/\s+/g, ' ').slice(0, 220)).catch(() => '?'));
// what clickable "play"-ish things exist
log('buttons:', await page.evaluate(() => [...document.querySelectorAll('button,[role=button],a')]
  .map(x => (x.textContent || '').trim()).filter(t => t && t.length < 30).slice(0, 25)).then(JSON.stringify).catch(() => '?'));
await page.evaluate(() => { const b = [...document.querySelectorAll('button,[role=button],a')].find(x => /^\s*play\s*$/i.test((x.textContent || '').trim())); if (b) b.click(); }).catch(() => {});
for (let i = 0; i < 12 && media.size === 0; i++) {
  const vf = page.frames().find(f => /vidcore\.net/i.test(f.url()));
  if (vf) { try { const v = await vf.$('video'); if (v) await v.click({ timeout: 1200, force: true }).catch(() => {}); } catch {} }
  const st = vf ? await vf.evaluate(() => (document.body?.innerText || '').replace(/\s+/g, ' ').slice(0, 50)).catch(() => '') : '';
  log(`t=${i * 3}s vidcore=${vf ? 'Y' : 'n'} url=${vf ? vf.url().slice(0, 80) : '-'} "${st}" media=${media.size}`);
  await page.waitForTimeout(3000);
}
await ctx.close().catch(() => {});
console.log(JSON.stringify({ watch: WATCH, media: [...media.keys()] }));