import * as URL from 'node:url'; import clip from './utils/clip.js'; import cleanupTitle from './utils/cleanup-title.js'; import { decode as decodeHtml } from 'html-entities'; import { get, head, scpaping } from './utils/got.js'; import * as cheerio from 'cheerio'; /** * Contains only the html snippet for a sanitized iframe as the thumbnail is * mostly covered in OpenGraph instead. * * Width should always be 100%. */ async function getOEmbedPlayer($, pageUrl) { const href = $('link[type="application/json+oembed"]').attr('href'); if (!href) { return null; } // XXX: Use global URL object instead of the deprecated `node:url` // Disallow relative URL as no one seems to use it const oEmbed = await get(URL.resolve(pageUrl, href)); const body = (() => { try { return JSON.parse(oEmbed); } catch { } })(); if (!body || body.version !== '1.0' || !['rich', 'video'].includes(body.type)) { // Not a well formed rich oEmbed return null; } if (!body.html.startsWith('