Parses and creates links and embedding codes for media hosting services
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
browser
platforms
tests
utils
.gitignore
LICENSE
README.md
index.js
package.json
platform_base.js

README.md

MediaEmbedder

MediaEmbedder is a javascript library for parsing and creating links and embedding codes for media hosting services. While parsing, it also supports outdated embedding codes, so it can be used to get rid of flash-player embeds.

Currently, these services are supported:

  • Youtube
  • Dailymotion
  • Vimeo

Example

const MediaEmbedder = require('media-embedder');

const mediaData = MediaEmbedder.detect(`
    <object height="344" width="425">
        <param name="movie" value="http://www.youtube.com/v/DLzxrzFCyOs&hl=pl&fs=1&color1=0xcc2550&color2=0xe87a9f">
        <param name="allowFullScreen" value="true">
        <param name="allowscriptaccess" value="always">
        <embed allowfullscreen="true" allowscriptaccess="always" height="344" src="http://www.youtube.com/v/DLzxrzFCyOs&fs=1&color1=0xcc2550&color2=0xe87a9f" type="application/x-shockwave-flash" width="425"></embed>
    </object>
`)

Returns this object:

{ mediaid: 'DLzxrzFCyOs',
    height: '344',
    width: '425',
    timestamp: null,
    allowFullscreen: true,
    loop: false,
    autoplay: false,
    platform: 'youtube' }

From that you can generate a new embed code:

MediaEmbedder.buildIframe(mediaData); //=> '<iframe height="344" width="425" allowfullscreen webkitallowfullscreen mozallowfullscreen frameborder="0" src="https://www.youtube.com/embed/DLzxrzFCyOs"></iframe>'

Or a direct link URL:

MediaEmbedder.buildLink(mediaData); //=> 'https://www.youtube.com/watch?v=DLzxrzFCyOs'