Skip to content

Instantly share code, notes, and snippets.

@zerostyle
Created August 23, 2013 20:07
Show Gist options
  • Save zerostyle/6323465 to your computer and use it in GitHub Desktop.
Save zerostyle/6323465 to your computer and use it in GitHub Desktop.
Extract Youtube/Vimeo info from URL
function parseVideoURL(url) {
function getParm(url, base) {
var re = new RegExp("(\\?|&)" + base + "\\=([^&]*)(&|$)");
var matches = url.match(re);
if (matches) {
return(matches[2]);
} else {
return("");
}
}
var retVal = {};
var matches;
if (url.indexOf("youtube.com/watch") != -1) {
retVal.provider = "youtube";
retVal.id = getParm(url, "v");
} else if (matches = url.match(/vimeo.com\/(\d+)/)) {
retVal.provider = "vimeo";
retVal.id = matches[1];
}
return(retVal);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment