Giter VIP home page Giter VIP logo

node-oembed's Introduction

node-oembed

From oEmbed.com:

oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

This library allows you to discover and retrieve the oEmbed JSON descriptors for these posts. It automatically converts the additional XML format to JavaScript objects for your convenience. This package comes with multiple tools that allow you to consume oEmbed information.

Installation

npm i oembed

Don't forget to put it in dependencies of your package.json later if you use this in a node app.

Features

  • Supports both

    • application/json+oembed
    • text/xml+oembed
  • Automatic Embed.ly fallback when an API key is provided

  • Uses htmlparser for HTML and XML parsing

Tools (bin/)

oembed_get <URL>

Retrieve and display oEmbed information for a custom URL.

oembed_httpd <bind-port> [bind-host]

Replicates the embed.ly API in a simple Web server.

oembed_diff_json_xml <URL>

Compare JSON and XML descriptors for a URL.

API (require('oembed'))

In a real-world app all you should need is the fetch function to get oEmbed information. We always use the function callback(error, result) convention.

oembed.fetch(url, { maxwidth: 1920 }, function(error, result) {
    if (error)
        console.error(error);
    else
        console.log("oEmbed result", result);
});

The two steps can be executed separately whenever you need more control:

  • oembed.discover(url, callback) finds all <link rel="alternate"> in a document
  • Get and parse descriptors immediately with oembed.fetchJSON(url, callback) and oembed.fetchXML(url, callback) if you have discovery information already

Embed.ly fallback

The Embed.ly service can deliver oEmbed information even for resources that don't provide oEmbed links. Go sign up with them and configure your API key like:

oembed.EMBEDLY_KEY = "...";

TODO

  • Document size limits?
  • bin/oembed_httpd: Multiple URLs like embed.ly
  • bin/oembed_httpd: Pass through for ETags and Last-Modified

node-oembed's People

Contributors

astro avatar focusaurus avatar simong avatar tuxpiper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-oembed's Issues

Any way to use this client side?

It looks like the oembed providers require CORS to request info which means modules like this one can only be used server side.

Is this true?

Query string params don't persist

If the url is https://youtu.be/0JUN9aDxVmI?t=32s, the response from node-oembed is

{"width":612,"author_url":"https://www.youtube.com/user/Harvard","title":"Advanced Algorithms (COMPSCI 224), Lecture 1","html":"<iframe width=\"612\" height=\"344\" src=\"https://www.youtube.com/embed/0JUN9aDxVmI?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>","thumbnail_width":480,"version":"1.0","type":"video","thumbnail_url":"https://i.ytimg.com/vi/0JUN9aDxVmI/hqdefault.jpg","thumbnail_height":360,"height":344,"provider_name":"YouTube","author_name":"Harvard University","provider_url":"https://www.youtube.com/","original_url":"https://youtu.be/0JUN9aDxVmI?t=32s"}

But directly from youtube (https://www.youtube.com/oembed?url=https%3A%2F%2Fyoutu.be%2F0JUN9aDxVmI%3Ft%3D32s), it's

{"thumbnail_url":"https:\/\/i.ytimg.com\/vi\/0JUN9aDxVmI\/hqdefault.jpg","provider_url":"https:\/\/www.youtube.com\/","thumbnail_height":360,"type":"video","version":"1.0","author_url":"https:\/\/www.youtube.com\/user\/Harvard","author_name":"Harvard University","thumbnail_width":480,"width":480,"title":"Advanced Algorithms (COMPSCI 224), Lecture 1","provider_name":"YouTube","height":270,"html":"\u003ciframe width=\"480\" height=\"270\" src=\"https:\/\/www.youtube.com\/embed\/0JUN9aDxVmI?start=32\u0026feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e"}

Note you the iframe does not handle the 32s from node-oembed, but does from youtube.

please publish new version out to npm?

PR #5 is a required change now for node 6.x and later since util.pump went from deprecated to gone, but the last published version in the npm registry is from before that fix. Could you please publish a new version out to npm? I'll point to this repo in the mean time but I'm sure others are hitting this issue as well. ๐Ÿ˜„

Crash

I had a crash when I tried to fetch the following URL: http://www.tatw.co.uk/podcast.xml
I also use embed.ly.

Stack trace
/Users/pronebird/dev/homejs/node_modules/oembed/lib/oembed.js:115
attrs.rel === 'alternate' &&
^
TypeError: Cannot read property 'rel' of undefined
at Object.DiscoveryHandler.writeTag (/Users/pronebird/dev/homejs/node_modules/oembed/lib/oembed.js:115:11)
at Parser$writeHandler as writeHandler
at Parser$parseTags as parseTags
at Parser$parseChunk as parseChunk
at Discovery.write (/Users/pronebird/dev/homejs/node_modules/oembed/lib/oembed.js:78:17)
at IncomingMessage.exports.pump (util.js:496:21)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
at IncomingMessage._emitData (http.js:359:10)
at HTTPParser.parserOnBody as onBody
at Socket.socketOnData as ondata
16 Nov 23:22:59 - [nodemon] app crashed - waiting for file changes before starting...

node-oembed hangs

Is there a way to set a time-out in node-oembed? When calling some URLs they just hang forever.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.