Skip to content

Instantly share code, notes, and snippets.

@derzunov
Last active August 29, 2016 20:32
Show Gist options
  • Save derzunov/a6da7a4a6663b12542cbbfe071a3236c to your computer and use it in GitHub Desktop.
Save derzunov/a6da7a4a6663b12542cbbfe071a3236c to your computer and use it in GitHub Desktop.
YouTube video id parser
link = "https://www.youtube.com/watch?v=Imeq3GeRttw"
link2 = "http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0"
link3 = "http://www.youtube.com/watch?v=EqS7oJcBi7w#t=0m10s"
youtube_parser = ( url ) ->
regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/
match = url.match regExp
if match and match[7].length == 11 then match[7] else false
console.log youtube_parser( link ), youtube_parser( link2 ), youtube_parser( link3 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment