GithubHelp home page GithubHelp logo

embedify's Introduction

Embedify

Simple and robust oEmbed library. Fetches oEmbed information for Soundcloud, Spotify, Vimeo and Youtube links. The library is highly modular and new providers can be added easily (contributions welcome).

Installing

npm install embedify

Usage

const embedify = require('embedify');

const options = { parse: true };
const oEmbed = embedify.create(options);

const urls = [
  'https://www.youtube.com/embed/iOf7CsxmFCs',
  'https://play.spotify.com/track/4th1RQAelzqgY7wL53UGQt',
];

oEmbed.get(urls)
  .then(res => console.log(res));

Result

[{ 
  type: 'video',
  version: '1.0',
  title: '☼ Min sommer road trip | Del 1 ☼',
  html: '<iframe width="480" height="270" src="https://www.youtube.com/embed/iOf7CsxmFCs?feature=oembed" frameborder="0" allowfullscreen></iframe>',
  author: { 
    name: 'Amanda MIDK',
    url: 'https://www.youtube.com/user/AmandaS4G'
  },
  provider: { 
    name: 'YouTube', 
    url: 'https://www.youtube.com/' 
  },
  image: { 
    url: 'https://i.ytimg.com/vi/iOf7CsxmFCs/hqdefault.jpg',
    width: 480,
    height: 360 
  },
  width: 480,
  height: 270
},
{  
  type: 'rich',
  version: '1.0',
  title: 'Avicii - The Days',
  html: '<iframe src="https://embed.spotify.com/?uri=spotify:track:4th1RQAelzqgY7wL53UGQt" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>',
  author: {},
  provider: { 
    name: 'Spotify', 
    url: 'https://www.spotify.com' 
  },
  image: { 
    url: 'https://d3rt1990lpmkn.cloudfront.net/cover/f8717f432506ab213c4de0c66d6ac24cd07ecf72',
    width: 300,
    height: 300 
  },
  width: 300,
  height: 380
}]

API

embedify.create([options])

Creates new Embedify instance.

options

parse

Type: boolean Default: true

By default, the provider's response will be parsed and the following schema is ensured:

[{ 
  type: string,
  version: string,
  title: string,
  html: string,
  author: {
    name: string,
    url: string,
  },
  provider: {
    name: string,
    url: string,
  },
  image: {
    url: string,
    width: number,
    height: number,
  },
  width: number,
  height: number,
}]

If parse is set to false the raw response will be returned instead, like for example:

[{
  provider_url: 'https://www.spotify.com',
  version: '1.0',
  thumbnail_width: 300,
  height: 380,
  thumbnail_height: 300,
  title: ' - ',
  width: 300,
  thumbnail_url: 'https://d3rt1990lpmkn.cloudfront.net/cover/',
  provider_name: 'Spotify',
  type: 'rich',
  html: '<iframe src="https://embed.spotify.com/?uri=spotify:track:sdfgerh" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>'
}]
failSoft

Type: boolean Default: false

By default, 404 responses from provider APIs (when for example a video has been removed from Youtube etc.) will make Embedify reject the Promise with a ProviderRequestError. In cases where an empty result is preferred, failSoft can be set to true and Embedify will resolve normally with no/empty result for that particular URL.

concurrency

Type: number Default: 10

Sets the maximum number of concurrent HTTP requests to provider APIs.

oEmbed.get(urls)

Returns a Promise and resolves to oEmbed information for all URLs that matched a provider.

urls

Type: string or array<string>

URL or list of URLs to get oEmbed information for.

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.