-
-
Save badah/6742649 to your computer and use it in GitHub Desktop.
Javascript: Get youtube video thumb
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment