Skip to content

Instantly share code, notes, and snippets.

@pinceladasdaweb
Created September 22, 2013 18:04
Show Gist options
  • Save pinceladasdaweb/6662290 to your computer and use it in GitHub Desktop.
Save pinceladasdaweb/6662290 to your computer and use it in GitHub Desktop.
Get Youtube Video Thumbnail with JavaScript.
var Youtube = (function () {
'use strict';
var video, results;
var getThumb = function (url, size) {
if (url === null) {
return '';
}
size = (size === null) ? 'big' : size;
results = url.match('[\\?&]v=([^&#]*)');
video = (results === null) ? url : results[1];
if (size === 'small') {
return 'http://img.youtube.com/vi/' + video + '/2.jpg';
}
return 'http://img.youtube.com/vi/' + video + '/0.jpg';
};
return {
thumb: getThumb
};
}());
//Example of usage:
var thumb = Youtube.thumb('http://www.youtube.com/watch?v=F4rBAf1wbq4', 'small');
console.log(thumb);
@ordinz
Copy link

ordinz commented Jun 22, 2022

Thank you!!

@MarkAUstine254
Copy link

cool

@festsnusa
Copy link

not working.

@younes-zeboudj
Copy link

thanks

@itzwalsh
Copy link

Thank you! Works great.

@lloydobligado
Copy link

thanks

@AlexOcculate
Copy link

Thanks!

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