Created
March 23, 2016 10:28
-
-
Save sinslav/d2b8037b590a14324c1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function processURL(url, success){ | |
var id; | |
if (url.indexOf('youtube.com') > -1) { | |
id = url.split('/')[1].split('v=')[1].split('&')[0]; | |
return processYouTube(id); | |
} else if (url.indexOf('youtu.be') > -1) { | |
id = url.split('/')[1]; | |
return processYouTube(id); | |
} else if (url.indexOf('vimeo.com') > -1) { | |
if (url.match(/^vimeo.com\/[0-9]+/)) { | |
id = url.split('/')[1]; | |
} else if (url.match(/^vimeo.com\/channels\/[\d\w]+#[0-9]+/)) { | |
id = url.split('#')[1]; | |
} else if (url.match(/vimeo.com\/groups\/[\d\w]+\/videos\/[0-9]+/)) { | |
id = url.split('/')[4]; | |
} else { | |
throw new Error('Unsupported Vimeo URL'); | |
} | |
$.ajax({ | |
url: 'http://vimeo.com/api/v2/video/' + id + '.json', | |
dataType: 'jsonp', | |
success: function(data) { | |
sucess(data[0].thumbnail_large); | |
} | |
}); | |
} else { | |
throw new Error('Unrecognised URL'); | |
} | |
function processYouTube(id) { | |
if (!id) { | |
throw new Error('Unsupported YouTube URL'); | |
} | |
sucess('http://i2.ytimg.com/vi/' + id + '/hqdefault.jpg'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment