-
-
Save JoshuaFrontEnd/ee35e67bbfe32b0538b6e436d5ee20d4 to your computer and use it in GitHub Desktop.
Obtener el ID de la url de un video en youtube
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
/** | |
* Get YouTube ID from various YouTube URL | |
* @author: takien | |
* @url: http://takien.com | |
* For PHP YouTube parser, go here http://takien.com/864 | |
*/ | |
function YouTubeGetID(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; | |
} | |
//Funcion simplificada | |
function YouTubeGetID(url){ | |
url = url.split(/(vi\/|v%3D|v=|\/v\/|youtu\.be\/|\/embed\/\/?)/); | |
return undefined !== url[2]?url[2].split(/[^0-9a-z_\-]/i)[0]:url[0]; | |
} | |
/* | |
* Tested URLs: | |
var url = 'http://youtube.googleapis.com/v/4e_kz79tjb8?version=3'; | |
url = 'https://www.youtube.com/watch?feature=g-vrec&v=Y1xs_xPb46M'; | |
url = 'http://www.youtube.com/watch?feature=player_embedded&v=Ab25nviakcw#'; | |
url = 'http://youtu.be/Ab25nviakcw'; | |
url = 'http://www.youtube.com/watch?v=Ab25nviakcw'; | |
url = '<iframe width="420" height="315" src="http://www.youtube.com/embed/Ab25nviakcw" frameborder="0" allowfullscreen></iframe>'; | |
url = '<object width="420" height="315"><param name="movie" value="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; | |
url = 'http://i1.ytimg.com/vi/Ab25nviakcw/default.jpg'; | |
url = 'https://www.youtube.com/watch?v=BGL22PTIOAM&feature=g-all-xit'; | |
url = 'BGL22PTIOAM'; | |
url = 'https://www.youtube-nocookie.com/embed//5ybGYHlgNGo'; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment