Skip to content

Instantly share code, notes, and snippets.

View viking2917's full-sized avatar

Mark Watkins viking2917

View GitHub Profile
@viking2917
viking2917 / MediaFormat
Last active May 28, 2020 02:57 — forked from TrevorJTClarke/MediaFormat
MediaFormat - A regex system for finding the media ID for each type of popular social site. Can identify YouTube, Vimeo, Spotify, and Soundcloud.
/**
* mediaId
* format and return only needed pieces of media from their public sources
* Author: Trevor Clarke, minor changes from Mark Watkins
*/
function mediaId (){
// http://www.youtube.com/embed/m5yCOSHeYn4
var ytRegEx = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/;
// http://vimeo.com/3116167, https://player.vimeo.com/video/50489180, http://vimeo.com/channels/3116167, http://vimeo.com/channels/staffpicks/113544877
var vmRegEx = /https?:\/\/(?:vimeo\.com\/|player\.vimeo\.com\/)(?:video\/|(?:channels\/staffpicks\/|channels\/)|)((\w|-){7,9})/;