Adicionei uma opção para o cara escolher qual frame das miniaturas ele quer, e criei um novo método para retornar a imagem grande, simplificando assim a interface de uso
var Youtube = (function () {
"use strict";
function _getId (url) {
var results = url.match("[\\?&]v=([^&#]*)");
return (results !== null) ? results[1] : "";
}
function getBig (url) {
return getThumb(url, "0");
}
function getThumb (url, frame) {
if (!url) return "";
var frame = frame || 2;
return "http://img.youtube.com/vi/" + _getId(url) + "/" + frame + ".jpg";
}
return {
small: getThumb,
big: getBig
};
}());
console.log(Youtube.small(""));
console.log(Youtube.small());
console.log(
Youtube.small("http://www.youtube.com/watch?v=F4rBAf1wbq4")
);
console.log(
Youtube.small("http://www.youtube.com/watch?v=F4rBAf1wbq4", "1")
);
console.log(
Youtube.big("http://www.youtube.com/watch?v=F4rBAf1wbq4")
);