Created
August 23, 2013 20:07
-
-
Save zerostyle/6323465 to your computer and use it in GitHub Desktop.
Extract Youtube/Vimeo info from URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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