microlinkhq / metascraper

Get unified metadata from websites using Open Graph, Microdata, RDFa, Twitter Cards, JSON-LD, HTML, and more.
https://metascraper.js.org
MIT License
2.35k stars 168 forks source link

Support Twitter:Player in metascraper-iframe #478

Closed nathangathright closed 3 years ago

nathangathright commented 3 years ago

Prerequisites

Subject of the issue

Twitter's Player Card spec defines the content of the twitter:player tag as "HTTPS URL to iFrame player." If a website doesn't support oEmbed, it would be ideal if metascraper-iframe returned a useful response powered by the twitter:player, twitter:player:width, and twitter:player:height tags.

Steps to reproduce

RunKit Sample Code

const oEmbed = require('oembed-spec')
const metascraper = require("metascraper")([
  require("metascraper-url")(),
  require("metascraper-iframe")(),
]);
const got = require("got");

const targetUrl = 'https://share.transistor.fm/s/ddad295d';

exports.endpoint = async function(req, res) {
    const { body: html, url } = await got(targetUrl);
    const metadata = await metascraper({ html, url });
    res.send(JSON.stringify(metadata));
}

Expected behaviour

{
  "url": "https://share.transistor.fm/s/ddad295d",
  "iframe": "<iframe src=\"https://share.transistor.fm/e/ddad295d\" height=\"180px\" width=\"500px\" frameborder=\"0\" scrolling=\"no\"></iframe>"
}

Actual behaviour

{
  url: 'https://share.transistor.fm/s/ddad295d',
  iframe: null
}
Kikobeats commented 3 years ago

Hey, that has a lot of sense.

I think it could be added as last chance to detect iframe here:

It could be added as a way at https://github.com/microlinkhq/metascraper/blob/master/packages/metascraper-iframe/src/index.js#L16

Can you make a PR? 🙂

nathangathright commented 3 years ago

I took a stab at it, but I'm very out of my depth 😅

Kikobeats commented 3 years ago

No problem I can review and help you 🙂

Kikobeats commented 3 years ago

Released at v5.25.3 🎉

Deployed at Microlink API as well:

https://api.microlink.io/?url=https%3A%2F%2Fshare.transistor.fm%2Fs%2Fddad295d&iframe