Skip to content

Instantly share code, notes, and snippets.

@joetastic
Created August 21, 2014 16:43
Show Gist options
  • Save joetastic/f902c96dafb407853290 to your computer and use it in GitHub Desktop.
Save joetastic/f902c96dafb407853290 to your computer and use it in GitHub Desktop.
thumbFromVideo: function(embed, quality) {
console.log('thumb for video', embed);
embed = embed.trim(); // who knows why
var hash, u;
if (embed.search(/https?:\/\/abc\.go\.com/) >= 0) {
hash = embed.match(/https?:\/\/abc\.go\.com\/embed\/([^\/\?"]*)/).pop();
return 'http://static.east.abc.go.com/service/image/ratio/id/' + hash + '/dim/160.1x1.jpg';
} else if (embed.indexOf('<') >= 0) {
hash = $(embed).attr('src').match(/embed\/(.*)$/)[1];
} else if (embed.search(/^https?:\/\/(www\.)?youtube.com/) >= 0) {
u = new URL(embed);
hash = u.search.substr(1).split('&').filter(
function(ob) { return (ob.search(/^v=/) == 0); })[0].substr(2);
} else {
hash = embed.split('/')[3]; // http://youtu.be/7gConQtn_5A
}
return "http://img.youtube.com/vi/" + hash + "/" + quality + "default.jpg";
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment