Skip to content

Instantly share code, notes, and snippets.

@mathieu-aubin
Forked from takien/youtubeID.js
Last active March 11, 2016 21:34
Show Gist options
  • Save mathieu-aubin/005c045cc446f7c70d2c to your computer and use it in GitHub Desktop.
Save mathieu-aubin/005c045cc446f7c70d2c to your computer and use it in GitHub Desktop.
Get YouTube ID from various YouTube URL using JavaScript
// src: takien (http://takien.com) mods: Mathieu Aubin (mathieu@zeroserieux.com)
function ytdID(url){var ID='';url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);if(url[2]!==undefined){ID = url[2].split(/[^0-9a-z_\-]/i);ID = ID[0];}else {ID = url;}return ID;}
@mathieu-aubin
Copy link
Author

Mods i performed:

- changed function name to a better javascript name (shorter is better, still relevant) - minified it (by hand just removing spaces and xtra) - kept the credits - added mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment