Skip to content

Instantly share code, notes, and snippets.

@tomrutgers
Created August 24, 2019 12:10
Show Gist options
  • Save tomrutgers/826127ea9644f55f568e1d2b006d2eff to your computer and use it in GitHub Desktop.
Save tomrutgers/826127ea9644f55f568e1d2b006d2eff to your computer and use it in GitHub Desktop.
def get_embed_url(url)
provider = url.match(/https:\/\/(:?www.)?(\w*)/)[2]
if provider == "youtube"
id = url.match(/https:\/\/(?:www.)?(\w*).com\/.*v=(\w*)/)[2];
"https://www.youtube.com/embed/#{id}"
elsif (provider == "vimeo")
id = url.match(/https:\/\/(?:www.)?(\w*).com\/(\d*)/)[2];
"https://player.vimeo.com/video/#{id}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment