Created
August 13, 2013 20:05
-
-
Save fenda/6225128 to your computer and use it in GitHub Desktop.
get youtube video id 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
| // from http://lasnv.net/ | |
| <script type="text/javascript"> | |
| function youtube_parser(url){ | |
| var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; | |
| var match = url.match(regExp); | |
| if (match&&match[7].length==11){ | |
| return match[7]; | |
| }else{ | |
| alert("Url incorrecta"); | |
| } | |
| } | |
| </script> | |
| /* These are the types of URLs supported | |
| http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index | |
| http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o | |
| http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0 | |
| http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s | |
| http://www.youtube.com/embed/0zM3nApSvMg?rel=0 | |
| http://www.youtube.com/watch?v=0zM3nApSvMg | |
| http://youtu.be/0zM3nApSvMg */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment