Created
September 22, 2013 18:04
-
-
Save pinceladasdaweb/6662290 to your computer and use it in GitHub Desktop.
Get Youtube Video Thumbnail with JavaScript.
This file contains 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
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); |
Thank you!!
cool
not working.
thanks
Thank you! Works great.
thanks
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Woks like a charm thanks a lot!