New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

embed-video

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

embed-video

Get embed code for embedding youtube/vimeo/whatever video in websites from URL or ID

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.2K
decreased by-36.62%
Maintainers
1
Weekly downloads
 
Created
Source

embed-video Build Status devDependency Status

Get embed code for embedding youtube/vimeo/whatever video in websites from URL or ID.

Currently supports YouTube and Vimeo. Please pull request to add others!

browser support

Example

var embed = require("embed-video")

var vimeoUrl = "http://vimeo.com/19339941"
var youtubeUrl = "https://www.youtube.com/watch?v=twE64AuqE9A"

console.log(embed(vimeoUrl))
console.log(embed(youtubeUrl))

var vimeoId = "6964150"
var youtubeId = "9XeNNqeHVDw"

console.log(embed.vimeo(vimeoId))
console.log(embed.youtube(youtubeId))

Output:

<iframe src="//player.vimeo.com/video/19339941" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<iframe src="//www.youtube.com/embed/twE64AuqE9A" frameborder="0" allowfullscreen></iframe>
<iframe src="//player.vimeo.com/video/6964150" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<iframe src="//www.youtube.com/embed/9XeNNqeHVDw" frameborder="0" allowfullscreen></iframe>

Usage

var embed = require("embed-video")

var embedCode = embed(url, [options])

Return an HTML fragment embed code (string) for the given video URL.

var embedCode = embed.vimeo(id, [options])

Return an HTML fragment embed code (string) for the given vimeo video ID.

var embedCode = embed.youtube(id, [options])

Return an HTML fragment embed code (string) for the given youtube video ID.

var embedCode = embed.image(url, [options], callback)

Returns an HTML <img> tag (string) for the given url and the src in a callback. Works for youtube and vimeo.

{
  src: http://img.youtube.com/vi/eob7V_WtAVg/default.jpg,
  html: <img src="http://img.youtube.com/vi/eob7V_WtAVg/default.jpg"/>
}

Options

query

Object to be serialized as a querystring and appended to the embedded content url.

Example
console.log(embed.vimeo("19339941", {query: {portrait: 0, color: '333'}}))

Output:

<iframe src="//player.vimeo.com/video/19339941?portrait=0&color=333" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

attributes

Object to add additional attributes (any) to the iframe

Example
console.log(embed('https://youtu.be/jglUWD3KMh4', {query: {portrait: 0, color: '333'}, attr:{width:400, height:200}}))

Output:

<iframe src="//www.youtube.com/embed/jglUWD3KMh4?portrait=0&color=333" frameborder="0" allowfullscreen width="400" height="200"></iframe>
Youtube Image options
optionimage
default
mqdefault
hqdefault
sddefault
maxresdefault
embedVideo.image('https://www.youtube.com/watch?v=ekETjYMo6QE', {image: 'mqdefault'}, function (err, thumbnail) {
  if (err) throw err
  console.log(thumbnail.src)
  // https://img.youtube.com/vi/ekETjYMo6QE/mqdefault.jpg
  console.log(thumbnail.html)
  // <img src="https://img.youtube.com/vi/ekETjYMo6QE/mqdefault.jpg"/>  
})
Vimeo Image options
optionimage
thumbnail_small
thumbnail_medium
thumbnail_large
embedVideo.image('https://vimeo.com/19339941', {image: 'thumbnail_medium'}, function (err, thumbnail) {
  if (err) throw err
  console.log(thumbnail.src)
  // http://i.vimeocdn.com/video/122513613_200x150.jpg
  console.log(thumbnail.html)
  // <img src="http://i.vimeocdn.com/video/122513613_200x150.jpg"/>
})

Keywords

FAQs

Package last updated on 13 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc