microlinkhq / metascraper

Get unified metadata from websites using Open Graph, Microdata, RDFa, Twitter Cards, JSON-LD, HTML, and more.

Home Page:https://metascraper.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Twitter:Player in metascraper-iframe

nathangathright opened this issue Β· comments

Prerequisites

  • I'm using the last version.
  • My node version is the same as declared as package.json.

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
}

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? πŸ™‚

I took a stab at it, but I'm very out of my depth πŸ˜…

No problem I can review and help you πŸ™‚

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